Humidity Sensor with LED display, Exterior Temp and High/Low

Working on a way to allow guests to bump the A/C cooler a bit if they are not comfortable (common complaint in the guest room).

I’m going to add to this sketch an interrupt that will send a signal back to Vera to drop the thermostat for some time period, allowing only one bump every X hours.

But I got this sketch to a point that some of you may find useful, bringing back weather info from Vera and displaying on an LCD. It creates four five variables, three four in the temperature and one in the humidity device. You then need to populate the variables (i use weather underground) and I attached the little bit of Luup needed to accomplish this part. I put it in a scene that runs every 5minutes to keep the arduino current with actual.

I added another dimension by including the Condition text coming back to the sensor and displaying on the LCD.

I thought I’d share the sketch. it is not pretty code but it is working. I’ll get round leaning it out when I get the pushbutton done.

[code]// Humidity and Temperature Sensor with LCD Display
// Retrieves Temperature, Humidity, Weather (text) and today’s Hi/Low from Vera and displays it on an LCD alongside with Room Temperature and Humidity.
#include <Sleep_n0m1.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Sensor.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x20 for a 16 chars and 2 line display
//
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 4
unsigned long SLEEP_TIME = 5; // Sleep time between reads (in seconds)
//
Sensor gw;
DHT dht;
Sleep sleep;
float lastTemp;
float lastHum;
float temperature;
float humidity;
float temp;
boolean metric = false;
int OutdoorHumidity;
int OutdoorTemp;
int TodayLow;
int TodayHigh;
String TodayWeather= “No Weather Reported”; //*****
int counter = 60;
//
void setup()
{
//Serial.begin(9600);
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
gw.sendSketchInfo(“Humidity”, “1.0”);
gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
gw.getStatus(CHILD_ID_HUM, V_VAR1);
gw.getStatus(CHILD_ID_TEMP,V_VAR1);//current exterior temperature
gw.getStatus(CHILD_ID_TEMP,V_VAR2);//today’s high temperature
gw.getStatus(CHILD_ID_TEMP,V_VAR3);//today’s low temperature
gw.getStatus(CHILD_ID_TEMP,V_VAR4);//todays weather
//
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
//lcd.setBacklight(LOW);******** come back to this
lcd.setCursor(0,0);
lcd.print(" Put Your “);
lcd.setCursor(0,1);
lcd.print(” Custom Startup “);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” Message ");
lcd.setCursor(0,1);
lcd.print("Here ");
delay(2000);
}
//
void loop()
{
delay(dht.getMinimumSamplingPeriod());
if (counter == 60){
gw.getStatus(CHILD_ID_HUM, V_VAR1);
HumStatus(gw.getMessage());
gw.getStatus(CHILD_ID_TEMP, V_VAR1);
TempStatus(gw.getMessage());
gw.getStatus(CHILD_ID_TEMP, V_VAR2);
LowStatus(gw.getMessage());
gw.getStatus(CHILD_ID_TEMP, V_VAR3);
HighStatus(gw.getMessage());
gw.getStatus(CHILD_ID_TEMP, V_VAR4);
WeatherStatus(gw.getMessage());
Serial.println(TodayWeather);
counter = 0;
}
temperature = dht.getTemperature();
temp = dht.toFahrenheit(temperature);
if (isnan(temperature)) {
Serial.println(“Failed reading temperature from DHT”);
} else if (temperature != lastTemp) {
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
Serial.print("T: ");
Serial.println(temperature);
}
humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println(“Failed reading humidity from DHT”);
} else if (humidity != lastHum) {
lastHum = humidity;
gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
Serial.print("H: ");
Serial.println(humidity);
}
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
delay(1000); //delay to allow serial to fully print before sleep
gw.powerDown();
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime
updateOutsideTemp();
updateOutsideHumid();
delay(3000);
updateLow();
updateHigh();
delay(3000);
updateWeather();
delay(3000);
updateTemp();
updateHumid();
counter = (counter + 1);
}
void updateTemp(){
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.print(round(temp));
lcd.print("F ");
}
void updateLow(){
lcd.setCursor(0,0);
lcd.print("Today’s Low: ");
lcd.print(round(TodayLow));
lcd.print("F “);
}
void updateHigh(){
lcd.setCursor(0,1);
lcd.print(” High: ");
lcd.print(round(TodayHigh));
lcd.print("F ");
}
void updateHumid(){
lcd.setCursor(0,1);
lcd.print("Humidity: “);
lcd.print(round(humidity));
lcd.print(”% ");
}
void updateOutsideTemp(){
lcd.setCursor(0,0);
lcd.print(“Outside Temp:”);
lcd.print(OutdoorTemp);
lcd.print("F ");
}
void updateOutsideHumid(){
//getStatus(CHILD_ID_HUM, V_VAR1);
lcd.setCursor(0,1);
lcd.print("Humidity: “);
lcd.print(OutdoorHumidity);
lcd.print(”% ");
}
void updateWeather(){
lcd.setCursor(0,0);
lcd.print(“Today’s Weather “);
lcd.setCursor(0,1);
lcd.print(” “);//clear the line
delay(25);
lcd.setCursor(0,1);
lcd.print(TodayWeather);
}
void HumStatus(message_s message){
if (message.header.type==V_VAR1) {
OutdoorHumidity = atoi(message.data);
}
}
void TempStatus(message_s message){
if (message.header.type==V_VAR1) {
OutdoorTemp = atoi(message.data);
}
}
void LowStatus(message_s message){
if (message.header.type==V_VAR2) {
TodayLow = atoi(message.data);
}
}
void HighStatus(message_s message){
if (message.header.type==V_VAR3) {
TodayHigh = atoi(message.data);
}
}
void WeatherStatus(message_s message){
if (message.header.type==V_VAR4) {
String Weather = String(message.data);
int locator = Weather.indexOf(”&”);
Weather = Weather.substring(0, locator);
TodayWeather= Weather;
}
}

[/code]

and the Luup:

[code]ocal temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 60)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,temp,58)

local low = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 61)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable2”,low,58)

local high = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 62)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable3”,high,58)

local weather = luup.variable_get(“urn:upnp-micasaverde-com:serviceId:Weather1”,“Condition”, 59)
weather = (weather…" &")
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable4”,weather,58)

local humid = luup.variable_get(“urn:micasaverde-com:serviceId:HumiditySensor1”,“CurrentLevel”, 63)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,humid,57)
[/code]

Have fun with it.

EDIT: Added moving Text into the sensor and displaying on LCD