Examples for using the new Get Entities node

That was the problem my friend. The server for some reason (probably because I use it at home and at work and it confused it) Many many thanks :slight_smile:
Now, Iā€™ve problems with the telegram node that for some reasons returns this error message:
ā€œCall-service API error. Error Message: Service not found.ā€

But the error my have to do with code-in-progress function node.I need to check the others nodes.

ETA:
horray, now Iā€™m able to send a telegram message. The problem with this node was also related to the misconfigured HA server. Now I will play around with attributes and/or regex to extract all the sensors at once.

many thanks to everyone!!!

1 Like

Most annoyingā€¦
I always look at:

image

Go to ā€œconfiguration nodesā€ and look for nodes with ā€œ0ā€.

Then double click on it, and you can delete it (most left top)ā€¦

but be very carefulā€¦ these are you main entrances to the apiā€™s.

1 Like

Hi again, Iā€™m trying to send my low battery report to the Telegram note, but for some obscure (again) reasons the message is not delivered by the node. The bot configuration is right since if I compile the message form it gets delivered correctly, any suggestions?
image

Hmmmm, are you getting any errors out of the Telegram node? I donā€™t use Telegram, so Iā€™m not 100% sure Iā€™ll be able to help.

Are you using Telegram through HA (notify) or are you trying to call Telegram directly from NodeRed?

At the beginning I was trying to use it though ha service, then I tried your (cooler) function and following that I installed the telegram bot node (so I suppose to answer your question, itā€™s the latter).
The fact is that Iā€™ve found different objects, and even nodes. I have notify / payload. I was trying to use the notify node, but it stays silent. Not even errors. Now Iā€™m doing some tests with telegram:payload.

If you have Telegram setup through HA, it might be easier to use that and then the format is the same no matter what service you use. Personally, I use Pushover and Slack for all my textual notifications, but both of those go through HA as well with the exception of my error nodes as HA may not always be available.

Iā€™ll setup a Telegram test over my lunch hour today and see what I can break. :smiley:

Just to have a visual idea, here what Iā€™ve tried that remains silent.


image
image

Fixed, it was my fault, I didnā€™t have the right telegram node. One was missing.
Not it works!

now Iā€™m having multiple entries for the same device while parsing the attributes. Iā€™ll have to modify the fn to exclude them.

1 Like

I was wondering if anyone has any ideas with this. Iā€™m using get entities to return all lights currently on. I want to turn off any lights that are returned by this node. I have the get entities node returning the correct results in an array, but not sure how to use the service call to turn off the lights in the results.

Any help would be appreciated!

[{"id":"6a685ddd.ebf4d4","type":"ha-get-entities","z":"1f5cb10d.aa77a7","server":"48b6dc20.3e4a34","name":"Get Number of Entities","rules":[{"property":"entity_id","logic":"starts_with","value":"light.","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"count","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":580,"y":1200,"wires":[["88e6a73e.654e78"]]},{"id":"88e6a73e.654e78","type":"api-call-service","z":"1f5cb10d.aa77a7","name":"Turn off all lights","server":"48b6dc20.3e4a34","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"","data":"{\"entity_id\":\"{{payload.*.entity_id}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":780,"y":1200,"wires":[[]]},{"id":"48b6dc20.3e4a34","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

You could use the split output of the get-entities node to do multiple several service calls.

image

[{"id":"295c21dc.5cb70e","type":"inject","z":"ffbd7f06.4a014","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":332,"y":2368,"wires":[["25835b72.64f7a4"]]},{"id":"25835b72.64f7a4","type":"ha-get-entities","z":"ffbd7f06.4a014","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"light.","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":486,"y":2368,"wires":[["487c9089.ff5bf"]]},{"id":"487c9089.ff5bf","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn off Light","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":662,"y":2368,"wires":[[]]}]

or use a JSONata expression with a single service call

[{"id":"295c21dc.5cb70e","type":"inject","z":"ffbd7f06.4a014","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":2358,"wires":[["25835b72.64f7a4"]]},{"id":"25835b72.64f7a4","type":"ha-get-entities","z":"ffbd7f06.4a014","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"light.","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":494,"y":2358,"wires":[["487c9089.ff5bf"]]},{"id":"487c9089.ff5bf","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn off Light","version":1,"debugenabled":true,"service_domain":"light","service":"turn_off","entityId":"","data":"{\"entity_id\": $join(payload.entity_id, \",\")}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":2358,"wires":[[]]}]
1 Like

You never cease to amaze me with your Node-Red wizardry. The first one did exactly what I wanted.

When it ā€œsplitsā€, I presume it sends a subsequent service call for each entity that is returned? Just want to understand why that worked.

Thanks again for your help Kermit!

it splits the array into individual messages. put a debug node after the get-entities node and youā€™ll see

1 Like

but turn_off servive call accepts multiple entities at once. It would be more sufficient to use this feature rather than calling turn_off for each light separatelly.
Not sure if product of get entities can be directly accepted. but shouldnā€™t be a problem to transform it into required comma separated string

BTW sending turn_off to all lights regardless their state gives the same result. So no need to test them for ā€˜onā€™ state. Even better option is to have a light being an agregate of all lights and then send turn off to this single light.

Is it possible to filter with regex? It seems not in the dropdown list.

Itā€™s under is and is not

1 Like

Is this still the way to check timeSinceChangedMs? I am running 0.30.1.

Thanks!

Hi guys,

alright, first I have to admit I just started using Node-RED and IĀ“m not a Coder so please bare with me if this request might sound rather simple stupid to you.

Existing Setup
I have a whole bunch of flower sensors to measure moisture, soil fertility etc. for my plants. I managed to integrate them to HA via custom integration so that every measurand of a sensor is represented through an individual entity (unfortunately the sensor itself doesnĀ“t exist as deviceā€¦). Furthermore I hooked up my Amazon Alexa Account so that I can address different Echo devices for Text to Speech automations.

Use Case
As a hobby gardener, I want Alexa to notify me once a plant needs water or fertilizer so that I have the most beautiful balcony in the neighborhood :slight_smile:

Using the ā€œtrigger stateā€ node I already managed that all moisture entities are regularly checked against the threshold. What IĀ“m failing to achieve is:

  1. Fetch the state attributes ā€œfriendly_nameā€ and ā€œmeanā€ from the entity that triggered the action
  2. create a message (template) that contains the ā€œfriendly_nameā€ and ā€œmeanā€ number as variables. (i.e. ā€œAttention, moisture sensor 11 [friendly_name] is at 14 [mean] %ā€

I tried achieving this using the ā€œget entitiesā€ node but I just donĀ“t understand how to configure it properly in order to fetch the needed state attributes. Anybody here to help me green the planet? :seedling:

If mean is an attribute of the sensor that triggered the flow. You should already have all the information you need from the trigger state node. Place a debug node after the trigger state and output msg.data you find friendly_name and mean under msg.data.attributes.

If youā€™re using a call-service node to trigger alexa take a look at https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/call-service.html for how to build messages using msg properties. Otherwise, you can use the template node and mustache templates to build a payload for a different type of node.

Thanks much @Kermit , this hint pointed me in the right direction to actually solve it :slight_smile: Just one more question: Now the alerting message is send every time the measured value drops even further. Is there a way to time the message sending like once a day between 8am and 8pm or sth. alike?

Is there a way to combine several enties? For example aqara temp sensors have around 6 entities ids. And seems that each one presents attributes_battery. So iā€™m getting around 6 messages for battery low.

The battery level for the temp_kotelnaya_battery is at 86%,The battery level for the temp_kotelnaya_temperature is at 86%,The battery level for the temp_kotelnaya_humidity is at 86%,The battery level for the temp_kotelnaya_pressure is at 86%,The battery level for the temp_kotelnaya_linkquality is at 86%,The battery level for the temp_kotelnaya_voltage is at 86%