Basic Rule, Switch "Is On", "Is Off" request

I have a place where the power goes out at night, its battery and solar powered. I have a security light turn on after sunset and turn off before sunrise. If the power goes out in the middle of night and power turns back on well after sunrise the light uses the last known state and stays on all day. In basic rules I could correct this if it had Switch "Is On" and "Is Off" in addition to the existing "Turns ON" and Turns Off"

-If light "Is On",
-Restriction: between sunrise and sunset,
-Turn off.

I can see this helpful as well for kids leaving lights on all day when not needed.

I'm not sure you could; Basic Rule "triggers" are events, not states. Turning on is an event; being on is a state (or condition). The Basic Rule would need something to "wake"/trigger it, which would necessarily be either a location or device event or a schedule (specific time, etc.). How would it know when to check? It isn't impossible theoretically; you could basically do it already with a time trigger and a restriction for a switch's state, but you can only set a single time "trigger," so it's probably a poor choice. In any case, I think the desired approach to solving this problem isn't looking at it from the right angle for this reason.

Not that this is a good idea, either; you could do a periodic schedule in Rule Machine. But you'll be triggering the rule a lot, often to do nothing. I suppose if it's mostly overnight, you may not care, but it's generally better to respond to actual events if you can (but you probably can't here if they don't report state on physical power change, as most don't).

For bulbs, you might even be able to do something better: are these Zigbee, and do the new "Advanced Zigbee..." drivers work with them? (Make sure to hit "Configure" after you switch drivers.) If so, there is an in-driver option for default power-on state there that will avoid you needed to handle this so the app level at all. Some Z-Wave bulbs also have this as a parameter you can set.


I have a similar situation where I need to detect power outage / restore.

I ended-up plugging a Ring Z-Wave range extender in an outlet connected to that circuit. It sends an event when the device is on battery or AC which I use to trigger a rule to turn off lights that would otherwise turn on due to the power restore.

1 Like

Yeah, I could do this in Rule Machine, but Basic Rules is cool, RM is not cool but it's awesome.

This in Basic Rules Switch would work:
State: "is On"
State: "Is Off"
Event: "Turns On"
Event: "Turns Off"

You can already trigger on events and restrict based on states in Basic Rule if that's what you want to do: the switch on/off event would be your "when," and you can use "Restrictions" to only make your action run under certain conditions. But it sounds like your bulbs don't send (to the hub) events for this real-world event, so I'm again not sure this would really work.

In any case, the "when" needs to be an event, not merely a state.