With rule machine, turn on light only when mode is night

Probably an easy question, but I haven't figured it out for myself yet. I'm looking to turn on a light (actuator) and so I need to use rule machine for this. How can I turn this light on only when night mode is active, so that when day mode returns it's off? Thanks for your explanations.

There are numerous ways to skin this cat, but if it was me, I'd use 2 rules... In the first, I'd use Mode = Night as a Required Expression for turning on the light (using whatever trigger you want). In the second rule, I'd use that light = on as a Required Expression, and then use Mode becomes Day as the trigger to turn it off.

But again, there are numerous other ways to accomplish this too, so other folks may have other suggestions.

Thank you for the idea. That's one way it could work. But I'd prefer if it were possible to do everything in a single rule.

Basically, one way to do it in a rule. . .

Required expression: When Mode Changes

Actions:
If MODE = DAY Then
LIGHT/SWITCH = OFF
Else
LIGHT/SWITCH = ON
EndIf

-OR-

Actions:
If NOT MODE = DAY and LIGHT/SWITCH = OFF Then
LIGHT/SWITCH = ON
Else
LIGHT/SWITCH = OFF
EndIf

the particularity of my need is that the light in question is managed by a virtal device (actuator) which is in fact a simple button that sends a signal and whose state I can't know. How can I make it send the action again when night mode changes to day mode (to turn off the light)?

My rule so far:

I wouldn’t use “change” for my trigger. I would keep it simple:

Triggers: Mode = Day; Mode = Night
Action: Push button

1 Like

I used Mode Changed to cover [cough] the Day vs. Evening (suns. to 11pm) or Night (11pm-sunr.) Modes that I use in a 24 day. Should something hiccups between Day and Evening, then Night Mode activating would pick it up. Too much? Overthinking it? Still learning, I do like the simplicity you suggested too.

There are many different ways to write rules that work and everyone's philosophy will be different. I personally do not like using "change" because it adds ambiguity to a trigger. I try to write my triggers clearly (Mode = Day; Motion = Active; etc...) so that I am defining the Event that triggers the action (Mode = Day) rather than having Hubitat calculate that a triggering event has occurred (Mode has changed from Night to Day). These two statements are slightly different even if the ultimate action is still the same.

1 Like

Understood and thanks for your perspective. That helps to evolve my own approaches and perspectives on tasks, as I get more ambitious. :grin: