How to combine two automations in one?

I have two automations that are triggered almost with the same triggers and i would like to know if it is possible to combine the two in only one.

The first automation is:

- alias: Nessuno a Casa Spegni Luci
  trigger:
    - platform: state
      entity_id: group.presenze
      from: 'home'
      to: 'not_home'
  condition:
    - condition: state
      entity_id: group.presenze
      state: 'not_home'
  action:
    - service: homeassistant.turn_off
      entity_id: group.all_lights
    - service: notify.telegram
      data:
        message: Nessuno a casa

and the second is:

- alias: Nessuno a Casa Spegni Sky
  trigger:
    - platform: state
      entity_id: group.presenze
      from: 'home'
      to: 'not_home'
  condition:
    - condition: state
      entity_id: group.presenze
      state: 'not_home'
    - condition: state
      entity_id: switch.sky
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.satellite_off
    - delay: 00:00:10
    - service: notify.telegram
      data:
        message: Nessuno a casa. Spengo satellite.

Who can help me ?

I would try something like this:

- alias: Nessuno a Casa Spegni Sky
  trigger:
    - platform: state
      entity_id: group.presenze
      from: 'home'
      to: 'not_home'
#
  condition:
    - condition: state
      entity_id: group.presenze
      state: 'not_home'
#
  action:
    - service: homeassistant.turn_off
      entity_id: group.all_lights
    - service: notify.telegram
      data:
        message: Nessuno a casa
    - condition: state
      entity_id: switch.sky
      state: 'on'
    - service: script.turn_on
      entity_id: script.satellite_off
    - delay: 00:00:10
    - service: notify.telegram
      data:
        message: Nessuno a casa. Spengo satellite.

I’m not sure, though, what the condition I marked with the two # is supposed to do.

I would do exactly the same, including removing the condition block as it’s pointless.

On the other hand, if it ain’t broke, don’t fix it!

1 Like