Change dimming level based on time of day?

In PLEG I have an action set up to turn on lights in my bedroom based on a motion trigger. The dim level of these lights is dependent on the time of day.

In order to avoid setting up multiple (nearly redundant) conditions and actions, I was able to include logic in the PLEG action which checked to see which Schedule was active - either mid-day (full lights) or late evening (dimmed lights).

PLEG logic for “newloadleveltarget” looks like this “{(s_brightlight ? 100 : 3)}”, where “s_brightlight” was a Schedule that was true from 8am to 8pm. The Condition that kicked off the Action also included the condition that “s_bedroom_light_on” was true from 7am to 10pm. So from 7am to 8am the light would be set to “3”, from 8am to 8pm the lights would be set to “100”, and from 8pm to 10pm the lights would be set to “3”.

Is there a way to do something similar in Reactor so I can avoid setting up multiple sensors with complimentary Day/Time schedules? I’d like just one Reactor Sensor with an Activity that sets the dimming level based on time of day.

-uberpixel

Yes, it is possible, quite easily (if I understand your need correctly). You can set three different OR conditions depending on the time intervall of the day in the same Reactor sensor

OR

  • AND
    – Device state: Triggered equals 1 (your motion sensor)
    – Date/Time: between 7am to 8am
  • AND
    – Device state: Triggered equals 1
    – Date/Time: between 8am to 8pm
  • AND
    – Device state: Triggered equals 1
    – Date/Time: between 8pm tp 10pm

Then set the dimming level for each condition in the Activities tab.

Another approach is to use expressions. You can get the current time, and use that in an if() to select the desired brightness. Then use a variable reference in the device action directly.

hour = tonumber( strftime("%H") )
brightness = if ( hour >= 8 and hour < 20, 100, 3 )

You would still use a Date/Time condition (between 7am and 10pm) to determine if the light should be on at all (and your motion sensor test), and then in the corresponding activity to turn the light on, set the level to {brightness}.

Yes, a much more elegant approach :slight_smile:

Just different, I think. I would never discredit an approach that (a) works and (b) is easily understood by anyone looking at it. Yours satisfies both handily.

2 Likes

Perfect. Thanks for the ideas!

As I look to convert my system from PLEG to Reactor I’m still getting used to the logic structure (obviously) and didn’t think about the fact that you have multiple “Activities” available if you have multiple groups in a given “Condition”. In PLEG it was basically one “Action” for a given “Condition”. This definitely opens things up. I’ve got this version up and running successfully!

Also/alternatively, this would be a great chance to dip my toes into “Expressions”. Thanks for the example.

If you have a second, it would be helpful to see what the syntax for a nested If expression would look like. I was thinking it may be helpful to have 3 or 4 different levels throughout the day based on time (and motion trigger). Say light level 5 from 7am to 8am, light level 100 from 8am to 7pm, light level 50 from 7pm to 9pm, and light level 5 from 9pm to 10pm (and no motion triggered light from 10pm to 7am).

-uberpixel