Rules: Activate Rule with Switch Item

Hi all,

i have two rules implemented for my thermostats:

  1. Turn off in the evening
    rule “HeizungNachtWohnenAus”
    when
    Time cron “0 45 22 * * ? *” // um 22:45 und 0 Sekunden
    then
    sendHttpGetRequest(“http://IP:PORT/set/thermostat/ABBxxxxx/ch0000/off”) //Wohnzimmer
    end
  2. The other way round in the morning

I have two questions now:

  1. How can i put that into one rule instead of having 2 rules
  2. I want to control the rule via Habpanel, e.g. via Switch item. How can i implement that?

Thx & Regards

Hi, try this:

.rules

rule "HeizungNachtWohnenAus"
 when
   Time cron "0 45 22 * * ? *" or // um 22:45 und 0 Sekunden
   Time cron "0 0 0 * * ?" or // your time
   Item yourTriggerSwitch received command ON
 then
   sendHttpGetRequest(“http://IP:PORT/set/thermostat/ABBxxxxx/ch0000/off”) //Wohnzimmer
end

and .items

Switch   yourTriggerSwitch  "manually Trigger Switch [%s]"   (yourGroup)

thx for your reply.
I am not sure about your 2nd cron entry
_

Time cron "0 0 0 * * ?" or // your time

_
What is that for exactly?

Just a dummy-time. Replace it with the value, you want to have in the morning :wink:

Ok, so now i have a manual trigger for the rule. Thats good. Thx :slight_smile:

But, what i am looking for is to have a switch wether i want to have the rule activated or not.

E.g. I change the switch in the afternoon to disable the rule if we stay up longer in the evening.

Sorry, this was a bit naively from my point of view, as i’m a newbie.:thinking:

But if you can get the actual state of your thermostate, you can think about using an if-Statement or switch/case-Statement in the execution-block. Perhaps you find some information here.

1 Like

Use an if statement to check if the switch is on before execution of the rule.

Example:

rule "HeizungNachtWohnenAus"
 when
   Time cron "0 45 22 * * ? *" or // um 22:45 und 0 Sekunden
   Time cron "0 0 0 * * ?" or // your time
   Item yourTriggerSwitch received command ON
 then
    if(yourTriggerSwitch.state == ON)
   sendHttpGetRequest(“http://IP:PORT/set/thermostat/ABBxxxxx/ch0000/off”) //Wohnzimmer
end

When time or the switch is triggered the rule will fire. If you have the switch on then the rule runs. if the switch is OFF then the statement is false and nothing happens.

I guess you want to send different commands? The problem is, you can’t get an explicit information about which Time cron triggered te rule. But of course it’s possible to “guess” the correct one.

rule "HeizungNachtWohnenAus"
 when
   Time cron "0 45 22 * * ? *" or                  // um 22:45 und 0 Sekunden to switch off
   Time cron "0 0 6 * * ?" or                      // the time to switch on
   Item yourTriggerSwitch received command         // a switch to manually switch off/on
 then
    var String myCommand
    if(triggeringItem !== null) {             // rule was triggered by switch
        if(triggeringItem.state == ON) {
            myCommand = "on"
        } else {
            myCommand = "off"
        }
    } else {
        if(now.getMinuteOfDay == 22 * 60 + 45) {   // Time cron 0 45 22
            myCommand = "off"
        } else 
        if(now.getMinuteOfDay == 6 * 60 + 0) {     // Time cron 0 0 6
            myCommand = "on"
        } 
    }
    sendHttpGetRequest("http://IP:PORT/set/thermostat/ABBxxxxx/ch0000/"+myCommand) // Wohnzimmer
end

I will try and let you know…thank you.

Please be aware that I changed the code slightly

if(triggeringItem !== null)

instead of

if(triggeringItem.state != NULL)