Combining Automations - light

Hi everybody

I am a novice when it comes to templates and could use a little help combining 4 automations into 1.
I have 4 automations adjusting the light in my kitchen based on the time of day. They all work great but in order to combine these 4 very similar automations into one, my best guess was to use a script containing a template.

The automations look like this and all that changes is the brightness and time of day.
Anybody up for helping a fellow HA-newb?

alias: Alrum lysstyrke - aften
description: Justerer lysstyrke i forhold til tid på dagen
trigger:
  - platform: device
    type: turned_on
    device_id: 3efbbbcd12f3d01df6e39eb400d3ec7d
    entity_id: light.kokkeno
    domain: light
    id: '1'
  - platform: device
    type: turned_on
    device_id: aa1ca1178c89941ec0244e13b19bd41c
    entity_id: light.spisebord
    domain: light
    id: '2'
condition:
  - condition: time
    after: '19:01:00'
    before: '05:59:00'
action:
  - choose:
      - conditions:
          - condition: trigger
            id: '1'
        sequence:
          - service: light.turn_on
            entity_id: light.kokkeno
            data:
              brightness_pct: 30
              entity_id: light.kokkeno
      - conditions:
          - condition: trigger
            id: '2'
        sequence:
          - service: light.turn_on
            entity_id: light.spisebord
            data:
              brightness_pct: 20
              entity_id: light.spisebord
mode: single

I would go for a Blueprint. By myself I tried to reduce the number of automations by increasing complexity, but it was dead end. No I use more, smaller automations with blueprints where possible. Much easier to maintain and to analyze.

1 Like

You can use a choose within a choose so make the first level choose as the time range condition.

Choose 1, condition time range 1

  • Choose 1, trigger 1
  • Choose 2, trigger 2

Choose 2, condition time range 2

  • Choose 1, trigger 1
  • Choose 2, trigger 2

And so on