Passing RegEx into node (get entities or current state)

I was wondering, is it possible to pass a (variable) (part of ) regEx into another node.
In the node below I’m using a regEx to find all groups, belonging to a specific area, in this case "woonkmr (with state == “on”)

[{"id":"41a6f55123e3d0f6","type":"ha-get-entities","z":"593fb70375108267","name":"","server":"2fba4297.e4145e","version":0,"rules":[{"property":"entity_id","logic":"is","value":"group...*woonkmr_.*","valueType":"re"},{"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":590,"y":400,"wires":[["53f6565f375405fe"]]},{"id":"2fba4297.e4145e","type":"server","name":"Home Assistant BasAdmin","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

In order to have a more flexible flow I would like to be able to pass the area part (“woonkmr”) as a variable for the get entities node.
The whole flow is driven by a helper (presence) for a specific area, when it changes (to off) it triggers a routine to switch off lights and in the end all devices in the area. But I want this only to happen when lights and such are on in that area in the first place…

[{"id":"41a6f55123e3d0f6","type":"ha-get-entities","z":"593fb70375108267","name":"","server":"2fba4297.e4145e","version":0,"rules":[{"property":"entity_id","logic":"is","value":"group...*woonkmr_.*","valueType":"re"},{"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":590,"y":400,"wires":[["53f6565f375405fe"]]},{"id":"2fba4297.e4145e","type":"server","name":"Home Assistant BasAdmin","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Above is the work around, but I was just wondering

Yes but not in the node config. You can pass in an array of rules as input as per the doc. So use a change node to set the payload with a jsonata expression to something like this before the get entities node:

{
  "rules": [
    {
      "property": "entity_id",
      "logic": "is",
      "valueType": "regular expression",
      "value": ".*" & field_with_area_from_msg & ".*"
    },
    {
      "property": "state",
      "logic": "is",
      "valueType": "string",
      "value": "on"
    }
  ]
}

Believe that should work. Haven’t really tried to set rules for a get entities node from input before myself but the doc says it is supported so it should work.

Worked! (just had to change “regular expression” into “re” and “string” to “str”)

Thanks!
Below is the result

[{"id":"9d28417466b85a87","type":"ha-get-entities","z":"593fb70375108267","name":"Entities","server":"2fba4297.e4145e","version":0,"rules":[{"property":"entity_id","logic":"is","value":"payload","valueType":"msg"},{"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":"10","x":420,"y":340,"wires":[["c6ec0c45751e0333"]]},{"id":"5ad07fd4696667bb","type":"change","z":"593fb70375108267","name":"RegEx as Payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t  \"rules\": [\t    {\t      \"property\": \"entity_id\",\t      \"logic\": \"is\",\t      \"valueType\": \"re\",\t      \"value\": \"^light.\"  & $substringBefore($substringAfter(target, \"group.\"), \"_all\") & \".*\"\t    },\t    {\t      \"property\": \"state\",\t      \"logic\": \"is\",\t      \"valueType\": \"str\",\t      \"value\": \"on\"\t    }\t  ]\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":340,"wires":[["9d28417466b85a87"]]},{"id":"2fba4297.e4145e","type":"server","name":"Home Assistant BasAdmin","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like