Presence detection to check house alarm state using Node Red

Hi There,

Currently, I have a NodeMCU setup with presents detection software installed and configured, every time it connects to my network it runs a series of events i.e, garage door opens, alarm state is checked etc. It has been working okay for the last few months but I would like to convert this automation over into Node-Red but that’s where I get stuck.

I would like to configure an automation that utilizes the presence detection device, once connected it will kick off a series of events. An example of this could be checking the alarm state to work out if it needs to be disarmed, opening a series of roller doors or turning on the lights.

I have read a bunch of posts and tried to set something up but my lack of Node-Red knowledge is hindering my progress. I’m unable to work out how to correctly pass the information from the presence detection device to check the alarm state. I’m pretty sure I need a function node to do this but my json knowledge is very limited and not sure how to proceed

So looking to the forums for some guidance on different ways others have approached this type of automation.

Thanks, Nick

Presence Detection Node
image

I have a sensor which tells the alarm state
image

I have a binary sensor which also tells the alarm state
image

Okay I think I might have something, might not be pretty but I think it will work.

image

image

[{"id":"2d90e1ae.9b668e","type":"debug","z":"60270baa.8dc234","name":"msg2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":280,"wires":[]},{"id":"d4eb9983.99a3b8","type":"debug","z":"60270baa.8dc234","name":"msg1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":240,"wires":[]},{"id":"68928ad3.6598a4","type":"server-state-changed","z":"60270baa.8dc234","name":"PresenceDetection","server":"162e3b4c.743075","version":1,"entityidfilter":"binary_sensor.carpresencenick","entityidfiltertype":"substring","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":130,"y":240,"wires":[["45430036.9a312"]]},{"id":"4cfa9043.1adee","type":"inject","z":"60270baa.8dc234","name":"","topic":"","payload":"Armed","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":300,"wires":[["4da23151.f015f"]]},{"id":"de76e516.18a998","type":"inject","z":"60270baa.8dc234","name":"","topic":"","payload":"Disarmed","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":340,"wires":[["4da23151.f015f"]]},{"id":"4da23151.f015f","type":"api-current-state","z":"60270baa.8dc234","name":"sensor.alarm_state","server":"162e3b4c.743075","version":1,"outputs":2,"halt_if":"Disarmed","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.alarm_state","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":510,"y":240,"wires":[["d4eb9983.99a3b8"],["2d90e1ae.9b668e"]]},{"id":"45430036.9a312","type":"function","z":"60270baa.8dc234","name":"state node","func":"if (msg.payload==\"on\")\nmsg.payload=[\"Armed\"];\nif (msg.payload==\"off\")\nmsg.payload=[\"Disarmed\"];\n\nreturn msg;","outputs":2,"noerr":0,"x":310,"y":240,"wires":[["4da23151.f015f"],["4da23151.f015f"]],"outputLabels":["true","false"]},{"id":"162e3b4c.743075","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]
if (msg.payload == "on"){
  msg.payload = "Armed"
}
else if (msg.payload == "off"){
  msg.payload = "Disarmed"
}
return msg;

You don’t need 2 outputs on the node, and you don’t need to wrap your payload in an array unless you have multiple outputs, which you don’t.

Thank you flamingm0e for the suggestion. My json skills are not very stong but that makes sense. I will adjust my function node.

Thanks Nick