Controlling LightwaveRF and Nest Thermostat with Siri

LightwaveRF and Nest are currently not supported by Apples HomeKit and could be awhile until this happens. The wait is now over thanks to the HAP NodeJS bridge.

What is the HAP NodeJS Bridge?

The HAP NodeJS Bridge (by Khaos Tian) is basically a way to instantly enable any smart or connected home automation product to be used with Apple Homekit.

The HAP Bridge acts like a Homekit bridge and gives a platform to define each of your devices as an accessory.

homescreenOnce you have the server running you will need a Homekit enabled app installed on your phone.  If you have a Apple Developer licence you can click here for a demo as a start or you can download one of many new Homekit enabled apps from the AppStore (e.g. Eve).

After you’ve installed and configured the app, you can start using Siri to control your home. Commands include:

  • Siri, turn on the living room lights
  • Siri, set the temperature to 20 degrees

If your phone is plugged in for charging you don’t even need to touch your phone to control your devices, just say your command after “Hey Siri!”

How do you install and configure the HAP NodeJS Bridge?

The perquisite to installing the HAP bridge is that the systems needs to have NodeJS (atleast verision 0.12).  The installation and launch details of the HAP Bridge can be found here: https://github.com/KhaosT/HAP-NodeJS and can be installed using the git clone command:

git clone https://github.com/KhaosT/HAP-NodeJS

The app configuration

Now that the server is running, let’s move on to the app. The demo app mentioned above is fairly simple to use. To link the app to the bridge simply click on add accessory and the bridge should be listed. Select the listed bridge and it will prompt for the code, the code can be found in the Bridge_Info.js (default is 031-45-154) file in the accessories folder. When that’s successful you will see the demo accessories.

You can now actually test Siri using the demo accessories!

Configuring the accessories 

Nearly any smart/home automation accessory can be configured to work with this Homekit bridge. All you need to do is define an accessory file for each device.  The accessory file defines the accessory and includes the actions possible, they are defined using object literal notification.

As I use Domoticz as my home automation platform, I’ve configured accessories based on that. I could have written a script that automatically grabs the devices from Domoticz and creates an accessory for each one, but I didn’t want to pollute my Homekit bridge with accessories which I won’t be controlling with Siri.

As most of my accessories will have common commands (e.g. Light on/off), I’ve created a shared class which will contain common actions.

Below is a snippet of the for Domoticz helper class (full class is here)

exports.switchAction = function (idx, action){
   var post_options = 
   {
     host: '192.168.0.7',
     port: '8089',
     path: '/json.htm?type=command&param=switchlight&idx='+idx+'&switchcmd='+action,
     method: 'GET',
     headers: 
     {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': post_data.length
     }
   };
   post(post_options);
}

exports.switchBrightness = function (idx, level){
 //32 = 100%
 var dimlevel = level / 3.125;
 var post_options = 
 {
    host: '192.168.0.7',
    port: '8089',
    path: '/json.htm?type=command&param=switchlight&idx='+idx+'&switchcmd=Set%20Level&level='+dimlevel,
    method: 'GET',
    headers: 
    {
     'Content-Type': 'application/x-www-form-urlencoded',
     'Content-Length': post_data.length
    }
  };
  post(post_options);
}

Once the helper class was created, I then create accessories for each of the devices I wanted to control.  Click here for an example of the accessory definition.  As Domoticz now supports Nest, I’ve also created a accessory for my Nest thermostat, which enables me to use Siri to change the temperature.

Home Kit App

Once all the accessories (e.g. LightwaveRF swtiches and Nest etc..) are defined, if they will appear in the HomeKit app.

The accessories then can be assigned to Rooms, Zones and Trigger and Actions be created.  By doing this you can tell Siri to turn on lights for particular rooms or zones.

Keeping the service running

To ensure that the HomeKit server is running all the time, I used a tool called Forever.  Forever is a simple CLI tool for ensuring that a given script runs continuously.

Forever can be used using the following command:

forever start BridgedCore.js

Now you’re ready to use Siri to control your smart home…

Enjoy…

Advertisement

The Initial Setup

There are a number of ways to control your home. You could use the LightwaveRF WIFI unit or go down the custom route.

I decided to go down the custom route.  This post will describe my setup.

What’s in your setup?

Currently my setup consists of two hardware components (apart from the light switches and sensors); a Raspberry Pi and the RFXCOM RFXtrx433.

As I went down the custom route I needed a computer which would be left on 24/7 as it will IMG_1752be the “brains” of the smart home. For this I opted to use the Raspberry Pi (B+ model).  The reason behind this decision is that the Pi is small, doesn’t use a lot of power and very quite as no fans are needed.  Another reason for opting for the Pi is that they have GPIO pins which give the flexibility to connect components directly to the Pi.  For example to integrate with my house alarm system.

My Raspberry Pi is used for two purposes; one for XBMC (Raspbmc/Kodi) and the other for home automation.  To date I’ve not experienced any performance issues, the future plan is to have one Pi dedicated for home automation and the other for XBMC.

And of course my setup consists of LightwaveRF switches, LightwaveRF relays, HomeEasy PIR and a Byron Doorbell.  I’ve also got a setup to interface with my existing house alarm. I will post about that particular setup at later stage.

How’s it all connected?

The setup between the Raspberry Pi and the RFXtrx433 is pretty much plug and play.  The lighting components are linked to the Raspberry Pi wirelessly via the  RFXtrx433.

What software do you run?

After much deliberation between custom software and open source platform, I decided to go with the open source platform option and use Domoticz.

Domoticz is a open source Home Automation System, that lets you configure and bring together smartIMG_2755 devices from different manufacturers.  Main features include the ability to create custom events, automated smart timers and flexibility with custom scripts.  As the platform has a HTML5  front end, it is automatically scaled for different devices.

Setting up Domoticz on the Raspbery Pi is pretty simple. The steps can be found here http://www.domoticz.com/wiki/Installing_and_running_Domoticz_on_a_Raspberry_PI

Once you have the software running you simply access the platform through any browser (http://raspberry PI IP :8080).  From the browser you can add new components to your setup.  Its very simple to setup, for example to add a new LightwaveRF switch, you click on “Manual Light/Switch”, Select RFXtrx433 as the hardware, Type as LightwaveRF and give it an ID. Once this is done you put your switch in to learning mode.  To do this on the dimmer switches press and hold down both the ‘ON’ AND ‘OFF’ buttons until the blue and amber LEDs ash alternately. The dimmer switch is now in learning mode.  Once its in learning mode, click your light switch button in domoticz, the blue light on the dimmer will flash to confirm the pairing.

So that’s it, once you have added your switches, you can now access them from any web browser on any device.

One downside to going down the custom route is that you need to consider service up time. By this I mean you ideally want the server to start up again if it crashes. For this I used Watchdog. Watchdog is a applications that knows when your raspberry is down, and will automatically reboot it in case this happens.  This can be configured to send you emails when a crash occurs.  Click here for more information.

How do you access the platform remotely?

In order to access the platform remotely, port fowarding needs to be setup on your router.  This is a pretty straightforward task. You can use http://www.canyouseeme.org/ to test if your port forwarding works.  Once this is setup, you access the platform using your IP address and the port of the domoticz server.

Domoticz has built in security to stop unauthorised access. There are two options, the first is using a username and password and the second is done using certificates. This under the System tab in the Setup menu.

To wrap up…

So that’s it, this is my setup.  Please get in touch if you have any questions.

In future posts I’ll go in to details of the mobile apps which I’ve tried, how I’ve intergrated my house alarm (using GPIO Pins), my door bell setup, geofencing, push notifications and other tech which I’ve added to my home automation system.


 Lighting Control

As mentioned in an earlier post “The Smart Home Vision”, I’ve decided to use  the LightwaveRF system to control the house lights.

Tell me more about LightwaveRF….

LightwaveRF is a new player in the home automation market.  They provide a revolution in heating, lighting and power control. LightwaveRF’s products include  dimmers (LED compatible), radiator valves, sockets and sensors.  They look stylish and work just like ordinary switches and sockets.  

The switches and sockets come in a variety of finishes (white, black chrome, chrome, stainless steel), which will suit well in most home decor.

One of the massive advantages of the LightwaveRF system is that the products can be retrofitted in place of existing sockets and switches as they  fit on standard back boxes (I’d say a minimum 25mm  back is required) and as they are fully wireless (they use RF 433mhz) no changes to existing wiring is needed.

As part of the LightwaveRF range they have a WIFI Unit. This unit is basically what’s needed to be able to control the products from your phone internally and remotely.  There are other ways to achieve this without using the LightwaveRF WIFI unit, I will discuss the other option later.

Why did you chose LightwaveRF?

The main reason for selecting LightwaveRF was due to its ability to be retrofitted in to place of existing sockets. If I went with wired options, I would have needed to rewire the switches. 

I’m currently in the process of replacing all the current light bulbs with LED bulbs so I needed a dimmer which was LED compatible.  LightwaveRF ticked this box too. Having a young family, I needed something wife and children friendly.  I wanted something that can be operated like normal switches and which don’t depend on having a phone or a remote. LightwaveRF ticks this box too, as the switches can be used like normal switches. And they also pass the wife style test!

How do you control the switches?

I’ve managed to replace all the switches in my house with LightwaveRF dimmers, all rooms from the living room to the kitchen, from bedrooms to the bathroom, including the hallways and the porch lights.  I’ve personally gone for the white finish as it matches the decor.

To control the products I’ve gone down the custom route rather then using the LightwaveRF WIFI unit.  The reason for this is that the custom route gives more flexibility and you’re not tied down to just LightwaveRF products.

The custom route consists of a Raspberry Pi and a RFXCom RFXtrx433 and I’m using open source software called Domoticz.  Domoticz provides the protocol to be able to control many products including LightwaveRF.  This route is more technical and does require a technical mind set.  I will detail how to set this up in a future post.   If you just want standard control over the switches and just want to use LightwaveRF products then the WIFI unit if the way forward.

Installing the switches

Installing the switches was pretty straight forward, most of the places it was just removing the old one (remember to turn the power off!) and replacing it with the LIghtwaveRF dimmer.  Some of the back boxes where not deep enough.  I could have replaced the back box, but that would have meant potentially causing damage to the decor.  After intensive research frameI came across the back box spacer frame.  This goes between the switch and the back box hence increasing the depth of the back box.

The Smart Home Vision

The Background 

Since a very young age, I’ve been intrigued by gadgets and technology.  I remember years ago reading about X10 Home Automation, from then I’ve always said that when I get a house, I’ll definitely make it a Smart Home. 10 years ago I experimented with IR controlled light switches (I used Varilight), for the technology available for that time, this was a great consumer home automation product. Obviously being IR, there was always an issue with maintaining the “line of sight”, that was one of the downfalls.  With the Varilight switch there was no ability to control the lights away from home.

Fast forward to today there are now an ambundance of home automation systems. To list a few:

  • Z-Wave Home Automation
  • Fibaro Automation
  • Insteon Automation
  • LightwaveRf

I’ve decided to use LightwaveRf for the starting point of my home automation. I’ll go in to the reasons why in a future post.

So what’s the vision?

Imagine you have left the house for the day and forgot to turn your bedroom lights off? By turning your “normal” home into a smart home you could easily control you lights from any device which is connected to the internet.

The home I want to create will allow me to:

  • Control the house lights
  • Receive notifications on my phone when door bell is pressed
  • Integrate with my Alarm system
  • Create events based on motion sensors and door/window contacts
  • Setup CCTV
  • Integrate with heating system
  • Make use of geofencing
  • To detect who’s home

The above list is not set in stone and will most probably expand as my quest in creating a smart home continues.

By my home being able to sense that no one is home and so the house will turn the lights and heating off.

With the house alarm system integration, events can be triggered based on the alarm status. For example from simply being notified if the alarm is triggered to being notified if no one is home and we’ve forgot to arm the alarm.

As and when I start to look in to each of the above points I will definitely try and create a blog post.