Hi everyone im stuck on my last rule its a rule for movie mode off
it is triggered by a button and needs to be stopped by pressing same button again and also when kodi changes from playing to stopped
the rule runs fine as expected when enabled by button and stopping kodi the rule runs perfect but when you press the button again the rule does not compete
rule "Movie Mode ON"
when
Item Movie_Mode_Trigger changed from OFF to ON // gets set to on by habpannel switch
then
Lamp1_Brightness.sendCommand("1")
BULB6LRMAIN1_Color.sendCommand("63,3,0")
Disable_Amp_Rule.sendCommand("ON")
logInfo("Rule", "Movie Mode ON ran (Movie Mode.rules)")
end
rule "Movie Mode OFF"
when
Item Movie_Mode_Trigger changed from ON to OFF or //Turn off by same habpannel button
Item KodiHTPC2_Stop changed from OFF to ON // when kodi stops
then
if (Movie_Mode_Trigger.state == ON) { //Because i only want this rule to run when enabled
Lamp1_Brightness.sendCommand("40")
Disable_Amp_Rule.sendCommand("OFF")
Movie_Mode_Trigger.sendCommand("OFF") //Sets button back off
logInfo("Rule", "Movie Mode OFF ran (Movie Mode.rules)")
}
end
there are no errors in the log the button that enables and should disables the rule is linked to `Movie_Mode_Trigger
is it because when the button is pressed my rule is no longer true ? how should i solve this? should i add a virtual switch at the end of the rule that can replace the moviemode trigger or is there a cleaner way or writing the code ?
your second rule is triggered when the state of Movie_Mode_Trigger changes to OFF. The action of that rule starts with an if-statement which checks whether Movie_Mode_Trigger is ON. This can never be true, hence nothing will happen. You probably want to remove the if-statement, if it is triggered by a switch.
You say, you like to trigger the rules by a button, however. Do you mean a physical button or within a graphical user interface?
i mean a button running on habpannel and the reason i added the if statement was that i don’t want the rule to run all the time only after being enabled by the habpannel button this button is linked to Movie_Mode_Trigger and sets it to ON
But the fact remains, when the Rule triggers when you change Movie_Mode_Trigger to OFF, the rule will never do anything because Movie_Mode_Trigger’s state will be OFF.
So either it makes no sense to trigger your rule with Item Movie_Mode_Trigger changed from ON to OFF or if makes no sense to have the if statement, because the Rule will never do anything when triggered by Movie_Mode_Trigger.
rule "Movie Mode ON"
when
Item Movie_Mode_Trigger changed from OFF to ON
then
Lamp1_Brightness.sendCommand("1")
BULB6LRMAIN1_Color.sendCommand("63,3,0")
Disable_Amp_Rule.sendCommand("ON")
Movie_Mode_Enabled.sendCommand("ON")
logInfo("Rule", "Movie Mode ON ran (Movie Mode.rules)")
end
rule "Movie Mode OFF"
when
Item Movie_Mode_Trigger changed from ON to OFF or
Item KodiHTPC2_Stop changed from OFF to ON
then
if (Movie_Mode_Enabled.state == ON) {
Lamp1_Brightness.sendCommand("40")
Disable_Amp_Rule.sendCommand("OFF")
Movie_Mode_Trigger.sendCommand("OFF")
Movie_Mode_Enabled.sendCommand("OFF")
logInfo("Rule", "Movie Mode OFF ran (Movie Mode.rules)")
}
end
as far as i can tell it seems to work ok the tv is currently in use so cant do much testing
im working on my last rule now im glad i moved them over to text based they are hard to understand and get running but alot easier to edit and glance over what a rule is doing