Using HA functions in NodeRed expressions

I’m trying to make an automation in NodeRed that calls turn_on on all entities in the same (Home Assistant) Area that the sensor itself that triggers it, is in.

I can’t get this working to get the Area ID, but if I hardcode the id as a string, it works.

This is the JSON expression that I have in the Data field in the “call service” node in my NodeRed flow:

{"area_id":"{{area_id('binary_sensor.office_motion_any')}}"}

The expression alone works in HA when I test it.

Use the path to the msg position, shown in the debug, to pass the variable.

{"area_id":"{{data.attributes.area_id}}"} //I'm guessing the attribute path

The attributes for the entity does not contain the area id in HA. The function area_id is to remedy that.

I see, it seems this is information is not easily obtained. The only other thing I can think of is the template node, it may be able to understand the ha template.

Yeah, and like the last comment in that thread says, you can just use the id and get the result. But an id makes the flow hard to read. I’m using it as a workaround. Thanks!

It works in a template node, gives me the area of the sensor back

[{"id":"ed2d2688ab62076f","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"44","payloadType":"num","x":750,"y":640,"wires":[["df4c134f93651038"]]},{"id":"0130417f024d8c56","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1390,"y":620,"wires":[]},{"id":"df4c134f93651038","type":"api-render-template","z":"f80b6c338afd5483","name":"","server":"","version":0,"template":"{\"area_id\":\"{{area_id('binary_sensor.xvr_front_garden_motion_alarm')}}}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1150,"y":680,"wires":[["0130417f024d8c56"]]}]