Finding out area (EDIT: area_name) of an entity that is part of a device

I’m trying to create a Node-RED chain as follows:

  • Any of my PIR sensors triggers
  • Check if I’m home
  • Update a helper Internal_location_from to a (previous) value from Internal_location_to
  • Update a helper Internal_location_to to the PIR location

I could and can create separate flows for each PIR but I’m trying to figure out the last step, how could I

  1. Extract PIR sensor value for Area from the parent PIR device (that has Area configured)
  2. Create custom message that would transfer the Area information from PIR trigger to the last step so that I could use the Area value for the Internal_location_to helper

Maybe you should move your question to the Node-Red category :+1:

1 Like

Very true, sorry

You can get the area using the render template node.

[{"id":"ed2d2688ab62076f","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"binary_sensor.xvr_front_garden_motion_alarm","payloadType":"str","x":770,"y":640,"wires":[["4ccf35029a7fb7c5"]]},{"id":"0130417f024d8c56","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1330,"y":640,"wires":[]},{"id":"df4c134f93651038","type":"api-render-template","z":"f80b6c338afd5483","name":"","server":"","version":0,"template":"","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1120,"y":640,"wires":[["0130417f024d8c56"]]},{"id":"4ccf35029a7fb7c5","type":"change","z":"f80b6c338afd5483","name":"","rules":[{"t":"set","p":"template","pt":"msg","to":"{\"area_id\":\"{{area_id('xxxxx')}}\"}","tot":"str"},{"t":"change","p":"template","pt":"msg","from":"xxxxx","fromt":"str","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":640,"wires":[["df4c134f93651038"]]}]
1 Like

Now that I played with the example above from @Mikefila I understood that I in fact don’t want the area_id but the area friendly name. The syntax for change node for that seems to be

{“area_name”:“{{area_name(‘xxxxx’)}}”}

This is my final flow

  1. PIR activation
  2. Check if I’m home
    Lower:
  3. Set helper Internal_location_from value to previous location based on Internal_location_to helper (area_name value)
  4. Clear payload to empty string (in order for the join node to work later)
    Upper:
  5. Fetch PIR area_name value via a template to msg.payload
  6. Wait via join node for step 3. to finish, combine payloads (empty string from step 3., area_name from step 5.
  7. set helper Internal_location_to based on msg.payload (area_name value)


[{"id":"a85985f846d9d157","type":"trigger-state","z":"129d4fa1e55fa789","name":"Hall PIR trigger","server":"5e7872b3.6ff53c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.nedis_pir_1_ias_zone","entityidfiltertype":"regex","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"inputs":0,"outputs":3,"customoutputs":[{"messageType":"payload","messageValue":"binary_sensor.nedis_pir_1_ias_zone","messageValueType":"str","comparatorPropertyType":"current_state","comparatorType":"is","comparatorValue":"on","comparatorValueDataType":"str","comparatorPropertyValue":"new_state.state"}],"outputinitially":false,"state_type":"str","enableInput":false,"x":100,"y":260,"wires":[[],[],["69887185cbb30919"]]},{"id":"93b47293430a75fd","type":"trigger-state","z":"129d4fa1e55fa789","name":"Bedroom PIR trigger","server":"5e7872b3.6ff53c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.neo_pir_1_home_security_motion_detection","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"inputs":0,"outputs":3,"customoutputs":[{"messageType":"payload","messageValue":"binary_sensor.neo_pir_1_home_security_motion_detection","messageValueType":"str","comparatorPropertyType":"current_state","comparatorType":"is","comparatorValue":"on","comparatorValueDataType":"str","comparatorPropertyValue":"new_state.state"}],"outputinitially":false,"state_type":"str","enableInput":false,"x":110,"y":340,"wires":[[],[],["69887185cbb30919"]]},{"id":"44a5046256155d8f","type":"trigger-state","z":"129d4fa1e55fa789","name":"Kitchen PIR trigger","server":"5e7872b3.6ff53c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.ikea_tradfri_pir_1_on_off","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"inputs":0,"outputs":3,"customoutputs":[{"messageType":"payload","messageValue":"binary_sensor.ikea_tradfri_pir_1_on_off","messageValueType":"str","comparatorPropertyType":"current_state","comparatorType":"is","comparatorValue":"on","comparatorValueDataType":"str","comparatorPropertyValue":"new_state.state"}],"outputinitially":false,"state_type":"str","enableInput":false,"x":110,"y":420,"wires":[[],[],["69887185cbb30919"]]},{"id":"6dbee0822f61a83b","type":"api-current-state","z":"129d4fa1e55fa789","name":"Read current Internal_location_to","server":"5e7872b3.6ff53c","version":3,"outputs":2,"halt_if":"NULL","halt_if_type":"str","halt_if_compare":"is_not","entity_id":"input_select.internal_location_to","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload.area_name","propertyType":"msg","value":"\"\"","valueType":"str"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":620,"y":460,"wires":[["a35caf96ad8668f7","af6a735ee93e89ae"],[]]},{"id":"26d79edf5e343eb1","type":"api-render-template","z":"129d4fa1e55fa789","name":"Set PIR area_name as payload","server":"5e7872b3.6ff53c","version":0,"template":"","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":910,"y":280,"wires":[["57294dc344eb5f22"]]},{"id":"58544058f08ca626","type":"change","z":"129d4fa1e55fa789","name":"Find PIR area_name","rules":[{"t":"set","p":"template","pt":"msg","to":"\"{{area_name('xxxxx')}}\"","tot":"str"},{"t":"change","p":"template","pt":"msg","from":"xxxxx","fromt":"str","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":280,"wires":[["26d79edf5e343eb1"]]},{"id":"69887185cbb30919","type":"api-current-state","z":"129d4fa1e55fa789","name":"At home?","server":"5e7872b3.6ff53c","version":3,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","entity_id":"person.petri","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":340,"y":320,"wires":[["6dbee0822f61a83b","58544058f08ca626"],[]]},{"id":"57294dc344eb5f22","type":"join","z":"129d4fa1e55fa789","name":"Join as strings","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"payload","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1180,"y":280,"wires":[["db617707c776be86"]]},{"id":"db617707c776be86","type":"api-call-service","z":"129d4fa1e55fa789","name":"Set new Internal_location_to","server":"5e7872b3.6ff53c","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.internal_location_to","data":"{\"option\":\"{{payload}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":280,"wires":[[]]},{"id":"a35caf96ad8668f7","type":"api-call-service","z":"129d4fa1e55fa789","name":"Set Internal_location_from","server":"5e7872b3.6ff53c","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.internal_location_from","data":"{\"option\":\"{{payload}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1410,"y":460,"wires":[[]]},{"id":"af6a735ee93e89ae","type":"change","z":"129d4fa1e55fa789","name":"Clear msg.payload to empty string","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":380,"wires":[["57294dc344eb5f22"]]},{"id":"5e7872b3.6ff53c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]