I have a rule that turns on music in my workshop but only if the lights are on. The rule turns everything on fine, but is ignoring the status of the lights.
These rules take the high level form of When t happens, if c then do a , where t are the triggers that cause the rule run, c are the conditions that must be true for the rule to run, and a are actions to perform when the rule is triggered and allowed to run.
The rule has no triggers. Without triggers there’s no event to cause the rule to actually run. In this case you’d want to trigger the rule when Workshop_Lights_Power changes to ON. (Note, as currently implemented with this trigger you won’t need the condition)
And you’ll need another rule to handle turning off the music when Workshop_Lights_Power changes to OFF.
Or you can handle it all in one rule but you’ll need to use a Script Action to turn things on/off based on what Workshop_Lights_Power has changed to.
When you trigger the rule directly from the UI like that the condition is not applied.
A Script is just a rule without triggers or conditions. It doesn’t really fix the problem.
You’ll need to use a script action and test the state of the Item and do the appropriate action based on the state of the Item. You can’t use a condition for a rule triggered in this way.
Just to make sure you understand the parts of OH rules, you could have used the exact same Blockly code in the original rule in place of the commands to the Items. Just choose “Inline Script” as the Action. Give how you are using this it makes sense to have this be a Script. I just don’t want you or future readers thinking that the only way to code a script like this is in the Settings → Scripts. Code like this can be an Action or even a Condition in Settings → Rules as well.
I do use many scripts in my rules as well. But those all have triggers, and the conditions work well.
My favorite one is for the gates around my house. If a gate is opened after “dusk”, it turns on multiple lights, sends me a notice on my phone and cancels a share timer. Then if the gate remains open the lights stay on. When the gate is closed it waits 10 minutes and turns off all the lights. But if the gate is opened back up while the lights are on it resets the timer back to 10 minutes.
Thank you for your help in pushing me in the right direction.