Hello everyone!
So I’ve been using, or should I say learning, OH2 for a couple of months now… WOW! The software is great and the community is full of talented people willing to help beginners like me. So thank you to those people… you know who you are!
I’m working on a thermostat project, so I wanted to share for others to use and to get some feedback / advice on how to improve. Any constructive criticism or advice is welcomed! I’m going to add some additional functionality, which I’ll share with the OH community as it progresses.
Note: The setup is working as expected, but there are a lot of logs being generated on behalf of the rule I wrote.
Thanks in advance for any help provided!!!
Setup…
Openhabian running on RaspPi (Linux openHABianPi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l GNU/Linu)
DHT22 hooked to gpis (Values read with python script executed via exec binding… man it was tough figuring it out!! Rule to change string into number)
16 channel relay board to switch heating, cooling, and fan.
hvac.items
//-----Proxy items used for logic-----//
Switch AC "AC" (HVAC)
Switch Heat "Heat" (HVAC)
Switch Fan "Fan" (HVAC)
//-----Number used for home.sitemap Setpoint-----//
Number Setpoint_Temp "HVAC Setpoint [%.1f °F]" <temperature> (HVAC)
//-----Living_Temp and Living_Hum numbers converted from the strings below (Note: See ../things/hvac.things)-----//
Number Living_Hum_Numb "Living Humidity [%.1f %%]" <humidity> (HVAC)
Number Living_Temp_Numb "Living Temp [%.1f °F]" <temperature> (HVAC)
//-----Strings read from DHT22 temp/humidity sensor-----//
String Living_Hum {channel="exec:command:hum:output"}
String Living_Temp {channel="exec:command:temp:output"}
//-----Relay Items used to turn on/off air handler-----//
Switch AC_Relay {gpio="pin:21 activelow:yes initialValue:high"}
Switch Heat_Relay {gpio="pin:20 activelow:yes initialValue:high"}
Switch Fan_Relay {gpio="pin:16 activelow:yes initialValue:high"}
hvac.things
Thing exec:command:temp [command="/usr/bin/python2 /etc/openhab2/scripts/temp.py", interval=30, autorun=true]
Thing exec:command:hum [command="/usr/bin/python2 /etc/openhab2/scripts/hum.py", interval=300, autorun=true]
temp.py and hum.py
#!/usr/bin/env python2.7
import sys
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
temperature = temperature * 9/5.0 + 32
if humidity is not None and temperature is not None:
print('{0:0.2f}'.format(temperature))
else:
print('Failed to get reading. Try again!')
sys.exit(1)
---------------------------------------------------------------------------------------
#!/usr/bin/env python2.7
import sys
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('{0:0.2f}'.format(humidity))
else:
print('Failed to get reading. Try again!')
sys.exit(1)
hvac.rules
//-----Rule to convert String type to Number type-----//
rule "Convert dht22 temp string to number"
when
Item Living_Temp changed
then
Living_Temp_Numb.postUpdate(Float::parseFloat(String::format("%s",Living_Temp.state).replace(' ','')))
end
rule "Convert dht22 humidity to number"
when
Item Living_Hum changed
then
Living_Hum_Numb.postUpdate(Float::parseFloat(String::format("%s",Living_Hum.state).replace(' ','')))
end
//-----Rule to postUpdate of Living_Temp_Numb every minute-----//
//-----Used to turn off AC if Setpoint changed but temp hasn't changed-----//
rule "Update Living Temp Number every minute"
when
Time cron "0 0/1 * 1/1 * ? *"
then
sendCommand(Living_Temp_Numb.name,Living_Temp_Numb.state.toString)
end
//-----Rule to turn off/on AC (Auto)-----//
rule "Turn AC on if AC switch is ON and Living Temp is greater than Setpoint"
when
Item Living_Temp_Numb received command or
Item Living_Temp_Numb changed
then
if (AC.state==ON && Living_Temp_Numb.state > Setpoint_Temp.state)
{
AC_Relay.sendCommand(ON)
Thread::sleep(5000)
Fan.sendCommand(ON)
Fan_Relay.sendCommand(ON)
}
else
{
AC_Relay.sendCommand(OFF)
Thread::sleep(5000)
Fan.sendCommand(OFF)
Fan_Relay.sendCommand(OFF)
}
end
rule "Turn AC off if AC switch changes from ON to OFF"
when
Item AC changed from ON to OFF
then
Thread::sleep(2000)
AC_Relay.sendCommand(OFF)
Thread::sleep(5000)
Fan_Relay.sendCommand(OFF)
Fan.sendCommand(OFF)
end
events.logs (50 lines)
2018-07-05 07:35:05.095 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:36:00.023 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:36:00.089 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:36:05.107 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:36:05.122 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:37:00.027 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:37:00.063 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:37:05.068 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:37:05.074 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:37:37.999 [vent.ItemStateChangedEvent] - ZWaveNode2ZW100Multisensor6_MotionAlarm changed from OFF to ON
2018-07-05 07:38:00.021 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:38:00.053 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:38:05.073 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:38:05.086 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:38:15.521 [vent.ItemStateChangedEvent] - ZWaveNode2ZW100Multisensor6_MotionAlarm changed from ON to OFF
2018-07-05 07:39:00.024 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:39:00.072 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:39:05.084 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:39:05.101 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:39:41.657 [vent.ItemStateChangedEvent] - Living_Hum changed from 53.10 to 53.30
2018-07-05 07:39:41.670 [vent.ItemStateChangedEvent] - Living_Hum_Numb changed from 53.1 to 53.3
2018-07-05 07:40:00.032 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:40:00.061 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:40:05.068 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:40:05.087 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:40:13.235 [vent.ItemStateChangedEvent] - ZWaveNode2ZW100Multisensor6_MotionAlarm changed from OFF to ON
2018-07-05 07:40:52.477 [vent.ItemStateChangedEvent] - ZWaveNode2ZW100Multisensor6_MotionAlarm changed from ON to OFF
2018-07-05 07:41:00.032 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:41:00.069 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:41:05.087 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:41:05.099 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:42:00.027 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:42:00.125 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:42:05.151 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:42:05.168 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:43:00.080 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.08
2018-07-05 07:43:00.114 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:43:03.877 [vent.ItemStateChangedEvent] - Living_Temp changed from 78.08 to 78.26
2018-07-05 07:43:03.898 [vent.ItemStateChangedEvent] - Living_Temp_Numb changed from 78.08 to 78.26
2018-07-05 07:43:03.913 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:43:05.123 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:43:05.133 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:43:08.924 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:43:08.932 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:44:00.046 [ome.event.ItemCommandEvent] - Item 'Living_Temp_Numb' received command 78.26
2018-07-05 07:44:00.090 [ome.event.ItemCommandEvent] - Item 'AC_Relay' received command ON
2018-07-05 07:44:05.110 [ome.event.ItemCommandEvent] - Item 'Fan' received command ON
2018-07-05 07:44:05.124 [ome.event.ItemCommandEvent] - Item 'Fan_Relay' received command ON
2018-07-05 07:44:43.258 [vent.ItemStateChangedEvent] - Living_Hum changed from 53.30 to 53.00
2018-07-05 07:44:43.273 [vent.ItemStateChangedEvent] - Living_Hum_Numb changed from 53.3 to 53.0```