Lookup for entity attributes

Hi,

I’m receiving the IP address of a device as a payload of a MQTT message. I’d like to get the friendly_name of this device on a node-red flow. The device appears as a device_tracker class on HA due to Unifi integration. Any clue on how to do this?

Thank you.

could you post a screenshot of the device_tracker attributes under devs tools? What do you want to do with that friendly name?

I want to present a more friendly message such as “Door opened by XXX” instead of “Door opened by 192.111.111.111”.

I don’t completely understand what’s your target but by doing this you can retrieve the friendly_name.

[{"id":"a37ad0b2.b2789","type":"inject","z":"ea371c1c.7f63c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":1060,"wires":[["6576745f.8545bc"]]},{"id":"6576745f.8545bc","type":"api-current-state","z":"ea371c1c.7f63c","name":"get data","server":"9405c3fe.d0a6c","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"device_tracker.galaxy_a32_5g","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":340,"y":1060,"wires":[["47cc9bc0.646984"]]},{"id":"47cc9bc0.646984","type":"debug","z":"ea371c1c.7f63c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":1060,"wires":[]},{"id":"9405c3fe.d0a6c","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}]

If you open the debug menu, right side in the picture, and hit the timestamp button, you’ll get the complete information of your device tracker. There you’ll find the path of the friendly_name field, which I believe will be data.attributes.friendly_name, and you can use that path to store/move the friendly name wherever you want.

The IP address comes from another device as a MQTT message. I need to use this IP address to retrieve the friendly_name from (probably) a device_tracker and forward this name to another node in order to send a notification.

You should follow the advice above. Set the debug node to complete message object and post the output.

image

[{"id":"417255b46be22d3f","type":"inject","z":"91a80f99.6180e","name":"ip","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"192.168.0.55","payloadType":"str","x":162,"y":720,"wires":[["a39eda9e97a5cd11"]]},{"id":"a39eda9e97a5cd11","type":"ha-get-entities","z":"91a80f99.6180e","name":"","server":"","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"device_tracker","valueType":"str"},{"property":"attributes.ip","logic":"is","value":"payload","valueType":"msg"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":314,"y":720,"wires":[["6d76a5d63418030b"]]},{"id":"6d76a5d63418030b","type":"api-call-service","z":"91a80f99.6180e","name":"","server":"","version":5,"debugenabled":false,"domain":"notify","service":"notify","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\": \"Door opened by \" & payload[0].attributes.friendly_name}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":474,"y":720,"wires":[[]]}]