Combine multiple conditions with an action for each within one automation

Hello,

I’m looking into combining some of my automations, since there is some overhead in some of them.

I currently have the following configuration in my ‘automation.yaml’ file:

- alias: "Coming Home Notification"
  trigger:
    platform: state
    entity_id: device_tracker.myPhone
    to: 'home'
  action:  
  - condition: time
    before: '22:00:00'
    after: '08:00:00'
  - service: notify.NotifyTelegram
    data:
      message: "Welcome home"

- alias: "Goodmorning Notification"
  trigger:
    platform: state
    entity_id: device_tracker.myPhone
    to: 'home'
  action:  
  - condition: time
    before: '08:00:00'
    after: '04:00:00'
  - service: notify.NotifyTelegram
    data:
      message: "Goodmorning!"

This sends me a message (via Telegram) when I come home, and if the time is between 4am and 8am I get a “Goodmorning”. However the automations are more or less the same, except for the condition (and the text).

Is it possible to combine both automations into one? To have one trigger with multiple conditions and with an action for a specified condition?

I am fairly new to Home Assistant, so I am not sure if what I want is possible. Nonetheless, any help is welcome!

Thanks!!

1 Like

To point you in the right direction, notify messages support templating. So the message would look more like:

'{% if night %}Welcome home{% else %}Good morning!{% endif %}'

That “if night” isn’t actually going to work. I don’t have an example handy in my config to post for you. I bet you can find some ideas from the “creating an alarm clock” project:

1 Like

Thanks! I’ll sure look into that!