In an effort to understand OpenHAB better and get into writing rules, I decided to work on a project which I last operated on 1-wire and programmed through bash; strictly using nano, no vi for me.
The concept is that we have a whole-house, indirect hot-water tank rated at 300L and insulated using spray-insulation. I wanted to be able to see the state of the tank in terms of the amount of hot water available within.
I fitted it with four sensor holes in the insulation so that I could mount four DS18B20 1-wire sensors and I connected them to the Fibaro Universal Sensor. The sensors should ideally touch the copper vessel, but frankly thatās difficult to achieve when retrofitting these sensors without affecting the functionality of the insulation.
Here are my item mappings for the Fibaro:
// Fibaro Hot Tank Sensors
Number FF_HotTank_01 "HotTank_01 [%.1f Ā°C]" <temperature> (gHotTankTemperature) {channel="zwave:device:c7937d7e:node16:sensor_temperature5"}
Number FF_HotTank_02 "HotTank_02 [%.1f Ā°C]" <temperature> (gHotTankTemperature) {channel="zwave:device:c7937d7e:node16:sensor_temperature6"}
Number FF_HotTank_03 "HotTank_03 [%.1f Ā°C]" <temperature> (gHotTankTemperature) {channel="zwave:device:c7937d7e:node16:sensor_temperature3"}
Number FF_HotTank_04 "HotTank_04 [%.1f Ā°C]" <temperature> (gHotTankTemperature) {channel="zwave:device:c7937d7e:node16:sensor_temperature4"}
Here are my 12hr min/max items for database storage, and some items for energy calcs:
Number FF_HotTank_01_Min12h "[%.1f Ā°C]" <temperature>
Number FF_HotTank_01_Min12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_01_Max12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_02_Min12h "[%.1f Ā°C]" <temperature>
Number FF_HotTank_02_Min12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_02_Max12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_03_Min12h "[%.1f Ā°C]" <temperature>
Number FF_HotTank_03_Min12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_03_Max12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_04_Min12h "[%.1f Ā°C]" <temperature>
Number FF_HotTank_04_Min12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_04_Max12h_Val "- Max. Temp [%.1f Ā°C]" <temperature>
Number FF_HotTank_TotEnergy "Energy in hot water" <energy>
Number FF_HotTank_Delta "Difference in Energy" <energy>
To derive some of the min/max values from our data, we create a rule such as the following which is triggered when a device in group āFF_HotTank_01ā changes. To save some space, the section of the rule below is only complete for the first two sensors!
rule "Calculate high and low of hot tank sensor 01"
when
Item FF_HotTank_01 changed
then
var Number FF_HotTank_01_Min12h
var Number FF_HotTank_01_Max12h
// var Number FF_HotTank_01_Min24h
// var Number FF_HotTank_01_Max24h
if (FF_HotTank_01.state instanceof DecimalType) {
FF_HotTank_01_Min12h = (FF_HotTank_01.minimumSince(now.minusHours(12), "influxdb").state as DecimalType)
postUpdate(FF_HotTank_01_Min12h_Val, FF_HotTank_01_Min12h)
FF_HotTank_01_Max12h = (FF_HotTank_01.maximumSince(now.minusHours(12), "influxdb").state as DecimalType)
postUpdate(FF_HotTank_01_Max12h_Val, FF_HotTank_01_Max12h)
}
end
rule "Calculate high and low of hot tank sensor 02"
when
Item FF_HotTank_02 changed
then
var Number FF_HotTank_02_Min12h
var Number FF_HotTank_02_Max12h
// var Number FF_HotTank_01_Min24h
// var Number FF_HotTank_01_Max24h
if (FF_HotTank_02.state instanceof DecimalType) {
FF_HotTank_02_Min12h = (FF_HotTank_02.minimumSince(now.minusHours(12), "influxdb").state as DecimalType)
postUpdate(FF_HotTank_02_Min12h_Val, FF_HotTank_02_Min12h)
FF_HotTank_02_Max12h = (FF_HotTank_02.maximumSince(now.minusHours(12), "influxdb").state as DecimalType)
postUpdate(FF_HotTank_02_Max12h_Val, FF_HotTank_02_Max12h)
}
end
Then to simply display this min/max data in a sitemap, we can show it as follows:
sitemap hottank label="hottank"
{
Frame label="Tank State" {
Text item=FF_HotTank_01
Text item=FF_HotTank_02
Text item=FF_HotTank_03
Text item=FF_HotTank_04
}
Frame label="Sensor 01" {
Text item=FF_HotTank_man label="Current Value"
Text item=FF_HotTank_01
Text item=FF_HotTank_01_Min12h_Val label="Min 12hrs"
Text item=FF_HotTank_01_Max12h_Val label="Max 12hrs"
Slider item=FF_HotTank_man label=Temperature
}
Frame label="Sensor 02" {
Text item=FF_HotTank_02
Text item=FF_HotTank_02_Min12h_Val label="Min 12hrs"
Text item=FF_HotTank_02_Max12h_Val label="Max 12hrs"
}
Frame label="Sensor 03" {
Text item=FF_HotTank_03
Text item=FF_HotTank_03_Min12h_Val label="Min 12hrs"
Text item=FF_HotTank_03_Max12h_Val label="Max 12hrs"
}
Frame label="Sensor 04" {
Text item=FF_HotTank_04
Text item=FF_HotTank_04_Min12h_Val label="Min 12hrs"
Text item=FF_HotTank_04_Max12h_Val label="Max 12hrs"
}
}
(continued belowā¦)