Trying to Set Automation Start and End Times Using Zigbee Button

Hello! I plan to have all holiday lighting controlled by smart plugs, but I want my non-technical wife to be able to set on and off times herself. I have a zigbee remote with two buttons that I would like for her to use to set the times by having HA remember when she last pressed them.

I created datetime helpers to hold start and stop times. I have automations for two buttons, one for setting Start Time and one for setting Stop Time. And now that I’m at the actual turning the lights on and off part, I’m stuck.

I cannot seem to externally modify an automation’s scheduled start time, so I figure I’d make an automation to act as a daemon on a 5-min interval that compares the current time to stored start and stop times, but I can’t find a robust way to do this (the available GUI datetime triggers require an exact match, and I need a chance to strip the date portion before comparing).

Is this simpler to do in YAML? Am I taking the wrong approach?

Thanks,
Larry

Not quite sure what you mean here.

If you want to turn the lights on at a certain time then you just use a time trigger that uses your datetime helpers as the trigger time:

triggers:
  - trigger: time
    at: input_datetime.start
actions:
  - action: light.turn_on
    entity_id: light.holiday_lights

but you need a datetime helper that only stores the time and not the date.

For me, yes. I never use the UI to make automations

No… the state machine and event loop already cover all that. There are very few cases an interval/continuous polling/time pattern trigger is actually the answer in HA automations.

Please follow the Community Question Guidelines by posting your automation’s YAML configuration… it makes it a lot easier for us to see any possible issues.

Have a look at the following docs:

Make two helpers: one for each time, and make them store times only, not dates.

Make an automation for each button to set them.

Make an automation for each helper using a time trigger to turn your lights on and off.

1 Like

I would use the buttons differently:

  • The first button is just a simple toggle (if lights off turn on, if lights on turn off).
  • The second button I would use as a “memory” button:
    • If you press the button and the lights are on change the auto on time.
    • If you press the button and the lights are off change the auto off time.

Implementation

  • Put all plugs/lights in a group so that you can turn them all on/off together.
  • Create a simple automation for the first button that simply toggles the lights on/off.
  • Create two input_datetime helpers - for the on and off times respectively (both set to time mode).
  • Create an automation to update the On and Off times based on if the lights are on or off when the second button is pressed.
  • Create an automation to turn the lights on when the on time occurs.
  • Create an automation to turn the lights off when the off time occurs.

I think that should handle most of the cases.

But there is one problem case, which is if someone turns the lights on after the preset off time - likely you will end up with the lights on for rest of the night, the simplest solution is just to add an automation that turns off the lights at say 2:00 AM so that the lights are turned off by next morning.

Clarifying question: When the button for setting the on time is pressed, do you then also want the lights turned on, and ditto for off?