Notify who has entered left a zone?

I have a notification set up which triggers on a change to the Home zone and lets me know if the first person comes home, or the last person to leave

image

I’d really like that notification to include the name of the person responsible (i.e the first person to arrive back (or if everyone is back together) or the first person to leave)

And… this is where I’m stumped
I’m assuming I can pull something into the Data object above, but… i’m not really sure what!
I see that the zone.home has a person array, so might be something to do with that, but again, not sure how to grab it

Anyone able to help?

First look at what is available in the HA globals.
You should have a data manager or something alike in the icons I the upper right corner.
In it there will be a section called globals and a refresh icon next to the word.
Hit the refresh icon and the HA global values should appear.
Find the homezone and see how it is setup.

I do not know if changes are updated when viewing the list or if you need to refresh it with the icon to see the changes,but play with it.

2 Likes

This will pick the friendly name of the first person listed in the array - so would only give you one person if two arrived or left simultaneously.

For the first person arriving

{
   "message": $entities(
       data.event.new_state.attributes.persons[0]
   ).attributes.friendly_name & " is home"
}

For the message triggered by last person leaving

{
   "message": $entities(
       data.event.old_state.attributes.persons[0]
   ).attributes.friendly_name & " has left the building"
}
1 Like

Thank you - will give that a try (I’m not sure anyone is leaving til tomorrow now so might be a while as the inject test leaves me with a blank name, but presumably since there is no trigger!)

For my sanity and future trouble shooting, how did you get to that?
(e.g. attributes.persons - I only see a person.[name] attributes - where did the s come from)

I see what you mean - the “Context Data” menu? That’s handy - hadn’t come across that!

I replicated what I think you’re doing in your trigger nodes and put a debug node in. I know that each trigger will put a new_state and an old_state into the message, so went there to see what I could see.

There’s an array with the person entities in the zone. So data.event.new_state.attributes.persons[0] is an entity ID. You could simply use the entity id but the person entity has a friendly_name attribute, which seems nicer.

The documentation and examples
JSONata | node-red-contrib-home-assistant-websocket (zachowj.github.io)
JSONata Examples | node-red-contrib-home-assistant-websocket (zachowj.github.io)

Contain plenty of information on how to access entity states and attributes directly from nodered JSONata. The custom functions only work in the HA nodes in nodered.

1 Like

Awesome - thank you!

And can I ask how you identified the output of the trigger without the trigger firing? This is something I keep hitting - I know how to use debug nodes and see the message, but the trigger needs to fire. I can sometimes use an inject instead but if i need to know the output (like now) I find it really difficult!

Thanks :slight_smile:

Edit - btw the triggers are very simple:

In this instance I just used the states tab in ha developer tools to manually change the state of a person entity, so it updated the state of the zone and triggered NR ‘properly’.

If I was doing something complicated that might need a lot of testing I’d do that once with debug to see what the messages should look like. Then enable the input to the trigger node and create messages in trigger nodes as per the instructions.

1 Like

Wow - learned something there- I didn’t realise I could set states manually in the developer tools!

Incredible - that’s SO useful… I even managed to work out that I had a string rather than a number (like an idiot)

I have a related but slightly different question - is it possible to use the zone but temporarily use a wider radius?

I.e. my home zone is 150m but I’d like to run a check when we pass (say) 1200m - is this possible? Or do I need to create a new zone?

Where is this menu?

image

1 Like

I’ll be damned. I never noticed the dropdown!

Me neither!

Be aware that context data menu doesn’t refresh on its own. you have to click reload icon to get current values

Regarding your flow I’m not sure how you distinguish all persons are at home (this second trigger state node from the first post).
I’m using GetEntities node for that. In switch node you can put number of members you expecting.

[{"id":"ae0f2f18.6cbb7","type":"ha-get-entities","z":"bcb4b1c6.803708","name":"How many persons in house","server":"6cdd0bc8.b8e434","version":0,"rules":[{"property":"entity_id","logic":"is","value":"person\\.*","valueType":"re"},{"property":"state","logic":"is","value":"home","valueType":"str"}],"output_type":"count","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":480,"y":220,"wires":[["affb329d.8fa8f"]]},{"id":"affb329d.8fa8f","type":"switch","z":"bcb4b1c6.803708","name":"zero or more","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"str"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":220,"wires":[["ee603327.68635","18bfb8bd.6da1c7"],["fcfa14ef.2feb28","18bfb8bd.6da1c7"]]},{"id":"d46b853a.df0c78","type":"server-state-changed","z":"bcb4b1c6.803708","name":"Some person state changed","server":"6cdd0bc8.b8e434","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"person\\.*","entityidfiltertype":"regex","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":220,"wires":[["ae0f2f18.6cbb7"]]},{"id":"6cdd0bc8.b8e434","type":"server","name":"HA MaXyM","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

The message with count should contain information about the person who triggered the event

Thanks - when you say the refresh icon where do you mean?

I’m doing it this way (well, trying to):
image

FWIW - this works for the Home zone without any manual refresh

EDIT. I’m silly - I thought I was replying to the thread over here… Using a person with passive zones does not trigger - Configuration - Home Assistant Community (home-assistant.io)