{"id":1410,"date":"2020-06-11T19:19:44","date_gmt":"2020-06-11T18:19:44","guid":{"rendered":"http:\/\/EvertDekker.com\/?p=1410"},"modified":"2022-12-30T22:33:21","modified_gmt":"2022-12-30T21:33:21","slug":"doublelock-sensor","status":"publish","type":"post","link":"https:\/\/evertdekker.com\/wp\/?p=1410","title":{"rendered":"Doublelock Sensor"},"content":{"rendered":"<hr \/>\n<p>Sometimes you&#8217;re laying in bed and your are almost sure that the front and back door are on the doublelock, you ask your wife <em>did you check the doors<\/em> and she answers I thought you did that.<br \/>\nFrom that moment you can&#8217;t sleep because your not 100% sure you locked the doors properly with the doublelock. The only thing left is getting out of bed and go downstairs to check the locks, then they are always locked, but if you do not check if they are locked then the door is unlocked for the whole night.<\/p>\n<p>A simple led in the Node-red dashboard on my phone or a physical led in the bedroom to check if the doors are locked and you can go sleep like a princess. Because the status of the doublelock is now known in Node-red you can do everything with it.<\/p>\n<p>The mechanical part of those kind of projects is the biggest challenge. How can you measure reliable if the door is double locked. You can buy locks with a build in sensor, but then you have to adapt your door and\/or door frame and bring a thick chequebook.<br \/>\nThe lock I have is of the type (Dutch: 3 punts sluiting) 3 point closure lock, see picture. That means that the door is locked on 3 points for maximum security. The top and bottom lock hook is designed so they push the door towards the door frame for a tight closure. Those hooks will hook in a metal lock tray. When those hooks are out and making (electric) contact with the lock tray you are sure that the door is locked and on double lock.<br \/>\nSo measuring if there&#8217;s an electrical connection between the hook and metal tray will be the best and easiest way to do this.<\/p>\n<p>The idea was to use an of the shelf 433Mhz wireless door\/window burglar alarm sensor and replace the reed switch with the &#8220;hook&#8221; and &#8220;tray&#8221; contact. Important was that this sensor can detect opening and closure, not all 433Mhz will send an unique code for both events. My choice was the <a href=\"https:\/\/www.banggood.com\/GS-WDS07-Wireless-Door-Magnetic-Strip-433MHz-for-Security-Alarm-Home-System-p-1174915.html?p=X70114928512201412DS&amp;custlinkid=942854\">GS-WDS07<\/a> sensor that you can find for example on Banggood. It runs on a single AAA battery, and this battery should last for at least 3 years, see below for my findings. The last digit of the code send by the GS-WDS07 will determine what the message is.<\/p>\n<table style=\"height: 96px; width: 20%; border-collapse: collapse; border-style: inset;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">13F70A<\/td>\n<td style=\"width: 50%; height: 24px;\">Open<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">13F70E<\/td>\n<td style=\"width: 50%; height: 24px;\">Closed<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">13F707<\/td>\n<td style=\"width: 50%; height: 24px;\">Tamper<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">13F706<\/td>\n<td style=\"width: 50%; height: 24px;\">Low battery<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>As receiver for the 433Mhz signal I&#8217;m using a <a href=\"https:\/\/www.banggood.com\/SONOFF-RF-Bridge-WiFi-433-MHz-Replacement-Smart-Home-Automation-Universal-Switch-p-1179900.html?p=X70114928512201412DS&amp;custlinkid=942857\">Sonoff RF-bridge<\/a> with <a href=\"https:\/\/tasmota.github.io\/docs\/\">Tasmota<\/a> software and <a href=\"https:\/\/tasmota.github.io\/docs\/devices\/Sonoff-RF-Bridge-433\/\">Portischs<\/a> firmware for the rf chip inside. With Tasmota it&#8217;s very easy to get all the data from the sensors in Mqqt and <a href=\"https:\/\/nodered.org\/\">Node-red<\/a>.<\/p>\n<p>Installed the wiring and sensor, all works perfect. When the door is double locked the sensor led becomes green and if not locked the sensor becomes red.<br \/>\nHowever after using the sensors for 7 months, very rare the sensor stops working and you have to remove and reinsert the battery to get the sensor going again. This makes the sensor and the whole idea unreliable, you can&#8217;t trust the state of the indicator any more, bummer, still have to go downstairs to check the doors.<br \/>\nBecause the sensor only sends data when the state changes, and that can be sometimes ones in 2 days, it&#8217;s hard to determine if the sensor is alive. I need something that will give &#8220;i&#8217;m still alive&#8221; message every x time. With this message you can make something simple in Node-red that will notify me when the sensor is off line.<\/p>\n<p>After initial thought like making my own sensor with an ESP8266 or Avr with rf module, I came to the idea to use the unpopulated tamper switch of the GS-WDS07 sensor.<br \/>\nActivating the tamper switch every 15 minutes will send a code that we can use for this purpose.<br \/>\nTo get this job done a Tiny45 avr processor with some software was added to the sensor, to save energy the avr had to draw a low current as possible. The Tiny45 draws only 4\u00b5A when sleeping with the watchdog timer enabled, adding this to the 36.8\u00b5A that the sensor was using, isn&#8217;t a big issue.<br \/>\nInternally the sensor runs on 3.3V, so giving the attiny45 some power isn&#8217;t also a big problem.<br \/>\nThe tamper switch signal pin was internally pull-up to vcc, to activate the tamper signal this has to be grounded. The\u00a0 Bascom code will wake up every 15 minutes and pull the tamper switch signal to ground for 50ms and goes back to sleep after setting the pin back as input to prevent energy use.<\/p>\n<p>An AAA battery has a capacity around 1500mAH, the sensor can run 1736 days on this. However there will be now a &#8220;i&#8217;m alive&#8221; transmission every 15 minutes.\u00a0 This transmission takes 1.4Sec and consumes 24mA peak. This is around 40\u00b5AH, add this up to the 40\u00b5AH the sensor was consuming and you can still run 868 days on 1 AAA battery. That&#8217;s fine with me. I love doing low power projects with Avr.<\/p>\n<p>Developed the code in <a href=\"https:\/\/www.mcselec.com\/\">Bascom<\/a> Avr, on of my favourite compilers that I&#8217;m using now for more then 20 years.<br \/>\nMade a little test setup with a dip version of the tiny45 on a breadboard, after writing and testing the code flashed it in a smd tiny45 and soldered that in sensor.<\/p>\n<p>Job, done.<\/p>\n<p><code><\/code><\/p>\n<div class=\"n2_ss_slider_publish__option_code\" dir=\"ltr\" data-mode=\"id\"><\/div>\n<p><code><\/code><\/p>\n<p>Used Bascom code.<\/p>\n<pre class=\"brush: vb; gutter: true\">&#039;#####################################################\n&#039; Door sensor &quot;is alive&quot; hack\n&#039; EvertDekker.com 2020\n&#039; V1 20200531 Bascom 2082\n&#039; Thanks to EDC for the nice watchdog example\n&#039;#####################################################\n\n$PROG &amp;HFF,&amp;H42,&amp;HDF,&amp;HFF&#039; generated fuse bit settings. \n$regfile = &quot;attiny45.dat&quot;\n$crystal = 1000000\n$hwstack = 64\n$swstack = 16\n$framesize = 64\n\nConfig Portb = Input                                       &#039;to Reduce Power , Setup All Pins As Inputs With No Pullups\n\nAdcsra.aden = 0                                             &#039;Disable a\/d convertor\nAcsr.acd = 1                                                &#039;Disabel analog comperator\nDidr0 = &amp;H3F                                                &#039;Disable digital input buffers on all ADC0-ADC5 pins\nPrr.pradc = 1                                               &#039;Power adc disable\nPrr.prtim0 = 1                                              &#039;Power timer0 disable\nPrr.prtim1 = 1                                              &#039;Power timer1 disable\n\nConst Minutsleep =(15*60)\/8.192                            &#039;15 minutes * 60 sec \/ 8.192\n\nDim Sleep_cnt As Byte\n\nConfig Watchdog = 8192                                      &#039; ~8s&quot;\nStart Watchdog\nOn Wdt Wdt_isr Nosave\nEnable Interrupts\n\n\nDo\n\n   If Sleep_cnt = 0 Then\n      Sleep_cnt = Minutsleep                                 &#039;Set counter back to start value\n      Config Portb.3 = Output                               &#039;PortB.3 as output\n      portb.3=0                                               &#039;Pull it low to activate the tamper input\n      waitms 50\n      Config Portb.3 = input                                &#039;PortB.3 back as input to prevent energy use\n   Else\n      Decr Sleep_cnt\n   End If\n\n   Enable Wdt\n   Config Powermode = Powerdown                            &#039;Will go to sleep here\n\n  &#039;here uC will start after wake up\n\nLoop\n\nWdt_isr:\n &#039;dont enable Wdt here\nReturn<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you&#8217;re laying in bed and your are almost sure that the front and back door are on the doublelock, you ask your wife did you check the doors and she answers I thought you did that. From that moment you can&#8217;t sleep because your not 100% sure you locked the doors properly with the [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[214,26,217,216,171,215],"class_list":["post-1410","post","type-post","status-publish","format-standard","hentry","category-joshua","tag-attiny45","tag-bascom","tag-door","tag-doublelock","tag-node-red","tag-tasmota"],"_links":{"self":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1410"}],"version-history":[{"count":40,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1410\/revisions"}],"predecessor-version":[{"id":1577,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1410\/revisions\/1577"}],"wp:attachment":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}