# Home Security Alarm

**URL:** https://discourse.nodered.org/t/home-security-alarm/7936
**Category:** General
**Created:** [13 February 2019 15:23 UTC](https://discourse.nodered.org/t/home-security-alarm/7936 "2019-02-13T15:23:02Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![ZenoVD](https://avatars.discourse-cdn.com/v4/letter/z/41988e/32.png) [@ZenoVD](https://discourse.nodered.org/u/ZenoVD)
#### Post date: [13 February 2019 15:23 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/1 "2019-02-13T15:23:02Z")

</div>

Hello, I am trying to make a home security alarm but I am new to Node-Red.

When the PIR has detected something i want it to send me a text on my mobile phone and a small led and siren should jump on when movement is detected.

Now I am stuck at the part where i want the siren and led to jump on untill I turn it back off.

Can someone please help me figure this out?  
Kind regards, Zeno

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [13 February 2019 15:24 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/2 "2019-02-13T15:24:39Z")

</div>

First you need to decide on a hardware platform.

---

<div class="post-metadata">

### Author: ![ZenoVD](https://avatars.discourse-cdn.com/v4/letter/z/41988e/32.png) [@ZenoVD](https://discourse.nodered.org/u/ZenoVD)
#### Post date: [13 February 2019 15:26 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/3 "2019-02-13T15:26:10Z")

</div>

I am currently using the Raspberry Pi 3 B+

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [13 February 2019 15:27 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/4 "2019-02-13T15:27:54Z")

</div>

And do you plan to use that to provide the hardware platform for the light and sounder?

If so, you should search for people who have already added such things to Node-RED. There are examples around.

---

<div class="post-metadata">

### Author: ![ZenoVD](https://avatars.discourse-cdn.com/v4/letter/z/41988e/32.png) [@ZenoVD](https://discourse.nodered.org/u/ZenoVD)
#### Post date: [13 February 2019 15:32 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/5 "2019-02-13T15:32:01Z")

</div>

Well, i have looked around a bit but i didnt really find anything.  
At the moment my program is working fine, when the PIR detects something, the siren makes sound and the led gives light. But that is only for a short amount of time (± 2 seconds) is it possible to keep it on untill i turn it back off on the dashboard?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [13 February 2019 15:48 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/6 "2019-02-13T15:48:40Z")

</div>

You've not told us what siren you are using or what your flow looks like.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [13 February 2019 16:18 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/7 "2019-02-13T16:18:02Z")

</div>

Put a Switch node in before the dashboard items so that your existing message can only switch the led and siren on not off. Only send On messages (whatever they are) to o/p 1 and ignore any others. Then from your acknowledge button feed the Off message to the led and siren.  
The result is that the PIR can only switch them on, and your button will switch them off.

---

<div class="post-metadata">

### Author: ![aihysp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aihysp/32/2278_2.png) [@aihysp](https://discourse.nodered.org/u/aihysp)
#### Post date: [13 February 2019 18:39 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/8 "2019-02-13T18:39:56Z")

</div>

i also was looking for somthing like this , i ended up twiking my flow and used the below Node  
it really helped me ,

i am doing somthing real simple

1. MP3 File on my PC (used for sirene)
2. and all PIRs go to counter
3. if the counter is more than two in less than 10 secs  
i get a notification on my phone and also the siren will go on very load, connected to desktop studio monitors

i have doors, windows ,PIRs, there is no chance to move around the house without making it go on twice...

> **[node-red-contrib-timed-counter](https://flows.nodered.org/node/node-red-contrib-timed-counter)**
>
> A Node-RED node that counts messages received in a specified time limit

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [14 February 2019 10:17 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/9 "2019-02-14T10:17:14Z")

</div>

You might want to take a look at this project I created for my IoT students.  
I reckon you could modify it to match your needs.  
It uses a Wemos D1 Mini to handle the IR side of things and then send an MQTT message to RPi-3+ running Node-RED.  
I've used Telegram to send messages to my mobile phone as the implementation is very easy.

Cheers from David.

> [@IR Detector - the project that grew and grew](https://discourse.nodered.org/t/ir-detector-the-project-that-grew-and-grew/4738):
>
> [The project that 'grew and grew'.](http://resources-area.co.uk/node-red-flows/it_grew_and_grew.pdf) Here's a link to an instruction sheet, for my IoT students, on how to interface an InfraRed (IR) detector to a WeMos D1 Mini.. Note: This exercise uses a WeMos D1 Mini, Node-RED and MQTT (mosquitto) and of course an IR detector. The project grew into using a RPi-camera to FTP images to a server and a dashboard to display those images. I hope you enjoy reading this as much as I enjoyed writing it. Regards from David.

---

<div class="post-metadata">

### Author: ![ZenoVD](https://avatars.discourse-cdn.com/v4/letter/z/41988e/32.png) [@ZenoVD](https://discourse.nodered.org/u/ZenoVD)
#### Post date: [14 February 2019 10:34 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/10 "2019-02-14T10:34:18Z")

</div>

This is excactly what i need, could you get a little more specific into the programming in node-red?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [14 February 2019 11:37 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/11 "2019-02-14T11:37:05Z")

</div>

I suppose I'd better say this as nobody else has.

It is easy to get carried away with things like this as Node-RED, Pi's, ESP's, etc make everything so easy to do. I certainly happily get carried away.

However, there is a big difference between doing something for the fun of it and relying on something for security.

A home-grown security "thing" will be a step up for most people who probably have nothing to start with. However, you wouldn't want to rely on this if you were a high-profile target or trying to protect a business.

I have things like this set up at home but I don't _rely_ on it for security.

Anyway, I'm sure you know all these things so I'll shut up now.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [14 February 2019 14:29 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/12 "2019-02-14T14:29:36Z")

</div>

Hi Julian - totally agree with all your comments.

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [16 February 2019 16:58 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/13 "2019-02-16T16:58:40Z")

</div>

Sorry about the delay in responding - I've been very busy this week.  
Here's a cut-down version of the NR flow for the IR security system.

 ![ScreenShot026](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/11b3098c85dc81d71b60c54fa5e634fe0e50432c.png)

```auto
[{"id":"121e7a1e.9edc66","type":"mqtt in","z":"d604a211.103938","name":"","topic":"node41/reading/ir/level/#","qos":"2","datatype":"auto","broker":"a86115be.40797","x":230,"y":340,"wires":[["3cb3209c.2c5588","99766cf1.371078"]]},{"id":"28bc587e.eaea28","type":"rising-edge","z":"d604a211.103938","name":"","threshold":"0","x":650,"y":340,"wires":[["2631a893.1d397"]]},{"id":"2631a893.1d397","type":"function","z":"d604a211.103938","name":"","func":"msg.payload=\"IR detected in rear garden\";\nreturn msg;","outputs":1,"noerr":0,"x":810,"y":340,"wires":[["3aed7900.dd064e"]]},{"id":"3cb3209c.2c5588","type":"function","z":"d604a211.103938","name":"","func":"if (msg.payload == \"1\")\n {\n msg.payload = 1;\n }\nelse if (msg.payload == \"0\")\n {\n msg.payload = 0;\n }\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":340,"wires":[["28bc587e.eaea28"]]},{"id":"99766cf1.371078","type":"debug","z":"d604a211.103938","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":490,"y":400,"wires":[]},{"id":"7be32425.13144c","type":"inject","z":"d604a211.103938","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":240,"wires":[["3cb3209c.2c5588"]]},{"id":"6ae036c5.ae339","type":"inject","z":"d604a211.103938","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":280,"wires":[["3cb3209c.2c5588"]]},{"id":"fdaccb35.7a9a48","type":"inject","z":"d604a211.103938","name":"Test IR unit remotely","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":160,"wires":[["e103eaa7.5b52b"]]},{"id":"78e3cdd4.4c3fcc","type":"mqtt out","z":"d604a211.103938","name":"","topic":"node41/cmd","qos":"","retain":"","broker":"a86115be.40797","x":570,"y":160,"wires":[]},{"id":"e103eaa7.5b52b","type":"function","z":"d604a211.103938","name":"","func":"msg.payload = \"event,IRon\";\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":160,"wires":[["78e3cdd4.4c3fcc"]]},{"id":"3aed7900.dd064e","type":"telegrambot-notify","z":"d604a211.103938","name":"","bot":"","chatId":"","message":"","parseMode":"","x":980,"y":340,"wires":[]},{"id":"a86115be.40797","type":"mqtt-broker","z":"","name":"Use this one 192.168.1.142","broker":"192.168.1.142","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

I used a Wemos D1 Mini to handle the IR detector - wired it up as a switch.

 ![ScreenShot027](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bb45be52096b0c21d4b0ec13f5554cc80a8271fb.png)  
I also used a set of "Rules" (in the Wemos) to remotely trigger GPIO-13 to remotely test the IR detector was working.

```auto
On IRon do
  gpio,13,1 //Set input 0 High
  timerSet,1,1 //timer 1 set for 1 sec
endon
 
On IRoff do 
  timerSet,1,0 //timer 1 set to halt,
  gpio,13,0 //Set input 0 low (normal state)
endon
 
On Rules#Timer=1 do  
  gpio,13,0 //Set input 0 low (normal state)
endon

```

Hope you find the above files/screenshots useful.  
Regards from David.

PS:  
I should add that I arrange for all my nodes to post their data in the format:

`<node_number>/reading/<device_name>/<value>`

You might need to alter the topic in the MQTT-In and MQTT-Out nodes to match the format you use.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [29 March 2023 00:07 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/14 "2023-03-29T00:07:46Z")

</div>

2 posts were split to a new topic: [Security system not working](https://discourse.nodered.org/t/security-system-not-working/77033)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [29 March 2023 00:09 UTC](https://discourse.nodered.org/t/home-security-alarm/7936/15 "2023-03-29T00:09:16Z")

</div>


