Multiple devices - dynamic notification

Hello,
I’m trying to push my understanding of Home Assistant automations and I have a situation I would like to try and achieve, but not sure if/how it’s possible. Below is a current automation I have setup that is working for my Blink camera.

- id: '10000000300'
  alias: Motion Test
  initial_state: true
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.blink_back_yard_motion_detected
    to: 'on'
  condition: []
  action:
    service: notify.ios_phone_x
    data: 
      title: 'Motion Detected'
      message: 'Camera has detected motion'

I would like to modify this so that it will work with all my Blink cameras and, even better, dynamically alert me to which camera detected motion.

So, for example (and I know the code below is NOT correct, but I’m using it to illustrate what I’m trying to do)

- id: '10000000300'
  alias: Motion Test
  initial_state: true
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.blink_cameras
    to: 'on'
  condition: []
  action:
    service: notify.ios_phone_x
    data: 
      title: 'Motion Detected'
      message: 'Camera {binary_sensor. entity_id} has detected motion'

Is it possible to dynamically change to message of this notification to include the specific sensor that captured the motion from a group of sensors?

Try this:

 id: '10000000300'
  alias: Motion Test
  initial_state: true
  hide_entity: true
  trigger:
    platform: state
    entity_id: 
      - binary_sensor.blink_back_yard_motion_detected
      - binary_sensor.blink_2
      - binary_sensor.blink_3
    to: 'on'
  condition: []
  action:
    service: notify.ios_phone_x
    data_template: 
      title: 'Motion Detected'
      message: 'Camera {{trigger.to_state.object_id}} has detected motion'

If any one of the three binary_sensors changes its state to on, it will trigger the automation. The action uses one of the trigger object’s properties to get the name (object_id) of the entity that triggered the automation.


EDIT
Changed data to data_template as per tom_I’s correction.

1 Like

Also be sure to use data_template: instead of data:

  action:
    service: notify.ios_phone_x
    data_template: 
etc...
1 Like