Customize email and app alert being sent out to be more specific

As you see in the attached flow, I have 4 water sensors that will turn off my water valve. I also have them sending an alert to my HA app on my phone as well as sending me an email.

Is there anyway to specify in the alert to my phone and email, which sensor detected water; without making a separate node for each sensor?

Attached is my flow. I get most of my flow by just importing others and then working off that framework. If you could edit mine or show me an example I can look off of, I’d appreciate it.

[{"id":"13a84f71.bdbac1","type":"server-state-changed","z":"5ce4431.0d95bbc","name":"Water leak detected at water heater","server":"456659de.370498","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.water_leak_sensor_water_heater","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":200,"y":100,"wires":[["7bdcf8b8.16a328","9a80962f.a5dce8"],[]]},{"id":"9a80962f.a5dce8","type":"api-call-service","z":"5ce4431.0d95bbc","name":"Turn off water valve","server":"456659de.370498","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.water_valve_shutoff","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":100,"wires":[[]]},{"id":"968a10b0.80d91","type":"server-state-changed","z":"5ce4431.0d95bbc","name":"Water leak detected at kitchen sink","server":"456659de.370498","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.water_leak_sensor_under_kitchen_sink","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":190,"y":160,"wires":[["7bdcf8b8.16a328","9a80962f.a5dce8"],[]]},{"id":"2f657e2e.2f6dd2","type":"server-state-changed","z":"5ce4431.0d95bbc","name":"Water leak detected at bidet","server":"456659de.370498","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.water_leak_sensor_bidet","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":170,"y":220,"wires":[["7bdcf8b8.16a328","9a80962f.a5dce8"],[]]},{"id":"a806aa50.9f1888","type":"server-state-changed","z":"5ce4431.0d95bbc","name":"Water leak detected at laundry room","server":"456659de.370498","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.water_leak_sensor_laundry_room","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":200,"y":280,"wires":[["7bdcf8b8.16a328","9a80962f.a5dce8"],[]]},{"id":"7bdcf8b8.16a328","type":"api-call-service","z":"5ce4431.0d95bbc","name":"Send alert to phones","server":"456659de.370498","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_pixel_3","entityId":"","data":"{\"title\":\"\",\"message\":\"WATER LEAK DETECTED AT XXX\",\"data\":{\"sticky\":\"true\",\"priority\":\"Normal\",\"ttl\":0,\"tag\":\"tagname\",\"color\":\"red\"}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":530,"y":180,"wires":[["e0fd83d2.af4aa"]]},{"id":"e0fd83d2.af4aa","type":"function","z":"5ce4431.0d95bbc","name":"","func":"msg = {\n    payload :\"A water leak has been detected at XXX \" + Date ().toString(),\n    topic : \"WATER LEAK DETECTED!!!!!\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":180,"wires":[["f55f762d.e17e18"]]},{"id":"f55f762d.e17e18","type":"e-mail","z":"5ce4431.0d95bbc","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"[email protected]","dname":"","x":920,"y":180,"wires":[]},{"id":"456659de.370498","type":"server","name":"Home Assistant","addon":true}]

First example, you can use a single event state node having entity id type of substring and comma delimited list of entity ids.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/get-entities.html#example-1

@Kermit

Im trying to follow Example1 on this page but Im not follwoing. Would I place my 4 water sensor ‘BINARY.SENSOR’ in his LEFT HOME node or ENTITIES node?

image

[{"id":"59dd279b.66fe48","type":"server-state-changed","z":"ffbd7f06.4a014","name":"Water leak detected","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor\\.water_leak.+","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":154,"y":2272,"wires":[["dd975109.914ab","878d58e.d947fa8"],[]]},{"id":"dd975109.914ab","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn off water valve","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.water_valve_shutoff","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":378,"y":2320,"wires":[[]]},{"id":"42699c04.fe8f84","type":"api-call-service","z":"ffbd7f06.4a014","name":"Send alert to phones","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_pixel_3","entityId":"","data":"{\"title\":\"\",\"message\":\"{{payload}}\",\"data\":{\"sticky\":\"true\",\"priority\":\"Normal\",\"ttl\":0,\"tag\":\"tagname\",\"color\":\"red\"}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":596,"y":2272,"wires":[[]]},{"id":"a562eebd.a1b38","type":"e-mail","z":"ffbd7f06.4a014","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"[email protected]","dname":"","x":596,"y":2320,"wires":[]},{"id":"878d58e.d947fa8","type":"function","z":"ffbd7f06.4a014","name":"","func":"msg.payload = `A water leak has been detected at ${msg.data.attributes.friendly_name} ${Date()}`;\nmsg.topic = \"WATER LEAK DETECTED!!!!!\"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":348,"y":2272,"wires":[["42699c04.fe8f84","a562eebd.a1b38"]]}]

edit: I changed it up a little as you’ll probably not having more than one sensor going off a time.

@Kermit

I got an error when tripping a sensor

image

it’s probably suppose to be msg.data.new_state.attributes.friendly_name

That did the trick! thanks. So In the state node you have entity ID set has binary_sensor.water_leak.+ and regex selected.

Is this like a wildcard? So if I add any future sensors, I need keep naming function as water_leak_xxxxxx ?

yes, that’s correct.

@Kermit thanks again. For some reason I cant set your reply as the solution though.