I have setup a number of virtual switches that have worked since version 1.1, and were still working in 4.3.4… after the upgrade to 5…. the switches toggle, but don’t execute the rule. But the rule still works, I can go through settings > Rules and it executes just fine… so I’m missing something ….
rules:
rule “Trigger Alexa ShowTime”
when
Item AlexaShowTime changed from OFF to ON
then
if (AlexaMasterSwitch.state == ON) {
TL DR;
}
AlexaShowTime.sendCommand(OFF)
end
In future posts please use code fence blocks. It makes the code much easier to read.
```
code goes here
```
This rule only triggers when AlexaShowTime changes from OFF to ON. It on’y trigger if it changes to any other state but ON and it won’t trigger unless the Item started in the OFF state and changed to ON (i.e. it’s not NULL and not UNDEF). Look at events.log and verify that the Item is actually changing from OFF to ON when you expect the rule to run.
Add logging so you can see in openhab.log that the rule is running. In particular log out what AlexaMasterSwitch isbefore the if statement.
OK, I’m not sure what happened, but I rolled back to 4.3.4 to make the changes to the rule and make sure that it worked as expected…
And to keep you from having to read the rest, once it worked (logged in notepad as I went), I re-implemented 5.0.2 and now…. my virtual switches are toggling the rules….So I’ll say it’s resolved but unduplicatable.
But the troubleshooting point’s @rlkoshak pointed out are very valid so below are my changes and the results:
Modified rules file:
rule "Trigger Alexa ShowTime"
when
Item AlexaShowTime changed from OFF to ON
then
logInfo("StartLogCopy","Start Log Copy Here - Redact as necessary")
logInfo("AlexaMasterSwitch", "AlexaMasterSwitch is " + AlexaMasterSwitch.state.toString())
logInfo("AlexaShowTime", "AlexaShowTime is " + AlexaShowTime.state.toString())
if (AlexaMasterSwitch.state == ON) {
TL DR;
}
AlexaShowTime.sendCommand(OFF)
logInfo("AlexaShowTime", "AlexaShowTime is " + AlexaShowTime.state.toString())
logInfo("AlexaMasterSwitch", "AlexaMasterSwitch is " + AlexaMasterSwitch.state.toString())
logInfo("EndLogCopy","End Log Copy Here")
end
Log in 4.3.4:
2025-10-24 10:53:53.470 [INFO ] [enhab.core.model.script.StartLogCopy] - Start Log Copy Here - Redact as necessary
2025-10-24 10:53:53.470 [INFO ] [.core.model.script.AlexaMasterSwitch] - AlexaMasterSwitch is ON
2025-10-24 10:53:53.470 [INFO ] [nhab.core.model.script.AlexaShowTime] - AlexaShowTime is ON
2025-10-24 10:53:53.776 [INFO ] [nhab.core.model.script.AlexaShowTime] - AlexaShowTime is ON
2025-10-24 10:53:53.798 [INFO ] [.core.model.script.AlexaMasterSwitch] - AlexaMasterSwitch is ON
2025-10-24 10:53:53.799 [INFO ] [openhab.core.model.script.EndLogCopy] - End Log Copy Here
Log in 5.0.2:
2025-10-24 11:08:09.363 [INFO ] [enhab.core.model.script.StartLogCopy] - Start Log Copy Here - Redact as necessary
2025-10-24 11:08:09.363 [INFO ] [.core.model.script.AlexaMasterSwitch] - AlexaMasterSwitch is ON
2025-10-24 11:08:09.363 [INFO ] [nhab.core.model.script.AlexaShowTime] - AlexaShowTime is ON
2025-10-24 11:08:09.678 [INFO ] [nhab.core.model.script.AlexaShowTime] - AlexaShowTime is ON
2025-10-24 11:08:09.678 [INFO ] [.core.model.script.AlexaMasterSwitch] - AlexaMasterSwitch is ON
2025-10-24 11:08:09.678 [INFO ] [openhab.core.model.script.EndLogCopy] - End Log Copy Here