Examples for using the new Get Entities node

Hi,
using one of your examples, I have this going:

[{"id":"86fd4fce.8920c","type":"template","z":"24e1aa62.edaa66","name":" ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":870,"y":120,"wires":[["585221ef.d4a54"]]},{"id":"2939427d.0edb7e","type":"ha-get-entities","z":"24e1aa62.edaa66","server":"3ddad461.2f050c","name":"Get","rules":[{"property":"entity_id","logic":"includes","value":"binary_sensor.wycabinetdoor,binary_sensor.wydeepfreezerdoor,binary_sensor.wypantrydoor,binary_sensor.wyfridgedoor,binary_sensor.wymedcab,binary_sensor.wytest","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":750,"y":120,"wires":[["86fd4fce.8920c"]]},{"id":"585221ef.d4a54","type":"join","z":"24e1aa62.edaa66","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":970,"y":120,"wires":[["b9762f6.ecdc1d"]]},{"id":"b9762f6.ecdc1d","type":"api-call-service","z":"24e1aa62.edaa66","name":"Alert Alexa","server":"3ddad461.2f050c","version":1,"service_domain":"notify","service":"alexa_media","entityId":"","data":"{\"data\":{\"type\":\"announce\",\"method\":\"speak\"},\"message\":\"The {{payload}} is open.\",\"target\":[\"media_player.living_room\",\"media_player.keesha\",\"media_player.bedroom\",\"media_player.bathroom\",\"media_player.kitchen\",\"group.alexa\"]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":120,"wires":[[]]},{"id":"3ddad461.2f050c","type":"server","z":"","name":"Home Assistant"}]

The problem I run into is if one of my kids leave the pantry open, then open something else, it doesn’t alert us again until everything in the group is “off”

What am I missing?
Thanks!

Your export doesn’t show what is triggering your flow but if you’re using group.something it will only trigger again after the whole group resets to off.

You can use substring filter type in an event state node and then use the same comma-delimited list as you do in the get entities node instead of the group.

Thanks. I ended up just splitting them out one by one for now and later will change the names around.

if I want to get different details from multiple devices in a flow, would you then need to call the getEntities call?

INIT:
e.g. on the init of my flow i want to get:

  • Sensor1.lux
  • Light1.dimlevel
  • Light1.state
  • Light2.dimlevel
  • Light2.state
  • Light3.dimlevel
  • Light3.state

I know the entity IDs.

Trigger:
The flow would run if ANY of these conditions is true.

  1. every minute
  2. in case the lux changes of 1 defined motion sensor
  3. in case motion is triggered of one of 2 defined motion sensors

So basically:
Trigger -> INIT -> FunctionBlock

Any guidance is helpful :slight_smile:

1 Like

Hi there HA NodeRed’ers… I’m a hobbyist (not a coder) and I’m banging my head on a wall trying to work out how to make a light automation work…

I have a smart front door lock entity (Yale) that when it is unlocked I want to save the state(on/off) and colour etc of a light entity in the lounge before turning the bulb red (so folk in the lounge know the front door is unlocked).

Then when the door ls locked again I would like to return the light to its former state - either on or off and its previous colour.

It looks like you can pull the states and attributes and pass through the NodeRed message flow but I am soooooooooooo out of my depth.

Any of you smart HA community folks care to help direct me ?

Does this help you?

https://community.home-assistant.io/t/example-saving-and-restoring-states/99061

Or would you like a more specific example?

[{"id":"5d8550c1.0ba7a","type":"server-state-changed","z":"316b7737.65f728","name":"","version":1,"entityidfilter":"sensor.front_door_lock","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"unlocked","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":230,"y":480,"wires":[["7f5b445.2a4fbbc"],["161c822d.85c10e"]]},{"id":"7f5b445.2a4fbbc","type":"api-current-state","z":"316b7737.65f728","name":"Save Light State","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.lounge","state_type":"str","state_location":"","override_payload":"none","entity_location":"lounge_light","override_data":"flow","blockInputOverrides":false,"x":496,"y":480,"wires":[["5e6bd94e.ad2118"]]},{"id":"5e6bd94e.ad2118","type":"api-call-service","z":"316b7737.65f728","name":"Set Lounge to Red","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lounge","data":"{\"rgb_color\": [255,0,0]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":698,"y":480,"wires":[[]]},{"id":"ce982b7b.7cac38","type":"api-call-service","z":"316b7737.65f728","name":"Light Off","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.lounge","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":668,"y":528,"wires":[[]]},{"id":"161c822d.85c10e","type":"switch","z":"316b7737.65f728","name":"","property":"lounge_light.state","propertyType":"flow","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":466,"y":528,"wires":[["ce982b7b.7cac38"],["ab142334.e9f33"]]},{"id":"ab142334.e9f33","type":"api-call-service","z":"316b7737.65f728","name":"Reset Light","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lounge","data":"{    \"brightness\": {{flow.lounge_light.attributes.brightness}},     \"rgb_color\": {{flow.lounge_light.attributes.rgb_color}}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":678,"y":576,"wires":[[]]}]

Hi @Kermit. Thank you very much for this it has been very helpful getting me started. Here is my version of your flow;

Everything works fine when the light state is off, however, if the light is already on then the reset flow terminates with an API error;

image

I’ve checked the data element of the Light On call, but can’t work out what I’m doing wrong…

{"brightness": {{flow.light.lounge_table_2.attributes.brightness}}, "rgb_color": {{flow.light.lounge_table_2.attributes.rgb_color}} }

Any hints?

Can you export your flow or show what you’re assign the current-state node data to? Within the call-service node there’s a checkbox to Show Debug Information it will output another debug line of what actually wasn’t sent to HA.

Hi @Kermit, I clicked the checkbox as requested but it did not seem to add any additional information to the debug window.

I’ve attached the full flow for you below;

[
    {
        "id": "da1768ea.51488",
        "type": "tab",
        "label": "Front Door Lock",
        "disabled": false,
        "info": ""
    },
    {
        "id": "904aa5c4.d230c",
        "type": "api-current-state",
        "z": "da1768ea.51488",
        "name": "Save Light State",
        "server": "aae3933d.e196d",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "light.lounge_table_2",
        "state_type": "str",
        "state_location": "",
        "override_payload": "none",
        "entity_location": "light.lounge_table_2",
        "override_data": "flow",
        "blockInputOverrides": false,
        "x": 380,
        "y": 280,
        "wires": [
            [
                "3f414e30.aafb6a",
                "a4788d1f.68af28"
            ]
        ]
    },
    {
        "id": "3f414e30.aafb6a",
        "type": "api-call-service",
        "z": "da1768ea.51488",
        "name": "Set Lounge to Red",
        "server": "aae3933d.e196d",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.lounge_table_2",
        "data": "{\"rgb_color\": [255,0,0]}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 750,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "4aad762f.fc6058",
        "type": "api-call-service",
        "z": "da1768ea.51488",
        "name": "Light Off",
        "server": "aae3933d.e196d",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.lounge_table_2",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 530,
        "y": 370,
        "wires": [
            []
        ]
    },
    {
        "id": "71027093.1f2538",
        "type": "switch",
        "z": "da1768ea.51488",
        "name": "",
        "property": "light.lounge_table_2",
        "propertyType": "flow",
        "rules": [
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 340,
        "y": 360,
        "wires": [
            [
                "4aad762f.fc6058",
                "f7c66e7.012a51"
            ],
            [
                "42e06631.c9555",
                "29aff69c.490312"
            ]
        ]
    },
    {
        "id": "42e06631.c9555",
        "type": "api-call-service",
        "z": "da1768ea.51488",
        "name": "Reset Light",
        "server": "aae3933d.e196d",
        "version": 1,
        "debugenabled": true,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.lounge_table_2",
        "data": "{\"brightness\": {{flow.light.lounge_table_2.attributes.brightness}}, \"rgb_color\": {{flow.light.lounge_table_2.attributes.rgb_color}} }",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 540,
        "y": 430,
        "wires": [
            []
        ]
    },
    {
        "id": "a4788d1f.68af28",
        "type": "debug",
        "z": "da1768ea.51488",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 680,
        "y": 140,
        "wires": []
    },
    {
        "id": "f7c66e7.012a51",
        "type": "debug",
        "z": "da1768ea.51488",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 660,
        "y": 330,
        "wires": []
    },
    {
        "id": "29aff69c.490312",
        "type": "debug",
        "z": "da1768ea.51488",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 430,
        "y": 520,
        "wires": []
    },
    {
        "id": "c73da24d.6824",
        "type": "server-state-changed",
        "z": "da1768ea.51488",
        "name": "Door Lock",
        "server": "aae3933d.e196d",
        "version": 1,
        "entityidfilter": "lock.assa_abloy_yale_conexis_l1_sd_l1000_ch_locked_2",
        "entityidfiltertype": "exact",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "unlocked",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 90,
        "y": 210,
        "wires": [
            [
                "904aa5c4.d230c",
                "a4788d1f.68af28"
            ],
            [
                "71027093.1f2538",
                "a4788d1f.68af28"
            ]
        ]
    },
    {
        "id": "aae3933d.e196d",
        "type": "server",
        "z": "",
        "name": "Home Assistant"
    }
]

I appreciate you taking the time to help me out with this.

Looks to be a bug.

Switch the data type of the data field in the call-service node to JSONata expression and use:

{
   "brightness": $flowContext("light.lounge_table_2").attributes.brightness,
   "rgb_color": $flowContext("light.lounge_table_2").attributes.rgb_color 
}

edit:
This also can be fixed by just adding brackets around the rgb color value:

{"brightness": {{flow.light.lounge_table_2.attributes.brightness}}, "rgb_color": [{{flow.light.lounge_table_2.attributes.rgb_color}}] }
2 Likes

Thanks @Kermit. I was getting the same error with the first suggestion, however, the second one (brackets around rgb) works perfectly!

Sincere appreciation for your assistance.

@Kermit is there away to get entities who’s id’s “contain” a keyword. For example all id’s who have the word “window” in them?

I tried this setup but it always returns zero results even though I have more than one window open. The idea was keep from having to make 14 current status nodes for all my windows to keep the light green if any window is left open and only change it back to normal if they are all closed.

Thanks for any assistance you can provide!

[{"id":"719a22bd.bc58ec","type":"server-state-changed","z":"7aaedca2.e8fb84","name":"","server":"d79fd69f.0bea18","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"window","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":240,"y":960,"wires":[["3ea8285a.908a78"]]},{"id":"3ea8285a.908a78","type":"ha-get-entities","z":"7aaedca2.e8fb84","server":"d79fd69f.0bea18","name":"","rules":[{"property":"entity_id","logic":"includes","value":"window","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":570,"y":960,"wires":[["7f55f6bf.336b58","134b752c.4f6e9b"]]},{"id":"7f55f6bf.336b58","type":"function","z":"7aaedca2.e8fb84","name":"","func":"if (msg.payload === 0) {\n    return [null, msg];\n}\n\nif (msg.payload !== 0){\nreturn [msg, null];\n    \n}\nreturn [null,null];","outputs":2,"noerr":0,"x":750,"y":960,"wires":[["59f51de0.345014"],["151d9068.65b2f"]]},{"id":"59f51de0.345014","type":"api-call-service","z":"7aaedca2.e8fb84","name":"Turn Office Lamp Green","server":"d79fd69f.0bea18","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.office_lamp","data":"{\"brightness_pct\":\"100\",\"color_name\":\"green\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1030,"y":940,"wires":[[]]},{"id":"151d9068.65b2f","type":"api-call-service","z":"7aaedca2.e8fb84","name":"Turn Office Lamp Soft White","server":"d79fd69f.0bea18","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.office_lamp","data":"{\"transition\":\"2\",\"kelvin\":\"3000\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":1000,"wires":[[]]},{"id":"134b752c.4f6e9b","type":"debug","z":"7aaedca2.e8fb84","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":1060,"wires":[]},{"id":"d79fd69f.0bea18","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

image

3 Likes

Thanks so much! Just when I thought I looked at every settings I overlooked that one in the drop down.

BTW I can see you are using function node probably just to make decision based on entities number found?
You can make it without function node (nothing bad in your approach though).
Get Entities node can return Count in payload. Then using Switch node, you can check if value is 0 or greater.

1 Like

Yes, you’re right. I ended up changing to the method you suggested not to long afterwards and then scraped the flow entirely because I decided I wanted to take the current state of the lights, save it, change the color to indicate a window was open, and then restore it to the previous state once all the windows were closed.

Hi @Kermit,

Thanks for your help with this node.
I’m trying to create a battery sensor notification. This does currently work, but I imagine there is a way to just shift the output from the array to a string without initially outputting it as split pieces and then re-joining it together.

Is there a cleaner way to send a notification of the output of the get-entities node as an array?

[{"id":"14738d25.15b903","type":"ha-get-entities","z":"d64d664b.8c1bf8","server":"c75798f0.9eb148","name":"Low battery","rules":[{"property":"attributes.battery_level","logic":"lt","value":"battery_threshold","valueType":"flow"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":1830,"y":420,"wires":[["28d8440e.046acc"]]},{"id":"308bb70.1836b4a","type":"join","z":"d64d664b.8c1bf8","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":", ","joinerType":"str","accumulate":false,"timeout":".1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1660,"y":600,"wires":[["9359c0b0.5f391","cbecdca1.66c67"]]},{"id":"cbecdca1.66c67","type":"template","z":"d64d664b.8c1bf8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"message\":\"You have {{flow.number_of_entities_below_threshold}} entities with battery levels below {{flow.battery_threshold}}%: {{payload}}\",\"title\":\"Battery Alert\"}","output":"str","x":1830,"y":600,"wires":[["f11b104.ef83af"]]},{"id":"f11b104.ef83af","type":"debug","z":"d64d664b.8c1bf8","name":"template","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2010,"y":600,"wires":[]},{"id":"d222a29b.c3425","type":"change","z":"d64d664b.8c1bf8","name":"threshold","rules":[{"t":"set","p":"battery_threshold","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1770,"y":360,"wires":[["14738d25.15b903"]]},{"id":"d7cc134e.7851","type":"inject","z":"d64d664b.8c1bf8","name":"Set","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"15 10 * * *","once":false,"onceDelay":0.1,"x":1710,"y":300,"wires":[["d222a29b.c3425"]]},{"id":"ff0eb13a.c2753","type":"change","z":"d64d664b.8c1bf8","name":"","rules":[{"t":"move","p":"parts.count","pt":"msg","to":"number_of_entities_below_threshold","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1960,"y":540,"wires":[["308bb70.1836b4a"]]},{"id":"28d8440e.046acc","type":"template","z":"d64d664b.8c1bf8","name":"combine","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.entity_id}} ({{payload.attributes.battery_level}}%)","output":"str","x":1870,"y":490,"wires":[["ff0eb13a.c2753"]]},{"id":"c75798f0.9eb148","type":"server","z":"","name":"Home Assistant Synology","legacy":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|ON|home|open","connectionDelay":true,"cacheJson":true}]

Here is how I did mine using get entities and telegram.

[{"id":"6f7813b2.784d8c","type":"ha-get-entities","z":"fc32e4e1.e1bf78","server":"f0aa0465.fa7ce8","name":"","rules":[{"property":"attributes.battery_level","logic":"lte","value":"20","valueType":"num"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":290,"y":2340,"wires":[["86f27845.2073f8"]]},{"id":"cbd98aae.1aa4e8","type":"inject","z":"fc32e4e1.e1bf78","name":"","topic":"","payload":"","payloadType":"date","repeat":"86400","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":2340,"wires":[["6f7813b2.784d8c"]]},{"id":"86f27845.2073f8","type":"template","z":"fc32e4e1.e1bf78","name":"Battery msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"The battery level for the {{payload.attributes.node_name}} is at {{payload.attributes.battery_level}}%","output":"str","x":450,"y":2340,"wires":[["47120015.2c969"]]},{"id":"47120015.2c969","type":"join","z":"fc32e4e1.e1bf78","name":"combine msgs","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":620,"y":2340,"wires":[["3c9a0af4.5a5d86"]]},{"id":"3c9a0af4.5a5d86","type":"telegrambot-notify","z":"fc32e4e1.e1bf78","name":"low battery","bot":"6cf9d125.c9a1f","chatId":"999999999","message":"","parseMode":"","x":790,"y":2340,"wires":[]},{"id":"f0aa0465.fa7ce8","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"6cf9d125.c9a1f","type":"telegrambot-config","z":"","botname":"somebot","usernames":"somename","chatIds":"999999999","pollInterval":"300"}]

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