# RM Example: Outdoor lights on/off with conditions

Looks like we have a new Examples category, sweet! This is a fairly simple rule, but I'm posting as an example of a basic "complex" rule input.

What it does
Turns my back yard lights on at Sunset. They will remain on until at least midnight. Between midnight and Sunrise, it depends on if someone is awake (awake = Home mode). If mode is home, the lights will stay/turn on, otherwise they turn off.

Scenarios
Lights come on at sunset. If we go to bed before midnight, the lights will turn off at midnight. If we stay up past midnight, the lights will stay on until we go to bed. If we get up before sunrise, the lights will turn on. Lights turn off at sunrise.

The logic, in plain English
There are two distinct time periods to work with here .

1. Sunset to Midnight. The lights should always be on during this period, so no other conditions required here.
2. Midnight to Sunrise. The lights should only be on during this period if mode is Home. This requires both Time Period and Mode conditions to be true.

So the lights should be on if either Condition 1 or Condition 2 from above are true. Condition 2 is really two separate conditions (time and mode), I'll call them 2a and 2b.

This can be rewritten as: Turn the lights on if condition 1 is true, or if condition 2a and 2b are both true. Otherwise turn them off.

Rewritten again, using parentheses to group conditions 2a and 2b:
Turn the lights on if:

Condition 1 is true
OR
(Condition 2a is true
AND
Condition 2b is true)

Otherwise turn them off.

RM Rule

• Select Conditions
-- Time between Sunset and 12:00 AM (this is condition 1 from above)
-- Time between 12:00 AM and Sunrise (this is condition 2a from above)
-- Mode is Home (this is condition 2b from above)
• Define Rule (requires enabling complex rule input)
-- Time between Sunset and 12:00 AM
-- OR
-- (Time between 12:00 AM and Sunrise
-- AND
-- Mode is Home )
• Select Actions for True
-- Back Yard lights on
• Select Actions for False
-- Back Yard lights off

Screenshot

5 Likes

Nice and simple!

A funky upgrade to this is to use @bangali's excellent apixu weather station and test for Illuminance rather than time. This way if you get an overcast day / dark storm / eclipse whatever your lights will automatically come on as well.

3 Likes

I am just learning RM and trying to port over some WC pistons. I have a question....do I have to put in the Actions for False to shut off the lights or will the lights just go off when they are not in the timeframes of the rule?

With Rule Machine, you have to explicitly tell it what you want it to do when the rule is false. There are some other apps that give you the option to "reverse" the True action, but RM is designed to be flexible and customizeable, so you have to be specific.

I have RM Rules where there is no False action. That's because I have another Rule to do that.

I have an "Early" and a "Late" pair of Rules.
Same Conditions and Rules, but the True action for "Early" is to set the light brighter than the "Late" Rule. They go true when motion goes true.

Sunset to 9PM is "early" and then "late" kicks in, 9pm to 1am.

The OFF rule is inverted. The Rule goes true when motion is off/false. The True action is to turn off the light(s) and again, there's no False action AND there's no time restriction. 24hrs a day the OFF Rule is willing to turn off the light.

1 Like

I would like to see those Rules if you could post a picture.

I took a different approach with multiple Modes that change based on offsets from sunrise and sunset. I have scenes setup for each mode and a single rule that changes the lights based on mode.

1 Like

This is what I put together to turn my lights on between 15 minutes to sunset and 11:00pm and also between 4:50am and 20 minutes to sunrise this second condition is only during the weekdays. But for some reason the lights aren't turning off at 11:01pm. What is wrong?

It looks like you changed the conditions after you set up the rule. If you click into the rule definition, you will probably see that the conditions have been blanked out. Any time you change a condition you need to go edit/update the rule too.

Thanks! That is what happened. I think I am starting to get the hang of RM! Need help with my Good Night Routine though. How do I make something happen just once a day?

1 Like

Use "At a certain time"

1 Like

That won't work in my Goodnight Routine though.

What does your Goodnight rule look like, can you post a screen shot?