Node-RED notify problem

hi all, i’m starting using node-red for my automation and i want to translate my alarm automation to node-red.
my alarrm automation notification is this:

- service: notify.GioZzz
    data:
      message: 'ALARM TRIGGERED!!! {{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'

With this message i rreceive the sensor that it was triggered. is it possible to incluse that code in node red?
thanks

I was just about to post a very similar enquiry. Well, exactly the same to be honest.
Any way of getting the sensor that was triggered into the notification with NodeRed please?
Thanks

This is my current flow:

You can add it to your alarm state switch as the payload. I am on my phone so can’t give an example but will upload shortly if your still stuck.

Thanks @jimpower

I’m still extremely new to nodered (less than 48 hours), so when you get a chance to show us that example, I’d thoroughly appreciate it. :slight_smile:

So I haven’t confirmed if this works yet, but I decided to try a yaml to json converter and ended up with this:

data:
message: ALARM TRIGGERED! {{states[states.alarm_control_panel.house.attributes.changed_by.split(“.”)[0]][states.alarm_control_panel.house.attributes.changed_by.split(“.”)[1]].name}}
title: Alarm

to:

{
“data”: {
“message”: “ALARM TRIGGERED! {{states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name}}”,
“title”: “Alarm”
}
}

I would add a debug at the output of your Alarm Control Panel … do the full msg view…that should help you to find out the structure to be used in your “Alarm State”

I did similar with my Kodi device and able to separate even complicated command structures… if you know the structure it is easy to use the payload … in my case it was MSG.PAYLOAD.Notification

image
image

So I got it working!!!

I used a function node and inserted the converted yaml to json text there. I then used {} in the data section of the notification service.

Here is the flow:

And here is the sequence exported:

[{"id":"ea72862f.6d8598","type":"server-state-changed","z":"5019f4af.6dab3c","name":"Alarm Control Panel","server":"9582d396.920b1","entityidfilter":"alarm_control_panel.house","entityidfiltertype":"substring","haltifstate":"","x":150,"y":215,"wires":[["c0cf4cef.8717"]]},{"id":"19eb658d.96f49a","type":"switch","z":"5019f4af.6dab3c","name":"Alarm State","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"armed_away","vt":"str"},{"t":"eq","v":"armed_home","vt":"str"},{"t":"eq","v":"disarmed","vt":"str"},{"t":"eq","v":"triggered","vt":"str"},{"t":"eq","v":"warning","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":580,"y":215,"wires":[["8399dd88.2c1b3"],["a5f9ed5c.20aa6"],["6259519e.1d852"],["bea1af4b.fe4d5"],["b0bc6f69.d6eab"]]},{"id":"8399dd88.2c1b3","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Armed Away","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Armed Away\"}","mergecontext":"","x":1170,"y":150,"wires":[[]]},{"id":"a5f9ed5c.20aa6","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Armed Home","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Armed Home\"}","mergecontext":"","x":1170,"y":190,"wires":[[]]},{"id":"6259519e.1d852","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Disarmed","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Disarmed\"}","mergecontext":"","x":1160,"y":230,"wires":[[]]},{"id":"6c39e09b.37416","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Triggered","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{}","mergecontext":"","x":1160,"y":270,"wires":[[]]},{"id":"86ca6274.c08c4","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Warning","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Warning\"}","mergecontext":"","x":1160,"y":310,"wires":[[]]},{"id":"2603d0fb.d7964","type":"comment","z":"5019f4af.6dab3c","name":"Notifications","info":"","x":130,"y":140,"wires":[]},{"id":"c0cf4cef.8717","type":"traffic","z":"5019f4af.6dab3c","name":" ","property_allow":"payload","filter_allow":"on","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"off","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":false,"x":350,"y":215,"wires":[["19eb658d.96f49a"]]},{"id":"20c43e2d.517242","type":"server-state-changed","z":"5019f4af.6dab3c","name":"On/Off","server":"9582d396.920b1","entityidfilter":"input_boolean.kettle_auto","entityidfiltertype":"substring","haltifstate":"","x":110,"y":285,"wires":[["c0cf4cef.8717"]]},{"id":"bea1af4b.fe4d5","type":"function","z":"5019f4af.6dab3c","name":"Message","func":"msg.payload =\n{\n  \"data\": {\n    \"message\": \"Triggered! {{states[states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[0]][states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[1]].name}}\",\n    \"title\": \"ALARM\"\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":270,"wires":[["6c39e09b.37416"]]},{"id":"b0bc6f69.d6eab","type":"function","z":"5019f4af.6dab3c","name":"Message","func":"msg.payload =\n{\n  \"data\": {\n    \"message\": \"Warning! {{states[states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[0]][states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[1]].name}}\",\n    \"title\": \"ALARM\"\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":310,"wires":[["86ca6274.c08c4"]]},{"id":"9582d396.920b1"]

The exported sequence throws an error when I try to import it

What’s the error?

It looks like there’s a little bit too much included and it’s an invalid json object.

Try this:

[{"id":"ea72862f.6d8598","type":"server-state-changed","z":"5019f4af.6dab3c","name":"Alarm Control Panel","server":"9582d396.920b1","entityidfilter":"alarm_control_panel.house","entityidfiltertype":"substring","haltifstate":"","x":150,"y":215,"wires":[["c0cf4cef.8717"]]},{"id":"19eb658d.96f49a","type":"switch","z":"5019f4af.6dab3c","name":"Alarm State","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"armed_away","vt":"str"},{"t":"eq","v":"armed_home","vt":"str"},{"t":"eq","v":"disarmed","vt":"str"},{"t":"eq","v":"triggered","vt":"str"},{"t":"eq","v":"warning","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":580,"y":215,"wires":[["8399dd88.2c1b3"],["a5f9ed5c.20aa6"],["6259519e.1d852"],["bea1af4b.fe4d5"],["b0bc6f69.d6eab"]]},{"id":"8399dd88.2c1b3","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Armed Away","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Armed Away\"}","mergecontext":"","x":1170,"y":150,"wires":[[]]},{"id":"a5f9ed5c.20aa6","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Armed Home","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Armed Home\"}","mergecontext":"","x":1170,"y":190,"wires":[[]]},{"id":"6259519e.1d852","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Disarmed","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Disarmed\"}","mergecontext":"","x":1160,"y":230,"wires":[[]]},{"id":"6c39e09b.37416","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Triggered","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{}","mergecontext":"","x":1160,"y":270,"wires":[[]]},{"id":"86ca6274.c08c4","type":"api-call-service","z":"5019f4af.6dab3c","name":"Notify Warning","server":"9582d396.920b1","service_domain":"notify","service":"ios_josephs_iphone","data":"{\"title\": \"ALARM\", \"message\": \"Warning\"}","mergecontext":"","x":1160,"y":310,"wires":[[]]},{"id":"2603d0fb.d7964","type":"comment","z":"5019f4af.6dab3c","name":"Notifications","info":"","x":130,"y":140,"wires":[]},{"id":"c0cf4cef.8717","type":"traffic","z":"5019f4af.6dab3c","name":" ","property_allow":"payload","filter_allow":"on","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"off","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":false,"x":350,"y":215,"wires":[["19eb658d.96f49a"]]},{"id":"20c43e2d.517242","type":"server-state-changed","z":"5019f4af.6dab3c","name":"On/Off","server":"9582d396.920b1","entityidfilter":"input_boolean.kettle_auto","entityidfiltertype":"substring","haltifstate":"","x":110,"y":285,"wires":[["c0cf4cef.8717"]]},{"id":"bea1af4b.fe4d5","type":"function","z":"5019f4af.6dab3c","name":"Message","func":"msg.payload =\n{\n  \"data\": {\n    \"message\": \"Triggered! {{states[states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[0]][states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[1]].name}}\",\n    \"title\": \"ALARM\"\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":270,"wires":[["6c39e09b.37416"]]},{"id":"b0bc6f69.d6eab","type":"function","z":"5019f4af.6dab3c","name":"Message","func":"msg.payload =\n{\n  \"data\": {\n    \"message\": \"Warning! {{states[states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[0]][states.alarm_control_panel.house.attributes.changed_by.split(\\\".\\\")[1]].name}}\",\n    \"title\": \"ALARM\"\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":310,"wires":[["86ca6274.c08c4"]]}]