Node-red get entity parent / group

How can I get an entity ‘parent’ or ‘group’ in node-red.

Example. I’ve a ‘states node’ with regex _adjust$ that captures a lot of entities. Next step I would like to lookup what ‘group’ it’s attached to (e.g. livingroom, bedroom).

Looking at the data there’s something called parent_id. Can I set that value somehow in HA?

{
  "topic": "input_number.bedroom_light1_adjust",
  "payload": 73,
  "data": {
    "entity_id": "input_number.bedroom_light1_adjust",
    "old_state": {
      "entity_id": "input_number.bedroom_light1_adjust",
      "state": 28,
      "attributes": {
        "initial": null,
        "editable": true,
        "min": 0,
        "max": 100,
        "step": 1,
        "mode": "slider",
        "unit_of_measurement": "%",
        "friendly_name": "Sänglampa Test"
      },
      "last_changed": "2020-10-24T15:04:00.445742+00:00",
      "last_updated": "2020-10-24T15:04:00.445742+00:00",
      "context": {
        "id": "25ca5e50160a11eb9eb85fcead666a97",
        "parent_id": null,
        "user_id": "69df44825150485e896ba4e8cc8af97e"
      },
      "original_state": "28.0"
    },
    "new_state": {
      "entity_id": "input_number.bedroom_light1_adjust",
      "state": 73,
      "attributes": {
        "initial": null,
        "editable": true,
        "min": 0,
        "max": 100,
        "step": 1,
        "mode": "slider",
        "unit_of_measurement": "%",
        "friendly_name": "Sänglampa Test"
      },
      "last_changed": "2020-10-24T15:04:36.885194+00:00",
      "last_updated": "2020-10-24T15:04:36.885194+00:00",
      "context": {
        "id": "3b8296ff160a11eb8ae4c7b2ebc22777",
        "parent_id": null,
        "user_id": "69df44825150485e896ba4e8cc8af97e"
      },
      "original_state": "73.0",
      "timeSinceChangedMs": 15
    }
  },
  "_msgid": "c3e9465.462d8b8"
}

If you want the Home Assistant group then something like this

image

[{"id":"9cf37e3a.cbbb","type":"inject","z":"ffbd7f06.4a014","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"input_number.bedroom_light1_adjust","x":498,"y":800,"wires":[["62bb23de.6b3dac"]]},{"id":"10aee7a2.3a0858","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":800,"wires":[]},{"id":"62bb23de.6b3dac","type":"ha-get-entities","z":"ffbd7f06.4a014","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"group.","valueType":"str"},{"property":"","logic":"jsonata","value":"topic in $entity().attributes.entity_id","valueType":"jsonata"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":648,"y":800,"wires":[["10aee7a2.3a0858"]]}]

If you wanted the Home Assistant area them something like this

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/get-state_changed-events-based-on-area.html

1 Like

Exactly what I was looking for. Thanks.