Set of on / Off times for an automation

I have an two automations (on/off) that I would like to trigger at a set of times.

On 5:30am, Off 9:00am
On 5:00pm, off 9:30pm

I could create 4 Automations but was wondering if there was a more elegant way to have variables for the automation.

Thinking through this I will see if there is a

On at
5:30am
or
5:00pm

and so on

If you want to do this purely in the UI, you can just create an automation with multiple triggers and then take action depending on if the device is already on or off. In this case Iā€™m just toggling a single light, but you can do whatever you want:

description: ""
mode: single
trigger:
  - platform: time
    at: "05:30:00"
  - platform: time
    at: "05:00:00"
  - platform: time
    at: "21:00:00"
  - platform: time
    at: "21:30:00"
condition: []
action:
  - service: light.toggle
    data: {}
    target:
      entity_id: light.armoir

Otherwise you will need to create some code to determine the day and fire your trigger based on the output of that code, if it is true or false. The way above is immediate and you can refine it with code later if you want.

trigger:
  - platform: time
    id: 'on'
    at:
      - "05:30"
      - "17:00"
  - platform: time
    id: 'off'
    at:
      - "09:30"
      - "21:30"
condition: []
action:
  - service: light.turn_{{trigger.id}}
    target:
      entity_id: light.example
3 Likes

Perfect

Thank You

I can add times easily, and reduce the touch points.

I like your solution better than mine darn it!