Creating a switch to turn rules on and off

Hi there, I have successfully setup this rule to work however I’m having a problem with the state change, most specifically on my mobile. I created a switch to control the rule below but the problem I’m having is that when I turn the rule switch on with my mobile phone it does not get picked up on the desktop. How can I have state changes reflected with some code? Below the rule code is the items code. The bedroom lights switch successfully updates on the desktop when switched on the mobile and vice versa. I’m assuming this is fine because of the MQTT message sent but how do I have this same functionality with a “floating” switch?


rule “turn burner on for work”


Time cron “0 5 6 ? * MON-FRI *”


if (Burner_Wakeup_Switch.state==ON)



Switch Bedroom_Lights “Bedroom Lights” (LR,gLight)

Switch Burner_Wakeup_Switch “Toggle Burner on Wakeup”

First, How to use code fences.

What do you mean by this statement. Are you saying that when you change the switch on your phone the Rule desn;t get the state or that the sitemap or HABPanel display on the desktop doesn’t show the new state?

State changes are state changes. Either they happen or they do not happen. So is Burner_Wakeup_Switch not changing state (you can see that in events.log) or is the UI just not showing that the state has changed?

Thanks for the prompt reply Rich, you are really helping everyone out on here. I’ve read through countless topics and they all seem to have multiple replies from you.So the Burner_Wakeup_Switch is changing state when I check the log, however if I check the sitemap on my mobile device, it’s status still shows as off.

I’ve tried this code you posted in another topic but I can’t seem to get it to work.

rule "status received update"
    Item Burner_Wakeup_Switch received update
   Burner_Wakeup_Switch.postUpdate(if(Burner_Wakeup_Switch.state.toString == "1") ON else OFF)

What you’re missing is basic coding experience. Here’s what u should be doing…

rule "status received update"
    Item Burner_Wakeup_Switch received update 
    Burner_Wakeup_Switch.postUpdate( Burner_Wakeup_Switch.state.toString == "1" ? ON : OFF)

But your logic doesn’t make sense to me. Is this an Item switch already? Basically, your rule says to update the item with its own state when it receives an update.

Then the problem has nothing to do with the Rule. There are known bugs in some browsers where it doesn’t always update the sitemap immediately with changes to the Items.

Actually, Ryan has the correct syntax for the Rules DSL. The trinary operator is indeed:

if(condition) trueValue else falseValue

Why they changed I can’t say, perhaps they liked it better that way.

But, like Lucky says, the Rule makes no sense.

Walk through the Rule step by step.

  1. Burner_Wakeup_Switch receives an update. Since it is a Switch Item that update can only be ON, OFF, or NULL
  2. We check to see if Burner_Wakeup_Switch.state == “1”. Since “1” is not a possible state for a Switch this will always be false so the trinary will always return OFF
  3. We postUpdate OFF to Burner_Wakeup_Switch which takes us back to 1. Loop forever.

What are you trying to accomplish?