Can i merge this Automations?

Hey,
i have a beginner question about the automation tools in hass.

My setting ist the following:

  • 2 lightgroups for the yard (1 for uplights, 1 for the main lighting)
  • the main light is controlled by a moving sensor
  • 1 dusk sensor

I wish to do the following: When dusk falls the uplights switch on till 23.30 o`clock. After 23.30 they went off.
β†’ i enabled this with TWO automations. the first switches the uplights on at dusk. the second switches them of at 23.30.

This is my first question β†’ is it possible to do this simple logic in one script/Automation?

The second part is the situation after 23.30. When the Moving Sensor gets active only the main light is switched to on (this is done in the knx logics).

No i want to switch the uplights also on and off when the main lights gets toggled after 23.30.

My idea would be to make a THIRD automation who gets aktiv when it is after 23.30. But i donΒ΄t like this solution because of its very inflexibel. (what is when i change the time to switch of the uplights in de first scripts, etc.)

Hopefully you understand my ideas and problems. i think there must be a much nicer and smoothy solution.

If I understand you correctly, this is no problem at all.
You can just define multiple triggers and let the action happen using Choose.

It’s way easier than explaining it in written text, so just a little simple example:

alias: Example
description: ''
mode: single
trigger:
  - platform: sun
    event: sunset
    offset: '0'
    id: Uplights on at sunset
  - platform: time
    at: '23:30'
    id: 'Uplights off '
  - type: motion
    platform: device
    device_id: 55b5ba---5a13
    entity_id: binary_sensor.motion_sensor_01
    domain: binary_sensor
    id: Motion on
  - type: no_motion
    platform: device
    device_id: 55b5ba---5a13
    entity_id: binary_sensor.motion_sensor_01
    domain: binary_sensor
    id: Motion off
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Uplights on at sunset
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.dimmable_light_1
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: 'Uplights off '
              - condition: trigger
                id: Motion off
          - condition: state
            entity_id: light.dimmable_light_1
            state: 'on'
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.dimmable_light_1
      - conditions:
          - condition: trigger
            id: Motion
          - condition: state
            entity_id: light.dimmable_light_1
            state: 'off'
          - condition: time
            after: '23:30'
          - condition: sun
            before: sunrise
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.dimmable_light_1
    default: []

I used the sunset/sunrise as a trigger and in a condition, but you can use your sensor off course.
Next, I used the same bulb as an example, but you can define your own actions.

You can copy past the code in a new automation to see what it looks like in the visual editor.

Good luck and feel free to ask if you have any questions left. And in general. Post the YAML of your automation if you need support on improving or fixing an automation.

1 Like