var setPoint = 18.0
rule "Thermostat"
when
Item MQTTItem changed
then
var ambientTemp = MQTTItem.state as Number
if (setPoint > ambientTemp) {
GPIO1Item.sendCommand(ON)
GPIO2Item.sendCommand(OFF)
} else if (setPoint < ambientTemp) {
GPIO1Item.sendCommand(OFF)
GPIO2Item.sendCommand(ON)
} else {
GPIO1Item.sendCommand(OFF)
GPIO2Item.sendCommand(OFF)
}
end
From the photo you posted above, I’m not sure how that GPIO binding is in play. THe photo is just primarily showing you are able to get data from MQTT.
thank you lucky
yes ; but now i’m trying an auther exemple the GPIO bindig is already installed and i have tested it in my last exemple,
now about this rule programme i want to understand how can i command gpio pins in item
If you are planning to drive a large appliance with this code (air conditionner, boiler…) you will eventually damage it because you are going to turn it on and off a lot.
You need to add an offset (A small band off temperature where appliance will remain in one state instead of oscillating between the two)
var setPoint = 18.0
var offset = 1.0
rule "Thermostat"
when
Item MQTTItem changed
then
var ambientTemp = MQTT.state as Number
var turnOnTemp = setPoint + (offset / 2)
var turnOffTemp = setPoint - (offset /2)
if (ambientTemp >= turnOnTemp) {
GPIO1Item.sendCommand(OFF)
GPIO2Item.sendCommand(ON)
} else if (ambientTemp <= turnOffTemp) {
GPIO1Item.sendCommand(ON)
GPIO2Item.sendCommand(OFF)
}
end
This way, the air con will turn on when the temperature is above 18.5 and turn off when below 17.5.
You can adjust the value, but it you make the offset too narrow, you will risk damaging your unit.
thank you very much vzorglub , i have problem about setpoint , when i use sitemap for chenging setpoint and command a temperature . this solution does not working
and those are my sitemap, items and rules:
Is in the wrong place. That will not work as a global variable in the rule file.
Put that line inside the rule before turnOnTemp = setPoint + (offset / 2)