Examples for using the new Get Entities node

I’m trying to pass a rules array to the get_entities node, I think I am passing the data correctly however the node isn’t able to return any entities. Shouldn’t the below input be able to return something?

image

Should be an array of objects.

{
    "rules": [
        {
            "property": "entity_id",
            "logic": "is_not",
            "value": "binary_sensor.front_door",
            "valueType": "str"
        }
    ]
}

image

[{"id":"f14cf8a0.cfc3f8","type":"ha-get-entities","z":"1222406.8e2dfc","name":"","rules":[{"property":"","logic":"is","value":"","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":559,"y":2512,"wires":[["c5faa2d5.26584"]]},{"id":"5ec024d4.4f5a3c","type":"inject","z":"1222406.8e2dfc","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"rules\":[{\"property\":\"entity_id\",\"logic\":\"is_not\",\"value\":\"binary_sensor.front_door\",\"valueType\":\"str\"}]}","payloadType":"json","x":391,"y":2512,"wires":[["f14cf8a0.cfc3f8"]]},{"id":"c5faa2d5.26584","type":"debug","z":"1222406.8e2dfc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":733,"y":2512,"wires":[]}]

I’m trying to make it work, the debug gives me the right string, but I’m unable to pass the payload to a telegram notify call service node. But it does nothing. Here what I pass to telegram:

{"message":"{{payload}}"} -> does nothing
{"message":"payload"} -> the message is sent literally with word "payload".

What I’m doing wrong?

Change {"message":"{{payload}}"} to {"message": {{ payload }} }. When you wrap a mustache template in quotes, it, well, quotes it.

I’ve modified the object, that’s the error returned:

"Call-service API error.  Error Message: extra keys not allowed @ data['0']"

Would you mind posting your flow? I can take a look.

Here my flow, thanks

[{"id":"cde85205.f62c6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"5169ab15.65ecf4","type":"ha-get-entities","z":"cde85205.f62c6","server":"a4bbe168.69c95","name":"","rules":[{"property":"entity_id","logic":"includes","value":" sensor.0x00158d00023a7f42_battery,sensor.0x00158d0002c8bb56_battery,sensor.0x00158d0002e2eafa_battery,sensor.0x00158d00036b897e_battery","valueType":"str"},{"property":"state","logic":"lt","value":"90","valueType":"num"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":296,"y":380,"wires":[["2bad6c8e.94a224"]]},{"id":"2bad6c8e.94a224","type":"template","z":"cde85205.f62c6","name":"Format Friendly Name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":500,"y":380,"wires":[["b96da787.994d38"]]},{"id":"b96da787.994d38","type":"join","z":"cde85205.f62c6","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":670,"y":380,"wires":[["db1d6e70.b31e8","4f2da6f6.05a828"]]},{"id":"55f4ce31.8e5f7","type":"inject","z":"cde85205.f62c6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"86400","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":500,"wires":[["5169ab15.65ecf4"]]},{"id":"db1d6e70.b31e8","type":"debug","z":"cde85205.f62c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":460,"wires":[]},{"id":"4f2da6f6.05a828","type":"api-call-service","z":"cde85205.f62c6","name":"","server":"a4bbe168.69c95","version":1,"debugenabled":false,"service_domain":"notify","service":"telegram","entityId":"","data":"{\"message\": {{ payload }} }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":850,"y":360,"wires":[[]]},{"id":"a4bbe168.69c95","type":"server","z":"","name":"Home Assistant","addon":true}]

Ok, oddly on mine, {"message":"{{payload}}"} worked:

With that said, this is how I do mine:

[{"id":"6beffbf3.c08c8c","type":"inject","z":"5dddeadd.7fcfa4","name":"@ 6 Hours","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"21600","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":420,"wires":[["d8027d97.481fd"]]},{"id":"d8027d97.481fd","type":"ha-get-entities","z":"5dddeadd.7fcfa4","server":"df8e6220.fa7b2","name":"Get low batteries","rules":[{"property":"entity_id","logic":"is","value":"sensor\\..*_battery","valueType":"re"},{"property":"state","logic":"lte","value":"75","valueType":"num"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":330,"y":420,"wires":[["afca09f7.e5981"]]},{"id":"afca09f7.e5981","type":"function","z":"5dddeadd.7fcfa4","name":"Parse","func":"var theMessage = \"The following battery devices are low:\\n\";\nvar devices = [];\nmsg.payload.forEach(device => {\n    var n = device.attributes.friendly_name.replace(\"battery state\", \"\").replace(\" - Battery\", \"\");\n    var v = device.state;\n    d = {\n        name: n,\n        value: v\n    };\n    devices.push(d);\n});\ndevices.sort((a, b) => (a.value < b.value) ? 1 : -1);\n\ndevices.forEach(device => {\n    theMessage += device.name + \": \" + device.value + \"%\\n\";\n});\n\nmsg.payload = {\n    domain: 'notify',\n    service: 'system_messages',\n    data: {\n        message: theMessage.slice(0, -1)\n    }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":420,"wires":[["dc13847b.0e4d6"]]},{"id":"dc13847b.0e4d6","type":"api-call-service","z":"5dddeadd.7fcfa4","name":"Notify","server":"df8e6220.fa7b2","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":420,"wires":[[]]},{"id":"df8e6220.fa7b2","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false}]

I’ve tried yours, and for some reasons the get entities node doesn’t discover any sensor. It’s probably a problem on my system. :frowning:

I’m not even able to upload images. :scream:

1 Like

Yeah, that’s weird.

Make sure in your get_entities looks like this (and change output type from split to array):

Derp… don’t use my regex. My devices are very meticulously named. LOL

From what I can tell it should match this one:

image

As I said something is not working, I’ll need to find out what it is. Sigh.

Try removing your second conditional (state < X) and see what happens.

Nothing happens.

Change “in” to “is” in your get-entities node for the entity_id.

I can’t, no regex option given. This evening I’ll do a snapshot. And then I’ll try to remove and install again nodered. (meanwhile I’m updating it to the latest version).

Ok. Sounds good. I was thinking you have taken my get-entites and merged it into yours. Getting get-entities right sometimes is a hair-raising experience. LOL

eheh, no I copy-pasted it directly into a new flow. I let you know if I make some progress, thanks for your time.

1 Like

Lets see if the screen shot work out better (I’m a visual person :wink:), it been a while since I did this and went some of the same challenges. the only one I didn’t take a shot of it the telegram node. If you need it let me know.

get entities

template

join

1 Like

Sadly the get entities node seems to not work on my HA. I set it up as you did but it doesn’t find any device.
image
image

Are you sure you selected the right server? In my case I had two Home Assistant servers selectable. Does a drop down appear if you try to write attributes.battry_level?

1 Like