Examples for using the new Get Entities node

On example two, I’m trying to use all of the lights in a specific group (group.kitchen), and it seems to identify those 4 entities, but the next node turns on all lights. I was only able to make the service call work with the split output.

hi. i am having the same problem.
i am trying to send a message to my telegram notification but am not able to do so. can you please guide me for the same. i am trying to use the Telegram_bot node in node-red for the same. attaching the snapshots.
@Kermit can you plz guide on this?
i am trying to retrieve the switches which are on currently and pass the message to my Telegram notification.
request your help.!

Hi,

I am trying to do something which I thought should be simple enough but I am running into issues I cannot explain…
I am trying to pull a list of entities whose state hasn’t been updated in say 1h… (ie timeSinceChangedMs > 3600000)

For some reason, this does not return any entities… Am I missing something?

Note, I was able to remove the 2nd condition then split my array using a split node, feed all the messages into a “Switch” node to filter out and then join them again but this feels convoluted and I would like to understand how this node is supposed to work…

Any help would be appreciated…

Guillaume

timeSinceChangedMs doesn’t exist in this context only the text timestamps from Home Assistant.

You can use a JSONata expression to convert them to a timestamp and check that way.

$millis() - $toMillis($entity().last_changed) > 3600000

image

[{"id":"da45ecf3.23b07","type":"ha-get-entities","z":"ffbd7f06.4a014","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"sensor.room","valueType":"str"},{"property":"ANY TEXT NEEDS TO BE HERE","logic":"jsonata","value":"$millis() - $toMillis($entity().last_changed) > 3600000","valueType":"jsonata"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":320,"y":1248,"wires":[["4a966b2b.ce1dd4"]]},{"id":"225bd07a.1d69b","type":"inject","z":"ffbd7f06.4a014","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1248,"wires":[["da45ecf3.23b07"]]},{"id":"4a966b2b.ce1dd4","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":1248,"wires":[]}]

Found a bug, while making this example, that requires the property field not to be empty but the example should still work.

edit: I’ll see about adding in timeSinceChangedMs as a filterable property

1 Like

That works, thanks a lot!

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}]