Examples for using the new Get Entities node

This was perfect, and exactly what I was looking for. Thanks heaps!!

isn’t friendly name one of entity attributes? If so having access to entity object you should be able to use obj.attributes.friendly_name

Possibly it’s passed with a message too.

That is exactly what I use to check my battery devices. I use the device class property to get all the devices and friendly name property to exclude the specific devices I am not interested in (phones, tablets and Roomba). Works great.

@Kermit how to get this working?
image

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

$entity().attributes.current_temperature
1 Like

Am I missing something with the get entities and getting the contents of a group?

Nevermind, looks like I choose the wrong time to play with the code as there was a bug which was just resolved with the latest companion update.

Hi there!
Im ok with the Get entities node, its working well, but now i want to do this:
Get “water_leak” entities that are “wet” and then send me a notification like this: "Attention theres a leak on “device x”.
I need help in the notification “expression” data part, to tell me exactly whats the device that detected water.
Can someone help?
Thank you!

example 1 shows you how to combine the friendly names

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

3 Likes

Hi,
I want to use the “get entities” node to identify the entity that was last changed in a given (binary sensor) group. Is that possible?

Hi

const globalHomeAssistant = global.get('homeassistant');

const ha = globalHomeAssistant.homeAssistant;

const groupEntity = ha.states['group.person_home_away'];

Hey,
I’m trying to do the following (someone shared the code here in the forum) I’m trying to make an adjustment to my system,

I’m trying to make Boolean receive an update who is at home,

Of course I have the group set, and also the Boolean of each person.

can you help

image

1 Like

How do I get the same result as the template below in a function on node red?

{{states
| selectattr('entity_id', 'search', 'quarto') 
| map(attribute='entity_id') 
| reject('search', 'wifi') 
| reject('search', 'ssid') 
| list }}

1 Like

regex: ^(?!.*wifi|.*ssid).*quarto.*

2 Likes

This! found this looking for a way to turn off all lights that are on. And of course, at the center of any higher level Node Red question, there is Kermit, spitting out answers like Ninja stars HAHA :wink:

Though I guess something has changed? Im getting this error with the “turn off light” node

“HomeAssistantError: not a valid value for dictionary value @ data[‘entity_id’]” I was using the one that has {{payload.entity_id}}

EDIT

This worked

{"entity_id": $join(payload.entity_id, ",")}

Kermit the Node Red Ninja :black_heart: :rofl:

For anyone looking to get all lights that are on and turn them, off, this the one that works;

[{"id":"cd6fc2911452f914","type":"api-call-service","z":"4f47f2fd.a611fc","name":"Turn off Light","server":"d272ac3c.e0735","version":5,"debugenabled":true,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":[],"data":"{\"entity_id\": $join(payload.entity_id, \",\")}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":630,"y":2740,"wires":[["571ea2756d3975fc"]]},{"id":"571ea2756d3975fc","type":"debug","z":"4f47f2fd.a611fc","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":2580,"wires":[]},{"id":"25835b72.64f7a4","type":"ha-get-entities","z":"4f47f2fd.a611fc","name":"","server":"d272ac3c.e0735","version":1,"rules":[{"property":"entity_id","logic":"starts_with","value":"light.","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"outputType":"array","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":374,"y":2580,"wires":[["cd6fc2911452f914"]]},{"id":"295c21dc.5cb70e","type":"inject","z":"4f47f2fd.a611fc","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":2580,"wires":[["25835b72.64f7a4"]]},{"id":"d272ac3c.e0735","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Maybe I’ve mis-understood example #1 but I’m having issues with the output to including what’s in msg.payload.

Here is my service node {"message":"The {{payload}} are open.","title": "Left Open"}

But I get the following "The {{payload}} are open."

[{"id":"6d0d44d40889d014","type":"inject","z":"0c7ea54a78e4f73f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":75,"y":160,"wires":[["e8a5dc398d617a2b"]],"l":false},{"id":"e8a5dc398d617a2b","type":"ha-get-entities","z":"0c7ea54a78e4f73f","name":"","server":"b77dc5f84903af5d","version":1,"rules":[{"property":"entity_id","logic":"is","value":".*contact*","valueType":"re"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"outputType":"split","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":210,"y":160,"wires":[["c738626a3cc39a41","e19f4740b6d68a6e"]]},{"id":"c738626a3cc39a41","type":"template","z":"0c7ea54a78e4f73f","name":"Format Friendly Name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":440,"y":160,"wires":[["298a83564e352ff5","0b11022889bf1d95"]]},{"id":"298a83564e352ff5","type":"join","z":"0c7ea54a78e4f73f","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":630,"y":160,"wires":[["a7db00a05178e65b","10a3e4235e76303f"]]},{"id":"10a3e4235e76303f","type":"api-call-service","z":"0c7ea54a78e4f73f","name":"Notify","server":"b77dc5f84903af5d","version":5,"debugenabled":true,"domain":"notify","service":"bot","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"The {{payload}} are open.\",\"title\": \"Left Open\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","output_location":"payload","output_location_type":"msg","x":830,"y":160,"wires":[["17f17dbeba54a359"]]},{"id":"b77dc5f84903af5d","type":"server","name":"https://ha.ha.co.uk","version":5,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

image

What am I doing wrong here?

When using mustache templates {{ something }} set the data field to JSON not j expression/jsonata

1 Like

@Mikefila That worked thanks.

@Kermit Example #1 might want updating as it’s using j expression/jsonata instead of JSON

How do I create that I want to see all the lights that are on when I leave the house?

I have something that works for door/window sensors that if open I get an alert

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/jsonata/call-service.html#notification-of-lights-left-on-when-leaving-home

Code is example flow 1c

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/jsonata/call-service.html#jsonata-and-the-call-service-node

1 Like

is there any possibility to find all devices by integration? i want to filter all esp devices and find offline