Node name or friendly name for notification with Node Red

Hello.
These are my first steps with Node Red and Home Assistant. I have some battery-powered devices where I would like to send a notification when the battery runs low.

This has been my idea so far:

[{"id":"0ef04dc37c3d2c33","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"be534ff6981c7c7c","type":"api-call-service","z":"0ef04dc37c3d2c33","name":"Benachrichtigung R. Handy","server":"ea544f4f.d7486","version":4,"debugenabled":false,"domain":"notify","service":"mobile_app_rmx1993_roman","target":{"entityId":[],"areaId":[],"deviceId":[]},"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":840,"y":60,"wires":[[]]},{"id":"948391439ac32016","type":"server-state-changed","z":"0ef04dc37c3d2c33","name":"Wohnzimmer Fensterkontakt","server":"ea544f4f.d7486","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.wohnzimmer_fensterkontakt_hinten_battery","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":40,"wires":[["dc4008089b6c239e"]]},{"id":"dc4008089b6c239e","type":"switch","z":"0ef04dc37c3d2c33","name":"Status bat_low","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"bat_low","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":420,"y":60,"wires":[["e44370e6cd475414"]]},{"id":"e44370e6cd475414","type":"function","z":"0ef04dc37c3d2c33","name":"Msg","func":"msg.payload = {\"data\":{\"message\":\"Batterie von\" + \" ist schwach! \",\"title\":\"Wichtige Nachricht von HomeAssistant!\",\"data\":{\"group\":\"Batterie\"}}};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":60,"wires":[["be534ff6981c7c7c"]]},{"id":"4a41b1aaac511640","type":"server-state-changed","z":"0ef04dc37c3d2c33","name":"Küche Fensterkontakt","server":"ea544f4f.d7486","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.kueche_fensterkontakt_battery","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":100,"wires":[["dc4008089b6c239e"]]},{"id":"ea544f4f.d7486","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":""}]

I hope this works the way I want it to. How do I get the name of the node or the friendly name in the function node? So that the name of the device is instead of the +.

function node:

msg.payload = {"data":{"message": "Batterie von" "+" " ist schwach! ","title":"Wichtige Nachricht von HomeAssistant!","data":{"group":"Batterie"}}};
return msg;

Or does someone have a better idea to implement my project? I would be very grateful for help.

Thank you.

Usually message topic is the entity.
Connect a debug to one of your blue nodes on the left and set it to complete message.

Thanks.
This is the debug log:

object

payload: “off”

data: object

entity_id: “binary_sensor.wohnzimmer_fensterkontakt_hinten”

old_state: object

entity_id: “binary_sensor.wohnzimmer_fensterkontakt_hinten”

state: “on”

attributes: object

model_type: “HMIP-SWDO”

connection_type: “HMIP_RF”

rssi_device: -64

id: “3014F711A00000DA499F3AC8”

is_group: false

device_class: “window”

friendly_name: “Wohnzimmer Fensterkontakt hinten”

last_changed: “2022-02-15T19:46:01.766103+00:00”

last_updated: “2022-02-15T19:46:01.766103+00:00”

context: object

id: “babc5e8188f7c4151ccb0a712f412ac7”

parent_id: null

user_id: null

original_state: “on”

new_state: object

entity_id: “binary_sensor.wohnzimmer_fensterkontakt_hinten”

state: “off”

attributes: object

model_type: “HMIP-SWDO”

connection_type: “HMIP_RF”

rssi_device: -54

id: “3014F711A00000DA499F3AC8”

is_group: false

device_class: “window”

friendly_name: “Wohnzimmer Fensterkontakt hinten”

last_changed: “2022-02-15T19:47:05.822879+00:00”

last_updated: “2022-02-15T19:47:05.822879+00:00”

context: object

id: “15bfc92618a4c0de147ca4f53420211e”

parent_id: null

user_id: null

original_state: “off”

timeSinceChangedMs: 3

topic: “binary_sensor.wohnzimmer_fensterkontakt_hinten”

_msgid: “8cd3ad46e14586c1”

So I can see:
attributes: object
friendly_name: “Wohnzimmer Fensterkontakt hinten”

That would be exactly what I would like to use. How can I insert this into the message?

A word of advice is to post all parts of the questions in English.
Now I can just make a guess.
And since the debug log is not a code block it’s hard to read what the hierarchy is, but topic would be:

msg.payload = {"data":{"message": "Batterie von" + msg.topic + " ist schwach! ","title":"Wichtige Nachricht von HomeAssistant!","data":{"group":"Batterie"}}};
return msg;

Hello.
Yes, you are right. Had I unfortunately not thought to adjust the German words in the message in English. Sorry.

I had already tried msg.topic. There the entity id is inserted.

It must be the setting in the node:

Can I set there, that friendly_name should be used?

Use $entity().attributes.friendly_name and set the drop down type to J;expression

3 Likes

Here is my battery notification set up - it will check at 11AM each day for any device under 10%. then send a notification with the friendly name and battery percent

[{"id":"eefe691a3a36e375","type":"template","z":"08f20723f19319cc","name":"Battery msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}} is low at {{payload.state}}%","output":"str","x":1130,"y":280,"wires":[["cf48c0bb97ac41e8"]]},{"id":"7df517c1c91e9a13","type":"ha-get-entities","z":"08f20723f19319cc","name":"","server":"0221b4f4da934702","version":0,"rules":[{"property":"state","logic":"lte","value":"10","valueType":"num"},{"property":"attributes.device_class","logic":"is","value":"battery","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":930,"y":280,"wires":[["eefe691a3a36e375"]]},{"id":"391fa8c74332a763","type":"inject","z":"08f20723f19319cc","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"00 11 * * *","once":false,"onceDelay":"60","topic":"","payload":"","payloadType":"date","x":730,"y":280,"wires":[["7df517c1c91e9a13"]]},{"id":"cf48c0bb97ac41e8","type":"api-call-service","z":"08f20723f19319cc","name":"Notify JohnDoe","server":"c43f98a6.706d78","version":4,"debugenabled":false,"domain":"notify","service":"notify","target":{"entityId":[],"areaId":[],"deviceId":[]},"data":"{ \"message\": \"{{payload}}\", \"title\":\"Battery Level Notification\" }","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1340,"y":280,"wires":[[]]},{"id":"fc2823a66a1b5821","type":"comment","z":"08f20723f19319cc","name":"Battery Notification ","info":"","x":730,"y":240,"wires":[]},{"id":"0221b4f4da934702","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30},{"id":"c43f98a6.706d78","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]
1 Like

@Mikefila
Thanks that works. That helps me a lot.

@kagetaro99
Thanks for your template. It helps me a lot to understand some things better.
My Homematic IP devices do not have a % indication for the battery status, but only bat_low or not_bat_low.
But I can use it in a modified form to get notified.