Convert this code to node-red

Hope someone can help with this…
I’m particularly having trouble with the ‘{{ trigger.to_state.attributes.friendly_name }} triggered’, I’m really bad with templates… struggled in home assistant but I thought I would give Node-red a go and now I’m stuck.

Basically if a sensor has triggered and we are not home I want a notification with which sensor triggered (friendly name)

- alias: 'Actionable notification when devices triggered'
  trigger:
    - platform: state
      entity_id: binary_sensor.study_motion, binary_sensor.wir_motion_sensor, binary_sensor.downstairs_bath_motion_occupancy, binary_sensor.ensuite_motion_occupancy, binary_sensor.kitchen_motion_sensor, binary_sensor.stairs_motion_occupancy
      to: 'on'     
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: armed_away
  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.ha_alarm
    - service: notify.mobile_app_sal_iphone
      data_template:
        message: '{{ trigger.to_state.attributes.friendly_name }} triggered'
      data:
        title: "Door or Motion sensor triggered"
        message: Security Breach
        data:
          push:
            category: "camera"
          entity_id: camera.blueiris_all_cameras

image

[{"id":"83f3a7c6.a44f88","type":"trigger-state","z":"f61766ce.f85398","name":"Sensors","server":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.study_motion, binary_sensor.wir_motion_sensor, binary_sensor.downstairs_bath_motion_occupancy, binary_sensor.ensuite_motion_occupancy, binary_sensor.kitchen_motion_sensor, binary_sensor.stairs_motion_occupancy","entityidfiltertype":"substring","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"},{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"old_state.state"},{"targetType":"entity_id","targetValue":"alarm_control_panel.ha_alarm","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"armed_away","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":124,"y":4768,"wires":[["61f258d2.f53238","5512be37.c0b1c"],[]]},{"id":"61f258d2.f53238","type":"api-call-service","z":"f61766ce.f85398","name":"","server":"","version":1,"debugenabled":false,"service_domain":"alarm_control_panel","service":"alarm_trigger","entityId":"alarm_control_panel.ha_alarm","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":374,"y":4768,"wires":[[]]},{"id":"5512be37.c0b1c","type":"api-call-service","z":"f61766ce.f85398","name":"","server":"","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_sal_iphone","entityId":"alarm_control_panel.ha_alarm","data":"{\t   \"title\": \"Door or Motion sensor triggered\",\t   \"message\": data.new_state.attributes.friendly_name & \" triggered\",\t   \"data\": {\t      \"push\": {\t         \"category\": \"camera\"\t      },\t      \"entity_id\": \"camera.blueiris_all_cameras\"\t   }\t}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":364,"y":4816,"wires":[[]]}]

@Kermit, thankyou so much for this! You have broadened my understanding of Nodered!!

I still don’t get the sensor that was triggered come through?
I had to remove “entityId”:“alarm_control_panel.ha_alarm” from notify call service node because I was getting an API error-

image

Now the flow works but I don’t get the sensor information :frowning: the message has the title and the message is just “triggered”… I’m kind of stuck at the same place.

I’m sure it has something to do with data.new_state.attributes.friendly_name but i’m not clever enough to work it out.

image

image

Set your debug node to “dispaly comlete mesg object” and check out what you see in the debug window. If HA hands over your information than it is in the message object and you have to use the access path in node red to get what you need.

@Kermit @HomeTrainee
Thanks guys between your help and code-in-progress from discord I have found the problem…
seems I need to add event to the template…

data.event.new_state.attributes.friendly_name