How to Minimize the number of tome dependent Automations

I am trying to create a single automation to control my bedside light, currently this is done by means of four different automations, this clutters front end very quickly, I have:

#bedside switch automation
  - alias: 'bedside_on'
    initial_state: True
    trigger:
     platform: sun
     event: sunset
     offset: '+00:00:00'
    action:
     - service: switch.turn_on
       entity_id: switch.Bedside_Lamp
  - alias: 'bedside_off'
    initial_state: True
    trigger:
     platform: time
     at: '23:30:00'
    action:
     - service: switch.turn_off
       entity_id: switch.Bedside_Lamp
  - alias: 'bedside_on2'
    initial_state: True
    trigger:
     platform: time
     at: '05:30:00'
    condition:
     - condition: time
       weekday:
        - mon
        - tue     
        - wed
        - thu
        - fri
    action:
     - service: switch.turn_on
       entity_id: switch.Bedside_Lamp
  - alias: 'bedside_off2'
    initial_state: True
    trigger:
     platform: sun
     event: sunrise
     offset: '+00:00:00'
    action:
     - service: switch.turn_off
       entity_id: switch.Bedside_Lamp

this switches the light on at sunset, off at 23:30, on at 5:30 (only weekdays) and off at sunrise, I would like to combine all these into one automation, but I don’t think homeassistant follows this convention:

trigger
......
action
......
trigger
.......
action
......

how do I create independent triggers and independent actions under one automation?

you will agree that this looks tardy:

image

Add another view to your Overview, and put the automations in there.

IMO you should be looking to the likes of HA Dashboard or HA Floorplan for a UI, and even then if you’re routinely using the UI then you’re doing automation wrong :wink:

I’ve got some 180 automations currently. In the default UI those are spread across 6 views, but other than when I’m debugging I don’t use them.

Thanks, is there a way of optimizing the four automations into one since they all control my bedside lamp using mostly time as a trigger for on and off.

FYI - watch your indenting. It needs to be two spaces per level, not a random mix of one or two.

You should certainly be able to easily merge both on and off automations. The off automations are easy:

  - alias: 'bedside_off'
    initial_state: True
    trigger:
      - platform: time
        at: '23:30:00'
      - platform: sun
        event: sunrise
    action:
      - service: switch.turn_off
        entity_id: switch.Bedside_Lamp

The on is slightly more complicated, because you want it to turn on only during weekday mornings (you could possibly use the workday sensor instead. I’m using an offset on sunset for the condition here because I’m unsure if at the point the sunset trigger fires the condition sees it as after sunset.

  - alias: 'bedside_on'
    initial_state: True
    trigger:
      - platform: sun
        event: sunset
      - platform: time
        at: '05:30:00'
    condition:
      - condition: or
        conditions:
          - condition: sun
            after: sunset
            after_offset: "-00:10:00"
          - condition: time
            weekday:
              - mon
              - tue     
              - wed
              - thu
              - fri
    action:
      - service: switch.turn_on
        entity_id: switch.Bedside_Lamp

Thanks, I will give it a try, I will also endeavor to indent better, I am also busy with groups and default views to organize my UI better.

I think it’s a matter of taste, but I surely prefer a hundred simple automation than a quarter of complicated ones :-). If you think they clutter the UI you can easily hide then using “hide_entity: True”. Most of my automations are hidden.

2 Likes