Lights off Rule

What would be the best way to write a rule that turns a light off 30 min after its been turned on and restricted by a virtual switch?

what is the virtual switch restricting? Restricting on? Restricting OFF?? Using RM or using Simple Lighting?

Here's my first guess at what you're asking.

With "Virtual Example" OFF, then when the light is on, it turns off 30 mins later. If "Virtual Example" is ON, then this Rule doesn't exist (functionally.)

My daughter was getting up in the middle of the night and leaving the Kitchen light on. So I have it turning off after 30 min, but I restrict the hours that happens.

Can I ask why you are making using both Lights ON and OFF conditions? Wouldn't you only need ON for the rule to work? Sorry to hijack OP just curious....

I think I read that it was best to define all the conditions, but I may be wrong. @bravenel, is it necessary or good practice to define all the conditions that a device can have or is it completely unnecessary?

On and OFF are defined as conditions, yet only ON is within Define Rule. As if the unused OFF wasn't there.

I'm thinking this has that "logic flaw" with the Time restriction. If the light gets turned on 15 mins before sunrise, it might not get turned off because the 30 min timer expires 15 min after sunrise. Same (but opposite) at the midnight end. If the light gets turned ON 15 mins before Midnight, then the 30 min timer won't get started. The light will never go off.

It is completely unnecessary. A rule will test the conditions as it is evaluated. In the case shown above, one of the conditions doesn't even appear in the rule, so it is completely irrelevant and never even looked at.

2 Likes

Thanks for confirming.

The virtual switch is a flag to indicate whether we have guests staying with us.

I think that means the Rule I "imagined" works. If you have guests, and turn OFF the virtual switch, the light does not auto turn off. It follows the physical switch.

Obviously if the "meaning" of the virtual switch needs to be opposite, Turn On the virtual switch to indicate, yes, you do have guests, that's easy too. Virtual Example = on vs off.

I ended up using the "switch to disable rule" option under restrictions in rule machine. Seems to be working as I had hoped.

1 Like

Rule Machine has a lot of ways to skin-the-cat :smiley: