Hi,
this is my first time to show a ‘more than a few lines’ rule at the formum with special thanks to @Dim, @job, and @rlkoshak . It is all working, no errors, but if anyone could comment on smart improvements I would really appriciate that! I hope other Lan2RF users may bennefit. (I think it’s mostly Dutch residents). Because of me being Dutch: WK is Woonkamer = Livingroom. I didn’t translate my items.
My situation: I have a Intergas boiler with Opentherm, Honeywell Round (wired) and a Intergas Lan2RF gateway which is connected to the boiler through RadioFrequency and to my network through UTP, ence the name Lan2RF.
I can set the setpoint with a http-Get request, and receive current data about i.e. setpoint (not updated immediately) and currend temperature. These data are stored in a json-file. The temperatures are calculated from two numbers, the lsb (least significant bit) and the msb (most significant bit). To get from a string (the jason file) to a number, I used:
- JSONPATH
- store the value in an item
- calculte new value from item lsb and item msb
Because it takes up to a minute to set a new setpoint from openhab in the thermostat, I have to postpone accepting new setpoints from the thermostat untill setting one from openhab has finnished, and vise versa. I have come up with a blocking switch for that.
I used a mapping-file to get human readable status-info from the boiler.
To-Do:
- Also get error messages and only show them when there is an error
- Get info on water set and return temperatures and show them on a ‘admin’'page
- Somehow get the power used (percentage) since that is not in the API-documentation but it should be possible to get this info since the android app does this too
Here are my files:
services/http.cfg
format=false # very important!
CV_data.url=http://192.168.0.6/data.json?heater=%3C0611f022270%3E
CV_data.updateInterval=60000
transform/BoilerStatus.map
85=sensortest
170=service
204=tapwater
51=tapwater_int
240=boiler_int
15=boiler_ext
153=postrun_boiler
0=opentherm
102=zone-heating #this one is not in the API-manual
255=buffer
24=frost
231=postrun_ch
126=standby
37=central_heating_rf
items/default.items
Group LivingRoomHeating "LivingRoomHeating"
Group Heating "Heating"
Number T_WK_is "Temp Livingroom [%.1f °C]" <temperature> (Heating)
Number T_WK_sp "Setpoint Temp Livingroom [%.1f °C]" <temperature> (Heating)
Number Room_temp_set_1_lsb
Number Room_temp_set_1_msb
Switch T_WK_SP_block1 { expire="5m,command=OFF" }//block setting new setpoint from Thermostat-data, expire incase of wrong initialisation
Switch T_WK_SP_block2 { expire="5m,command=OFF" }//block setting new setpoint from openHAB, expire incase of wrong initialisation
Number WK_room_temp_1_lsb "Thermostat Tis lsb" { http="<[CV_data:10000:JSONPATH($.room_temp_1_lsb)]" }
Number WK_room_temp_1_msb "Thermostat Tis msb" { http="<[CV_data:10000:JSONPATH($.room_temp_1_msb)]" }
Number WK_room_temp_set_1_lsb "Thermostat setpoint lsb" { http="<[CV_data:10000:JSONPATH($.room_temp_set_1_lsb)]" }
Number WK_room_temp_set_1_msb "Thermostat setpoint msb" { http="<[CV_data:10000:JSONPATH($.room_temp_set_1_msb)]" }
Number WK_displ_code "CV-status [MAP(BoilerStatus.map):%s]" { http="<[CV_data:10000:JSONPATH($.displ_code)]" }
sitemap/default.sitemap
Frame item=LivingRoomHeating {
Text item=T_WK_is
Setpoint item=T_WK_sp minValue=10 maxValue=24 step=0.5
//Switch item=T_WK_SP_block1 for debug
//Switch item=T_WK_SP_block2 for debug
Text item=WK_displ_code
}
rules/default.rules
val String debug = "ON" //set ON for debug messages
val String Lan2RF_ip = "192.168.0.6" //check the right IP in browser!
rule "Update Thermostat SP from openhab"
when
Item T_WK_sp changed
then
// construct url for setting thermostat//
var Number celsius
var String data
if(T_WK_SP_block2.state == ON){
if(debug =="ON"){
logDebug("Update Thermostat SP", "waiting for setpoint from Thermostat to finnish") //Wait untill new setpoint arrived
}
} else {
val twish = T_WK_sp.state as Number
val setp = (twish - 5 ) * 10
T_WK_SP_block1.sendCommand(ON) //Make sure no new setpoints are received through http-binding in other rule
sendHttpGetRequest("http://"+Lan2RF_ip+"/data.json?heater=0&setpoint="+setp+"&thermostat=0%C3%97") //set the new setpoint
if(debug =="ON"){
logDebug("Update Thermostat SP", "step 1 setpoint sent: "+setp+"°C, this means: "+twish+"°C" )
}
do {
Thread::sleep(30000) //wait 30 seconds before resending setpoint and get new data
if(debug =="ON"){
logDebug("Update Thermostat SP", "step 2, waited 30 sec, now resend setpoint and get current setpoint from thermostat" )
}
data = sendHttpGetRequest("http://192.168.0.6/data.json?heater=0&setpoint="+setp+"&thermostat=0%C3%97") //resend untill succes
WK_room_temp_set_1_lsb.sendCommand(transform("JSONPATH","$.room_temp_set_1_lsb", data)) //put in item to get string to number
WK_room_temp_set_1_msb.sendCommand(transform("JSONPATH","$.room_temp_set_1_msb", data))
if(debug =="ON"){
logDebug("Update Thermostat SP", "step 3 data received, checking setpoint in thermostat." )
}
val lsb = WK_room_temp_set_1_lsb.state as Number
val msb = WK_room_temp_set_1_msb.state as Number
celsius = (lsb + msb *256) / 100
if(debug =="ON"){
logDebug("Update Thermostat SP", "step 4 setpoint in thermostat: "+celsius+"°C, should be: "+twish+"°C" )
}
} while (twish != celsius)
T_WK_SP_block1.sendCommand(OFF)
if(debug =="ON"){
logDebug("Update Thermostat SP", "step 5: Finnished!")
}
}
end
rule "Update Livingroom Thermostat setpoint from Thermostat"
when
Item WK_room_temp_set_1_lsb changed or
Item WK_room_temp_set_1_msb changed
then
if(T_WK_SP_block1.state == ON){
if(debug =="ON"){
logDebug("Update Thermostat SP from Thermostat", "waiting for setpoint from OpenHAB to finnish") //Wait untill new setpoint arrived
}
} else {
T_WK_SP_block2.sendCommand(ON)
val lsb = WK_room_temp_set_1_lsb.state as Number
val msb = WK_room_temp_set_1_msb.state as Number
val celsius = (lsb + msb * 256) / 100
T_WK_sp.postUpdate(celsius)
if(debug =="ON"){
logDebug("Update Thermostat SP from Thermostat", "temperature setpoint recieved: "+celsius+"°C")
}
Thread::sleep(10000) //wait 30 seconds before allowing input from OH-setpoint
T_WK_SP_block2.sendCommand(OFF)
}
end
//
rule "Update Livingroom Thermostat real temperature"
when
Item WK_room_temp_1_lsb changed or
Item WK_room_temp_1_msb changed
then
val lsb = WK_room_temp_1_lsb.state as Number
val msb = WK_room_temp_1_msb.state as Number
val celsius = (lsb + msb * 256) / 100
T_WK_is.postUpdate(celsius)
if(debug =="ON"){
logDebug("Update Thermostat", "temperature recieved and calculated")
}
end
I hope I don’t mis anything, or I will edit later. It’s hard to see in this little window.