HELP : How to Mimic HA Zone Triggers in Node-Red

I use HA as my state machine and currently let it handle zones because circles work fine for me. Also, note that not everything needs to be in node-RED. Things that are easier in HA I keep in HA.

Using the HA zones, what you have in YAML is really easy to re-create.

Start with an event:state node, and set the entity_id to “device_tracker” and you’ll get all device_tracker entities (the filtering is a simple substring match), or you can just have multiple event nodes so you don’t accidentally pick up device_tracker.D.

Feed everything into a switch node and use the “expression” option for the property and check to see if the state changed. This is because some device trackers will report a new state even though the old state is the same. (my gps logger does)
image

Then feed everything into a switch and switch based on msg.payload. Then that should be fed into either a template for creating the message or into another switch the switch on device_tracker.id.

It might look something like this…


If I was going to use the geofence node, I would probably feed the results of that into a sensor hosted by HA, and then in the flow above instead of monitoring the device trackers, monitor the new sensors.

5 Likes