Everyone is away and alarm is disarmed

Hi,

I'd like to have a flow that does the following:

-when "device_tracker.a" and "device_tracker.b" are both away
and:
-when alarm_control_panel.alarm_partition_1 is disarmed
then:
-notify "mobile_app_iphone_14" and say "xxxxxx - enter text here"

Because the status of both trackers may not always be the same (away/home, etc.) I think it might be necessary to run the flow at certain intervals during a 24 hour period (if there is a way around that, I am open to that, too.)

If you have a solution to this and are able to post the code, that would be great.

Thank you

Hi @Node11

  1. I have moved this out of Developing Nodes - you're not developing a node
  2. You have tagged this with home-assistant
  3. With the details provided, it seems very dependant on HA Nodes

Honestly, I would ask the HA community - few here use HA

However, you can maybe make use of the inject node to run with an interval, to kick start any checks you want to do, and respond accordingly.

1 Like

I find that the home assistant nodes want to do too many functions inside a single node, which makes it confusing.

I would keep it simple and sequential.
use 'current state' nodes, only fill in the entity id and keep everything else default. Process the output using switch nodes, if the value passes, continue.

something like

The inject node can be set to run at intervals as @marcus-j-davies pointed out.

1 Like

The simple way to do this is to use the person integration. In settings go to people. Create a person for everyone you want to track and assign their device tracker.

You have an entity that is called zone.home. This sensor will show the number of people who are home. When no one is home it's state will be zero. It's also instantly updated so there is no need to poll over and over. Place that sensor in an event state node.

image

[{"id":"f819f6c13f389062","type":"server-state-changed","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":6,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["zone.home"],"substring":[],"regex":[]},"outputInitially":true,"stateType":"str","ifState":"0","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1240,"y":240,"wires":[["556b7cabbec8a8e3"],[]]},{"id":"1456d48f8918b8e1","type":"api-call-service","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":7,"debugenabled":false,"action":"notify.mobile_app_pixel_8_pro","floorId":[],"areaId":[],"deviceId":[],"entityId":[],"labelId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":true,"domain":"notify","service":"mobile_app_pixel_8_pro","x":1830,"y":240,"wires":[[]]},{"id":"556b7cabbec8a8e3","type":"api-current-state","z":"0a325c35fc29f44e","name":"alarm_partition_1 disarmed ?","server":"6b1110b5.183a4","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1530,"y":240,"wires":[["1456d48f8918b8e1"],[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

If you rather avoid using the person integration, you can use a trigger state node. Add each entity

Below define their state by adding conditions

[{"id":"39b7071a58cb1b73","type":"trigger-state","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["device_tracker.pixel_7","device_tracker.pixel_8_pro","switch.hallway"],"substring":[],"regex":[]},"debugEnabled":false,"constraints":[{"targetType":"entity_id","targetValue":"device_tracker.pixel_7","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"away"},{"targetType":"entity_id","targetValue":"device_tracker.pixel_8_pro","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"away"},{"targetType":"entity_id","targetValue":"switch.hallway","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":1130,"y":740,"wires":[[],[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
2 Likes

Very cool, thank you, mikefila. So to test out the away status, I put one of the devices into away mode and I see this:

As soon as that device goes to away status, the # changed to 1. As soon as I put it back to home, it went to 2. So it looks like if both go away, it's 0, which then triggers the 2nd node which looks at the alarm status (I put in DISARMED for this section, not sure if that is what it needs to see.) Once it sees DISARMED, then it sends a notification?

Here's the code, does it look right? I'm not sure why it's saying it can't find "mobile_app_iphone_14"

https://pastebin.com/raw/TbEcxTva

The current state, go to devtools and look for the alarm entity. Make sure the state is actually DISARMED. Many times the state displayed on the dash is reflective of it's type but the actual state will be on/off. Also that it is in all capitals, state is case sensitive.

If the iphone is not showing up in the action drop down, first try restarting node red itself. Drag out any home assistant node set any way and deploy. Then check for the entity in the drop down.

If it is still not there, in any HA node towards the top where your home assistant server is click the pencil icon. Uncheck the cache autocomplete option. Click update/done/deploy. Then repeat the previous step restarting and deploying a new node before checking.

The alarm part is correct, as I could see it update to disarmed...I am working on the notification now. It's a new install and I haven't worked on Node-Red for several years - to say I am rusty is an understatement.

I do find the phone in the drop-down, but when I go to deploy, I get this:


It's working, thanks a bunch. I would have never figured out that 2,1, 0 status - that makes it super easy, like you said.

1 Like