Author Topic: Front Door Sensor via MQTT  (Read 597 times)

Nick_W

  • Full Member
  • ***
  • Posts: 212
    • View Profile
Front Door Sensor via MQTT
« on: November 04, 2016, 03:56:12 pm »
I know, this sounds like the project shown in the example video - door open/close sensor, well it is, but on steroids!

This project addresses several needs. As you may find, any home automation system needs a good way to detect the status of doors/windows, especially the front door. This is needed for:

  • Security (obvious I guess)
  • Automation of door locking
  • Turning Lights on/off

Plus many more. The problem I found is that if you want wireless sensors (and who doesn't), there are really only two choices, Zwave and Insteon. Most of these consist of large ugly boxes, with magnets. Fortunately, you can get hidden sensors as well (some very weird ones - check this out http://darwinsden.com/strips-zwave-door-window-sensor-review/).

This is the best Zwave one I have found: http://aeotec.com/hidden-z-wave-door-sensor, and this is the best insteon one I have found: http://www.insteon.com/hidden-door-sensor/

The problem with all these sensors is that they only report when the status of the door changes (to save battery). You can't get an absolute value from them, just a change. The battery reporting is a bit digital as well - ie 100%, 100%, 100% - nothing. So when your door sensor battery dies, you have no idea what the door status is (especially if you are on the road as I tend to be), and that messes up all your other dependent routines (door locking/unlocking for example).

So my solution to date has been to have two sensors, the main Zwave one (which is ultra reliable until the battery dies), and a backup one (insteon) which is not as reliable - you would not believe how fast the front door opens and closes when my kids come and go, and the insteon sometimes misses a transition. The missed transition can be an issue, as now you have one sensor saying the door is closed, and one saying it is open. I believe the Zwave (reliable) one, but when the battery dies, I have to switch to the unreliable one. Not the best situation for the front door (especially when I use this to auto-lock the door with a yale zwave lock). I need a third sensor, that meets the following criteria:

  • Small (no large boxes!)
  • long battery life
  • reliable
  • can report status, not just events
  • Not Zwave or Insteon

Solution:
mcModule 110! Bonus, with the accelerometer, you can also detect people knocking at the front door (I have a door bell, but lots of people are baffled by it - it's an August smart door bell). They knock on the door, and say "I couldn't find the door bell" - I say "it's the thing with the button with a picture of a bell on it next to the door".

NOTE: the code for this is written for the 110 module, it will not work for the 120 until the accelerometer library for the 120 module is working. You could use it without the door knock feature though.

The module is used as is, no wiring or anything. I attached it with velcro to the top left of the door. The module goes on the door, and a small magnet attaches to the frame (see the pictures).

The module reports battery, door status (open/closed), temperature (why not), and uptime every 30 seconds in turn. It also reports a double tap on the door as a door knock, with some lock out timing to prevent door opening/closing etc from setting off the knock sensor.

As usual (for me) this reports through my openhab set up, and pushes alerts to my phone when a door knock is detected.

With this added to the door, I now have an absolute method of telling if the door is open or closed, and with three sensors (using different technologies for redundancy), I can use 2 out of 3 voting to decide what is the actual door status, and best guess if one sensor has a dead battery.

We will see what the battery life is like.

code is here: https://github.com/NickWaterton/mcScript/tree/master/projects/DoorSensor

This is what the output of my front door log looks like:

Code: [Select]
2016-11-04 15:25:15.758 [INFO ] - Front Door OPEN (ZWave Sensor)
2016-11-04 15:25:15.849 [INFO ] - Front Door OPENED - Master Sensor: Zwave
2016-11-04 15:25:16.116 [INFO ] - Front Door OPEN (Insteon Sensor)
2016-11-04 15:25:16.220 [DEBUG] - Setting Front Door Indicator (153) to hallway_HSM200_setcolour Mode: 8
2016-11-04 15:25:16.435 [DEBUG] - HSM200 Indicator Changed to value: 8 (Yellow)
2016-11-04 15:25:16.671 [DEBUG] - Setting Front Door Indicator (153) Mode to: Fast BLUE (door open)
2016-11-04 15:25:16.818 [INFO ] - Front Door OPEN (mcThings Sensor)
2016-11-04 15:25:24.377 [INFO ] - Front Door CLOSED (ZWave Sensor)
2016-11-04 15:25:24.414 [INFO ] - Front Door CLOSED - Master Sensor: Zwave
2016-11-04 15:25:24.415 [DEBUG] - Setting Front Door Indicator (153) to hallway_HSM200_setcolour Mode: 5
2016-11-04 15:25:24.417 [DEBUG] - HSM200 Indicator Changed to value: 5 (Blue)
2016-11-04 15:25:24.418 [INFO ] - AutoRelock: autolock timer (FrontDoor) reset by: Door Close Auto Lock for 5 more minutes
2016-11-04 15:25:24.420 [DEBUG] - Setting Front Door Indicator (153) Mode to: Tail Yellow (lock pending)
2016-11-04 15:25:24.700 [INFO ] - Front Door CLOSED (Insteon Sensor)
2016-11-04 15:25:24.968 [INFO ] - Front Door CLOSED (mcThings Sensor)
2016-11-04 15:30:24.423 [INFO ] - AutoRelock: Front Door Locked by: Door Close Auto Lock
2016-11-04 15:30:24.427 [INFO ] - Front Door LOCK command received
2016-11-04 15:30:24.432 [DEBUG] - Setting Front Door Indicator (153) Mode to: Tail RED (locking)
2016-11-04 15:30:33.380 [DEBUG] - Front Door Lock Status updated to: CLOSED
2016-11-04 15:30:33.380 [INFO ] - Delay between Front Door Lock receiving command and CONFIRMED response: 8.958s
2016-11-04 15:30:33.418 [INFO ] - Door Lock confirmed recipt of Lock command
2016-11-04 15:30:33.418 [DEBUG] - Setting Front Door Indicator (153) to hallway_HSM200_setcolour Mode: 4
2016-11-04 15:30:33.420 [DEBUG] - HSM200 Indicator Changed to value: 4 (Green)
2016-11-04 15:30:33.424 [DEBUG] - Setting Front Door Indicator (153) Mode to: Slow RED (locked)
2016-11-04 15:30:33.917 [INFO ] - Front Door is CONFIRMED LOCKED
2016-11-04 15:30:53.308 [INFO ] - Door Lock Battery level: 66%
2016-11-04 15:30:53.368 [INFO ] - Front Door command status: SUCCESS
2016-11-04 15:32:23.915 [INFO ] - Door Knock Detected at: 2016-11-04 15:32:23

All I need now is a nice white box to put the module in - hint hint...
« Last Edit: November 04, 2016, 04:04:58 pm by Nick_W »

Social Buttons


kristofferis

  • Sr. Member
  • ****
  • Posts: 285
  • Location: Sweden
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #1 on: November 04, 2016, 04:00:13 pm »
Good Work.
I have to test this on my doors :)

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #2 on: November 07, 2016, 09:14:19 am »
Cool. Where did you get your magnet?

Nick_W

  • Full Member
  • ***
  • Posts: 212
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #3 on: November 07, 2016, 09:28:20 am »
It's a Flair Pill Style Surface Mount magnet (rare earth, 0.75" range, self adhesive). P/N VIP120-2C $2.79 (CDN) from aartech (www.aartech.ca).

I'm still dealing with some random reboot in the software currently. Not sure what is causing them, and the "randomly stops publishing" problem is a pain. Waiting for an update from mcThings to hopefully address this. Just FYI.

The software on github is being updated daily, so check often!, and if you have any improvements, please let me know.

mr_mcthing

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #4 on: January 09, 2017, 09:19:46 am »
Hi,

Nice project. This is something I had in mind when getting the modules. I now only have some of the modules prepared for (outside) temperature reporting. Which is published to my mqtt broker running on a NAS.
Having a look at the device on the photo, attached to the door I do not see anything soldered to it? So only having one magnet makes this work? Or is the other part hidden behind the module?
Would be great if you could share some more details. So, the not so technical ones around here, can try to create this as well :)

Thanks

Nick_W

  • Full Member
  • ***
  • Posts: 212
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #5 on: January 09, 2017, 09:31:51 am »
No other parts required, works with just the one magnet.

I am working on an updated version right now, as the new firmware is much more stable (but still has publishing issues). The new version will publish json strings so that I can get timestamps and so on.

Check github in a few days...

mr_mcthing

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #6 on: January 09, 2017, 09:36:29 am »
Thanks for the reply. Give it a try.

mc-T2

  • Administrator
  • Full Member
  • *****
  • Posts: 239
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #7 on: January 09, 2017, 11:35:30 am »
Just to add to the conversation,
mr_mcthing - the module has a reed switch/magnetic switch built-in to the module already! This is how you can use a magnet to change the field and then the module can report an open or close.
Nick has done a great job with his setup -Thanks Nick!

We also put together a video using the magnetic switch on our production room door and then relaying that information to an Android phone app using MQTT. It's not as fancy as Nick's - doesnt include a door knocking option.

You can check it out here:
https://youtu.be/WfkQmg5P-3k
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

Nick_W

  • Full Member
  • ***
  • Posts: 212
    • View Profile
Re: Front Door Sensor via MQTT
« Reply #8 on: May 03, 2017, 11:39:47 pm »
Here is the module with the new nice white case (just as I requested)!

Latest code is on my github, with 110 and 120 module code. I'm still using my old 110 module, one day I'll upgrade it to a 120 module, but the 110 works fine.
Like Like x 1 View List