Home Assistant Community

Examples for using the new Get Entities node

#21

Is it possible to use this node to get all entities currently in HA? If so, how? I tried things like removing all properties, as well as setting property entity_id is not "" (with string selected), and entity id is .* with RegEx selected, all without luck.

Of course, I’m brand new to Node Red, so I may just not be doing it right :slight_smile:

0 Likes

#22

regex with .* worked for me, test it out and let me know.

[{"id":"30d7a4ea.4b0d5c","type":"ha-get-entities","z":"5eb3594f.d294b8","server":"ef067c6f.620e6","name":"","rules":[{"property":"entity_id","logic":"is","value":".*","valueType":"re"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":352,"y":384,"wires":[["ec642993.2a7988"]]},{"id":"1538f157.28693f","type":"inject","z":"5eb3594f.d294b8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":188,"y":384,"wires":[["30d7a4ea.4b0d5c"]]},{"id":"ec642993.2a7988","type":"debug","z":"5eb3594f.d294b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":534,"y":384,"wires":[]}]

edit:

All current states are also available in the global context.

[{"id":"1538f157.28693f","type":"inject","z":"5eb3594f.d294b8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":188,"y":384,"wires":[["61f648dd.48c528"]]},{"id":"ec642993.2a7988","type":"debug","z":"5eb3594f.d294b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":502,"y":384,"wires":[]},{"id":"61f648dd.48c528","type":"function","z":"5eb3594f.d294b8","name":"","func":"msg.payload = global.get('homeassistant').homeAssistant.states;\nreturn msg;","outputs":1,"noerr":0,"x":338,"y":384,"wires":[["ec642993.2a7988"]]}]
0 Likes

#23

Aha!

This was a “I don’t really know NodeRed yet” failure. I failed to use an inject node, just assumed that the get entities node could be a starting place. I don’t see anywhere in the info panel for get entites say what the input should be, am I missing it, or is that assumed?

0 Likes

#24

It’s doesn’t take any input variables other than just being “triggered”, not really sure the term that should be used.

0 Likes

#25

Interesting. The other one I was poking at, the “Events: all” module, doesn’t have any inputs, it just runs, so I was kind of expecting the same. I’ll know for next time.

0 Likes

#26

Thanx, my problem was that one cannot use this string as is in a template. I had to convert it back to an object, so i could use it in a notify node.

1 Like

#27

Does anyone know how to get the entity_id from an array of entities with the highest timeSinceChangedMs?

0 Likes

#28

Here’s a quick and dirty solution but does have at least one problem. If two entities have the same timeSinceChangedMs it will use the first one in the array.

const index = msg.payload.reduce((oldestIndex, current, currentIndex, array) => current.timeSinceChangedMs > array[oldestIndex].timeSinceChangedMs ? currentIndex : oldestIndex, 0);
msg.payload = msg.payload[index].entity_id;

return msg;

edit: different version

msg.payload = msg.payload.reduce((oldest, current) => current.timeSinceChangedMs > oldest.timeSinceChangedMs ? current : oldest).entity_id;

return msg;
0 Likes

#29

That’s awesome, the function works!

Thanks!

0 Likes