[SOLVED] I want to set a temperateure value with air-conditioner

Hi i’m biginner plzz help me :
is ther a way to set the state of raspberry pi’s GPIO with setpoint items.
-i have an LED1 conect on GPIO “pin17”

  • an auther LED2 conect on GPIO “pin15”
    -an ESP8266 send a sensor datta (ambiant_temp) to the broker via MQTT ( it’s working)
  • i want :
    if (setpoint value) >(ambiant_temp) ==> LED1= alight
    if (setpoint value) <(ambiant_temp) ==> LED2= alight
    else LED1=LED2=0

Have you taken a look at the GPIO Binding?

This can also easily be done through with the Exec Binding

yes i have insttaled gpio binding and I tested it with a simpl exempl and it’s working now i need how i can configure my rules for having my task

1 Like
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

thank you very much vzorglub :slight_smile: .

can you explain to me about GPIO item , i don’t understand where is GPIO’s topic , and how to command it .

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.

https://docs.openhab.org/addons/bindings/gpio1/readme.html

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

Show us your items that are bound to the GPIO channels

my item


sitmap
sitmap
rule
Capture

thank you very much ,
it’s working :slight_smile:

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:



sifou-3

First line of your rules

var setPoint = apt_t.state as Number

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)

1 Like