[SOLVED] Help with a rule


(Runar) #1

Hey. Im trying to make a rule, but Im stuck :frowning:, pretty new to this game :stuck_out_tongue:
It is supposed to turn on oven if temperature is under or over a certain value, but only if a virtual switch is pressed. What am I doing wrong?


(Runar) #2

This is the rule

rule " OVN Gjesterom PÅ / AV INGEN GJEST"

when

Item GJEST_BESOK.state == OFF

then

if (SENSORGjesterom_ActualTemperature.state < 5.0) {

Item DEVICEOvnGjesterom_Switch.sendCommand(ON)

}

if (SENSORGjesterom_ActualTemperature.state > 12.0) {

Item DEVICEOvnGjesterom_Switch.sendCommand(OFF)

}

end

rule " OVN Gjesterom PÅ / AV GJEST"

when

Item GJEST_BESOK.state == ON

then

if (SENSORGjesterom_ActualTemperature.state < 18.0) {

Item DEVICEOvnGjesterom_Switch.sendCommand(ON)

}

if (SENSORGjesterom_ActualTemperature.state > 22.0) {

Item DEVICEOvnGjesterom_Switch.sendCommand(OFF)

}

end


(Vincent Regaud) #3

First please use the code fences when posting code…

Second, install VSCode with the openHABextension to validate your code
Third, read: https://www.openhab.org/docs/configuration/rules-dsl.html

rule " OVN Gjesterom PÅ / AV INGEN GJEST"
when
    Item GJEST_BESOK changed
then
    var switchCommand = "OFF"
    val temperature = SENSORGjesterom_ActualTemperature.state as Number

    if (GJEST_BESOK.state == NULL) return; // Do Nothing if NULL

    if (GJEST_BESOK.state == OFF) {
        if (temperature < 5.0) {
           switchCommand = "ON"
        }
        if (temperature > 12.0) {
           switchCommand = "OFF"
        }
    if (GJEST_BESOK.state == ON) {
        if (temperature < 18.0) {
           switchCommand = "ON"
        }
        if (temperature > 22.0) {
           switchCommand = "OFF"
        }
    }
    DEVICEOvnGjesterom_Switch.sendCommand(switchCommand)

end

(Runar) #4

Thank you. :slight_smile: And Thanks for the tips. Like I said Im new and still learning :smiley:


(Vincent Regaud) #5

One more tip: