Home Automation with Node.JS & MQTT

Shutting down my old homebrew Windows-based Home Automation system and letting the new Node.JS/MQTT based HA system take full control last Saturday was done without a glitch! Better, faster, smoother than I expected.

I had planned to start with this on Saturday morning, so that I would have ~36 hours to fix any problems that would arise, but that didn’t go as planned – some other things I had to do on that Saturday made me postpone the big switch to Saturday evening.

Around 7 o’clock in the evening I told the rest of the family that they just had to pretend that I was away, unreachable, until I would tell them that I was back again – the ‘do not disturb’ door hanger 😉

The main concern in this whole exercise was not losing any historical data. First I did a test-run of copying all the historical data from MS SQL to MySQL and checked if this still worked like it should; it did. Checked the information in the MySQL database for consistency, correctness and so forth. Great. I ran the historical-data copy again, renamed some tables in MySQL, changed some configuration settings (database names), restarted some Node services and checked if storing the historical data worked as before, but now by Node.JS, directly into the production database. This was the point where I had to decide for the go/no-go; within just a couple of minutes I knew it was a GO!

I copied a file with the new configuration settings to the Raspberry Pi’s and after that, all I had to do was restart all the services so that they would switch from the MQTT broker running on the Windows VM to the broker on the Cubietruck. Great!

About an hour later, after testing some things by walking through the house, pushing some buttons, seeing lights being switched on by detected motion and other stuff like that, I knew I would have a huge amount of free time to do a lot of other things again! 🙂

The day after went just as smooth and relaxed – no issues, just a minor thing I forgot about and which was fixed in 5 minutes… Now, Wednesday evening and 96 hours later, everything’s still 110% OK.

As of now, my Node.JS/MQTT based HA system has the following ‘features‘:

  • Smart meter

The output of the so-called P1 port of our Smart meter is being parsed by a small script which publishes the relevant information (power usage, gas usage) to the MQTT broker.

Our Roomba 563 robot vacuum cleaner is monitored and controlled with a Thinking Cleaner module which is plugged into the SCI port of the Roomba.

  • RFXCOM receiver

Two RFCOM receivers are used to collect information from various sensors (mainly Oregon Scientific temp/humidity, Visonic door/window, motion).

This is one of the drivers that’s controlling a lot of lights in our house, but is also used for things like controlling the garage door opener. I use 2 PLCBUS controllers – one in the meter cabinet, the other one is located at the other end of the house.

  • EISCP protocol

The RS-232 port on our Onkyo AV Receiver enables us to control every aspect of the device – switching HDMI inputs, volume level, on/off, mute…

  • NMA

Notify My Android is being used to send notifications to my cell phone – stuff like new LED Bar messages, and warnings about things that might need my attention.

  • Mobotix

Our Mobotix D22 security camera has a great light sensor; i use this light sensor to determine when the time has come to switch some outdoor lights (front door, back door, garden, gazebo) on or off. The http interface of the camera enables me to take snapshots.

  • LED Bar

Just a funny gadget..

  • IRTrans

The IRTrans LAN module is used to control our UPC media box and to turn on our Dune media player.

The Dune IP Control protocol enables the system to control our Dune HD Max media player.

The HA7Net provides information about in- and outgoing temperatures of our 5 floor heating groups with 1-Wire sensors and about the amount of DHW (hot water) we use (water meter with pulse + Dallas 1-Wire DS2423 counter).

  • Remeha Calenta

One of the most informative devices… even things like the fan speed can be monitored with its ‘service‘ port! More interesting of course are things like modulation level, water pressure, operating mode (central heating, DHW).

  • Alphatronics

A great receiver to receive Visonic Keyfobs and sensor RSSI information;

Primarily used for the Philips Pronto TSU9600, our single remote solution for all our AV equipment.

  • Somfy RTS

An RS-485 Somfy RTS transmitter enables us to control 12 roller shutters.

  • Rules engine

The part of the system that does the real automation: based on inputs (sensors) this engine can initiate all kinds of actions with all the hardware (actors) which is connected to the system.

  • RGB LED

A DMX based RGB LED driver controls 6 RGB LED lights under our gazebo;

This great device enables us to set the room temperature to what we want it to be, without having to walk to the room thermostat or even being at home.

  • Nemef Radaris Evolution

This RFID lock that’s on our frontdoor, controlled by a Nemef RF controller, gives detailed status information about the RFID tags being used, access control and remote access.

  • Conrad MS-35 LED driver

A couple of these are used to control warm white LED strips. I made them wireless with small TTL-to-Wifi adapters.

  • Siemens M20T GSM modem

This GSM modem is being used to send SMS messages to my cell phone, but it’s task is gradually taken over by NMA.

  • Email

Emails are primarily used to notify me about sensors that need new batteries.

  • ELV MAX!

The ELV MAX! Radiator Thermostats are used to control the temperatures in all the rooms in our house: bedrooms, bathroom, etcetera.

Why? Because I can! 😉

  • Zigbee

I have several sensors based on a combination of JeeNodes with XBee ZB modules: motion, temperature, pressure. I also use those XBees to make 3 Chromoflex LED drivers wireless by connecting an XBee to the serial port of the chromoflex – works great.

  • 16-channel LED driver for staircase lighting

Homebrew LED driver to control 13 (or is it 12?) LED strips which light the stairs. The Node driver mainly controls how an Arduino sketch should behave.

  • RFXCOM transmitter

This RF transmitter has only one purpose: controlling 2 433 MHz door bell chimes.

  • Plugwise

12 Plugwise Circles are used for monitoring power usage and to detect whether the washing machine or dryer has finished its program.

  • Chromoflex

This service calculates the payload that has to be sent to the Chromoflex LED drivers to control the LED strips. This payload is then forwarded to an XBee radio to which the Chromoflex driver is connected.

  • Btraced

Btraced is an app for iPhone/Andriod and it enables you to send your location to your own server; this service adds some additional information (by reverse geocoding) so that the location can be displayed on our touchscreen with use of Google Maps.

  • Visonic PowerMax Plus

Our security system is connected too; we’re no longer limited to using keyfobs, panel or keypad anymore for controlling this security system. And additionally, all the sensor information (open, closed, motion, battery status, tampering) is available in my system.

In use since I ditched A-10/X-10 recently. It has been on the shelf for some time after doing some small tests with it, but now it’s an excellent replacement for the small amount of X-10 stuff I was still using.

  • Doorbell

Our Ethernet-enabled doorbell communicates with a Node script to report ‘rings’ and query daylight status (used for switching a LED on & off for visibility of the button).

Quite a list, if I may say so … and it’s all running great!

My ASP.Net website still uses a MS SQL Server for its data – this database is now kept up to date by a NodeJS script, just like the MySQL database on the Cubietruck.

So, what’s next? Well, first I’m gonna take a break, that’s for sure… I’ve done enough JavaScript in the past 8 months, so it’s time for something different; I’ve also neglected some other things that really do need my attention now. And of course I’ll have to start working on the User Interface, for which I’l have to learn a lot before I can start developing.. never a dull moment!

Onwards!

Tagged , , . Bookmark the permalink.

12 Responses to Home Automation with Node.JS & MQTT

  1. Impressive list om connections to your HA system. Mine is also up and running, however with a lot less connections (p1 via ethernet, audio and light via rs232-to-ethernet).

    I do use plugwise, however they’re ‘standalone’ or can only be connected via their software.
    How did you manage to connect them to mqtt?

  2. Nick says:

    Sounds very impressive! just planning/prototyping a Node/MQTT system based on a number of Pi’s and a central server.
    I plan on using Zwave (lightswitches/wireless relays etc), LIRC (IR control on RPi’s), few networked Arduinos for RS232 control of things like a HDMI matrix and my projector.

    Think I am making it far too complicated haha, just wondering is your source is available anywhere? Curious to see how you have structured an app of this size in node!

    Thanks
    Nick

    • It may sound impressive, but it ain’t 😉 I think 80% of the code deals with communicating with the hardware i.e. just a protocol implementation. The rest is about historical data, converting values to something human readable (e.g. 0/1 can mean motion/no motion, open/closed, on/off, yes/no; 23.5 can be a temperature or a volume level, etcetera) and some utility processes – an example of that is one that provides the metadata that’s stored in a database somewhere.

      The code is not available yet, because there’s no real structure yet… 😉 It’s just a folder on my HDD with >150 files in it, of which some contain code from people who might not appreciate me publishing it without their approval. So I haven’t reached that point yet (of publishing the code). I do have plans to write some posts about how my system actually works, I think those might help you. In the meantime, you can always contact me directly with specific questions.

  3. Jason says:

    Hello,
    Neat project. I came across your blog while searching for a home automation solution using Raspberry Pi + Arduinos. Can you give me some pointers on how you did your Arduino and Pi integration?

    I have a bunch of nRF24L01 2.4GHz transceivers that the Arduino’s can use to communicate with each other. The RPi can also communicate using these transceivers. The Arduinos would act as field nodes w/ temperature sensors and relay actuators, perhaps similar to your Arduino LED device.

    But I’m missing the software platform to run on the RPi that would present all this sensor data as a web service, one that can display a webpage or on an Android app.

    Did you write your own node.js app to run on the RPi?

    • I actually don’t use a lot of Arduinos, although it might look that way. An Aruino Ethernet connected to a DMX driver, another one for bedroom lights. I’m probably forgetting one now, but the majority is JeeNode here for battery powered sensors – JeeNode with an XBee radio. An Arduino is rather big for my taste and more suitable for testing purposes. And when it’s working, I use a JeeNode to build the actual sensor. And yes, I (re)wrote my system in NodeJS myself, with the help of modules like for example serialport.

  4. Andreas says:

    Hi,

    nice 😉
    I am currently looking for a simple solution to control a Chromoflex CF RC USB-Dongle from RPi. Do you have any idea if this is easily doable? I don’t need anything else – just a way to control the dongle….

    Cheers
    Andreas

    • Hi Andreas,
      Well if I had such a device I would probably be able to tell you, but I don’t… If I would have such a device I’d just plug it into one of the USB ports of the RPi and see if it’s being recognized (and a /dev/ttyUSB0 suddenly pops up). If so, the next step is to find out what you need to send to the dongle. If protocol information is available that shouldn’t be too hard; if not, it depends on the complexity of what has to be reverse engineerded – ranging from very easy to very hard to do.

  5. Dennis van Velzen says:

    Nice setup, we just bought a house and did added some additional pipes for domotica stuff. After reading your article and all the stuff you connected I consider changing the brains of the central HA Server to Node.JS.

    Still new on your site, read some articles, maybe the information is already somewhere in the archives but hope you can share some more detailed (technical) information.

    Certainly gonna check some implementations above.

    I already planned to use DMX to control RGB + separate WW LED strips and LED downlights (4 channel constant current drivers).

    Have some questions about DMX:
    – Is it desirable to switch off the powersupplies using a relay board for example?
    – …

    As GUI I planned to used a Arduino tablet with some nice custom in wall mount with Smart-VISU (http://smartvisu.de/).

    Any suggestions to a cheap, stable, good bus system?
    Dimming normal light bulbs?

    But impressive! Will continue reading when I have some more time…

    • Hi Dennis,

      Any questions you might have, just ask! I think you’ll be capable enough to guess my email address 😉
      Regarding DMX: I do. I have a PLCBUS module that disconnects everything (DMX controller, Arduino, power adapter) from mains to save energy.
      For switching light bulbs Insteon is my favorite choice nowadays. Quiet, quick, reliable, lower energy consumption by the modules.
      Have fun reading!

      Robert

    • Bluefox says:

      Hast du auch ccu.io + DashUI gesehen?

  6. Pingback: The future’s bright, the future’s RED, Node-RED | Why? Because I Can!

Leave a Reply

Your email address will not be published. Required fields are marked *