Notify Slack of devices home/away state when it changes

I’m having some trouble coming up with the config for Slack notification when multiple device is home or away. I’m assuming it is possible to do it with a single automation rather than multiples.

Say I have device_tracker.iphone_1 and device_tracker.iphone_2. If device_tracker.iphone_x changed from not_home to home, or home to not_home, then I get a Slack notification that says ‘<friendly_name_of_device> is <state_of_device>’. Could use some guidance on how to do this in a concise way.

Do you have your slack notifications working yet? I’ll assume you do and that the service is called notify.slack. Then we can solve this with templating:

alias: "Tell me about changes of who is home"
trigger:
  - platform: state
    entity_id:
      - device_tracker.iphone_1
      - device_tracker.iphone_2
    to: 'home'
  - platform: state
    entity_id:
      - device_tracker.iphone_1
      - device_tracker.iphone_2
    to: 'not_home'
action:
  - service: notify.slack
    data_template:
      message: >-
        {{ trigger.to_state.name }} is {{ trigger.to_state.state }}

There are (of course) other ways of solving this, but this one should be fairly obvious I hope.

Thanks. Didn’t realize you can have multiple triggers.