How would you improve this simple rule (JUST CHAT) (CLOSED)

just wondering how everyone would improve this rule i look forward too seing some replys how would you make it shorter ? how would you improve on it and what else would you add its a simple rule but the best i can make at the moment

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) {
    if(now.getHourOfDay > 9 && now.getHourOfDay < 16) {} //9AM - 4PM
    Lamp1_Brightness.sendCommand("70")
    Disable_Amp_Rule.sendCommand("OFF")
    Movie_Mode_Trigger.sendCommand("OFF")
    Movie_Mode_Enabled.sendCommand("OFF")
    logInfo("Rule", "Movie Mode OFF Running (Routines.rules)")
  }
if (Movie_Mode_Enabled.state == ON) {
    if(now.getHourOfDay > 16 && now.getHourOfDay < 20) {} //4PM - 8PM
    Lamp1_Brightness.sendCommand("60")
    Disable_Amp_Rule.sendCommand("OFF")
    Movie_Mode_Trigger.sendCommand("OFF")
    Movie_Mode_Enabled.sendCommand("OFF")
    logInfo("Rule", "Movie Mode OFF Running (Routines.rules)")
  }
if (Movie_Mode_Enabled.state == ON) {
    if(now.getHourOfDay > 20 && now.getHourOfDay < 22) {} //8PM - 10PM
    Lamp1_Brightness.sendCommand("30")
    Disable_Amp_Rule.sendCommand("OFF")
    Movie_Mode_Trigger.sendCommand("OFF")
    Movie_Mode_Enabled.sendCommand("OFF")
    logInfo("Rule", "Movie Mode OFF Running (Routines.rules)")
  }
if (Movie_Mode_Enabled.state == ON) {
    if(now.getHourOfDay > 22 && now.getHourOfDay < 9) {} //10PM - 9AM
    Lamp1_Brightness.sendCommand("10")
    Disable_Amp_Rule.sendCommand("OFF")
    Movie_Mode_Trigger.sendCommand("OFF")
    Movie_Mode_Enabled.sendCommand("OFF")
    logInfo("Rule", "Movie Mode OFF Running (Routines.rules)")
  }
end

This is wrong

{}
if(now.getHourOfDay > 22 && now.getHourOfDay < 9) {} //10PM - 9AM

Try this

if (Movie_Mode_Enabled.state == ON) {
    if     (now.getHourOfDay >= 22 || now.getHourOfDay < 7) {var x = 10}
    else if(now.getHourOfDay >= 20) {x = 30}
    else if(now.getHourOfDay >= 16) {x = 60}
    else {x = 70}
    Lamp1_Brightness.sendCommand(x)
    Disable_Amp_Rule.sendCommand("OFF")
    Movie_Mode_Trigger.sendCommand("OFF")
    Movie_Mode_Enabled.sendCommand("OFF")
    logInfo("Rule", "Movie Mode OFF Running (Routines.rules)")
    }
1 Like

i will try that its alot better than my rule i was only going too look at what people would do and now i actually need help lol

it took me ages to type the old rule :frowning:

what was wrong with the way i did it ? it still looks ok too me

You need to have your Lamp1_Brightness.sendCommand inside of your brackets:

if(now.getHourOfDay > 16 && now.getHourOfDay < 20) Lamp1_Brightness.sendCommand("60")

or

if(now.getHourOfDay > 16 && now.getHourOfDay < 20) { 
   Lamp1_Brightness.sendCommand("60")
}

I will have to check my other rules to make sure that they are right

when i made and tested this rule it seemed to run ok

i have done the same in another rule too

rule "Xbox Online Power TV" //ALL MODES DAILY
when
Item TylerSXboxOnline_Online changed
then
if(now.getMinuteOfDay > 900 && now.getMinuteOfDay < 1140) {} //3PM <> 7PM
    if( TylerSXboxOnline_Online.state == ON ) {
    PLUG6TylerSTV_Switch.sendCommand ("ON")
    logInfo("RULE", "Xbox Online Power TV Running Kids.Rules")
    logInfo("RULE", "Tyler's TV ON")
    }
if(now.getMinuteOfDay > 900 && now.getMinuteOfDay < 1140) {} //3PM <> 7PM
    if( TylerSXboxOnline_Online.state == OFF ) {
    PLUG6TylerSTV_Switch.sendCommand ("OFF")
    logInfo("RULE", "Xbox Online Power TV Running Kids.Rules")
    logInfo("RULE", "Tyler's TV OFF")
}   
end

Your (old) rule only do that:

if (Movie_Mode_Enabled.state == ON) {
    Lamp1_Brightness.sendCommand("10")
    Disable_Amp_Rule.sendCommand("OFF")
    Movie_Mode_Trigger.sendCommand("OFF")
    Movie_Mode_Enabled.sendCommand("OFF")
    logInfo("Rule", "Movie Mode OFF Running (Routines.rules)")
  }

That is what are you can have tested.

It would have partially worked. Basically if Movie_Mode_Enabled.state == ON, it would have done each block as the if(now.gethour…) isn’t doing anything.

It would have turned your light to 70, turned all your items listed off, made a log entry and moved to the next block. The next block would have set the light to 60, turned everything off (again) and added another entry. Repeat for the next block with 30 and then 10…

Did you not get four log entries of “Movie Mode OFF Running (Routines.rules)”?

How can a value at once be > 22 and < 9???

thats what the light set too 10% when i tested it and that was what i was expecting too happen

noob mistake

i was thinking in time i thought it knew another noob mistake :frowning:

if(now.getHourOfDay > 15 && now.getHourOfDay < 19) { //3PM <> 7PM
    PLUG6TylerSTV_Switch.sendCommand (TylerSXboxOnline_Online.state)
    logInfo("RULE", "Xbox Online Power TV Running Kids.Rules")
    logInfo("RULE", "Tyler's TV "+TylerSXboxOnline_Online.state.toString)
}   
1 Like

i understand whats wrong now its because im an idiot lmao thanks for that

i will check the logs and get back too you on that give me a moment

yes there were 4 it was running just as you said it was

No you aren’t. You’re learning. We all have been there. I still make stupid mistakes… trust me :slight_smile:

One take away is to get a good tail going on your logs while you are testing rules. It would have been a solid indicator that something odd was happening.

i normally watch the log:tail i didn’t even realise anything was wrong with the rule so i didn’t bother this time i only posted too see what people would do iv learned a few lessons lol

log:tail has helped me create a few rules already :slight_smile: