Get Entities node

Hello all,

Kind of new to Node Red here. So I’m trying to poll multiple entities every 60 seconds using the “Get Entities” node on Node Red (running as an Add-On on Home Assistant) - I’m not sure what I’m doing wrong, all I see is “no results” (see attached screenshot)

Here’s a screenshot of the get entities node:

Can someone please explain to me what I’m doing wrong here?

My end goal is to send values over MQTT. I’m able to successfully do this using the “Poll State” node+function node (that modifies payload into the json format I want) + mqtt out node - but this works for one entity at a time. I’m trying to do this for multiple entities using a single flow.

Thanks

Welcome to the forum @vish022091

Most people here use Node-red as a stand-alone programming language, not as an add-on to Home Assistant.

Are you expecting your Entities node to generate messages when something happens - perhaps when an 'Entity' pops into existence or changes state?

I suspect you are better off to ask in the Home Assistant forum, where folks will be more familiar with HA nodes.

In the meantime this playlist will introduce you to the Node-red way, which is rather different to how HA does things.
Node-RED Essentials. The short videos are made by the developers of node-red.

2 Likes

I don't use HA either but my interpretation of the node config is that you can get a list of "entities" whose "state" property matches what you have typed in.

So I'm guessing that nothing has a "state" of sensor.system_monitor_processor_temp, as that is the name of an entity not a state value, which likely should be a temperature, eg 40 degrees.

I don't have the node, but see what else other than state you can select, perhaps an entity id/name and then use a wild card to select multiple. Maybe contains "sensor.system_monitor_"

You could then filter the results to get the ones you want downstream.

It is rare for entities in home assistant to need to be polled. If you use those entities in an event state node, they will trigger whenever there is an update.

If you want to get the state of a particular entity at a certain time use the entity in a current state node. get entities is for finding entities e.g. find all door or window sensors that are reporting open.

You can find examples for the get entities node at the bottom of this page. You can find examples on how to use each node here.

1 Like

I just came back here to say that polling is not the best option and there must be another way to get your values, but Mike beat me to it, with what sounds like your best option :wink:

2 Likes

Welcome to the forum @vish022091
Thank you :slightly_smiling_face:

I did post this on the Home Assistant forum - I'm still kind of not sure after the response I got there and so I thought I'd post here

Are you expecting your Entities node to generate messages when something happens - perhaps when an 'Entity' pops into existence or changes state?

Yes, I'm expecting a msg.payload output every 60 seconds with last entity state values.

So I'm guessing that nothing has a "state" of sensor.system_monitor_processor_temp, as that is the name of an entity not a state value, which likely should be a temperature, eg 40 degrees.

Yes, I thought the same.

see what else other than state you can select, perhaps an entity id/name and then use a wild card to select multiple. Maybe contains "sensor.system_monitor_"

The funny thing is, the Entity Property field has no ‘entity_id’ option available in its list of selectable items. I can see state, last_changed, etc., but not any ‘entity_id’.

It is rare for entities in home assistant to need to be polled. If you use those entities in an event state node, they will trigger whenever there is an update.

My use case involves extracting values regardless of state changes and hence the polling. I am able to poll and send via mqtt an individual entity state every 60 secs. (see screenshot for flow) and I was wondering if I could do the same for a group of entities and not just a single one.

get entities is for finding entities e.g. find all door or window sensors that are reporting open.

I see. So I infer there's no way to obtain entity state values.

examples for the get entities node at the bottom of this page

I'm not sure where in the gui one enters the payload similar to the one at the bottom of the page. Don't know if HA's Node-red GUI allows for that

Thanks!

Since you already need to process the values, I would approach this through a function node. You can pull the state of an entity inside a function.

To get a state of an an entity

const hallwayLight = global.get('homeassistant.homeAssistant.states["switch.hallway"].state');

To get the attribute of an entity.

const cloudCover = global.get('homeassistant.homeAssistant.states["weather.openweathermap"].attributes.cloud_coverage');

Hit that with an inject inject every 30 seconds.

Edit: To import the json examples in the top right hamburger menu, choose import. Paste the json and click import.

1 Like

I updated the above post.

I figured it out, thank you!! Function node it is!

1 Like

One other thing, it's been so long since I started using NR, I can't remember if globals are enabled by default. Inside an ha node > server > pencil edit button

If it is not enabled, enable, restart NR, then restart HA

1 Like