My wife has decided I have a phobia of light switches and think I might be a little mad for the amount of time, effort and money I have spend on automating our lights at home. This has morphed over the last year or so with different parts added over time.

The key components of the system are

Hue Lights

– recently replaced a set of remote controlled switches

PC/Server

– for those who care a HP N40L Microserver

EventGhost

– With the following plugins:

-SunTracker

-HueLights

-SerialPort

-XBMC2

-SchedulGhost

-PushBullet

-AutoRemote

-Timer

Arduino

433 Mhz Reciever/Transmitter set for the Arduino

– Originally used to send signals to the remote switches, but now used to receive signals from the remote to control the Hue Lights

433 Mhz Motion Sensor

– Bit of an experiment at the moment and used in the toilet to detect movement and switch the light on

Fire TV and Apple TV both running Kodi

– Used by the system to detect when something is playing and set the light levels appropriately

Moto X

– Running Tasker, AutoLocation and AutoRemote for geofencing

Iphone 6

– Running Pushbullet and IFTTT for a poor mans version of the above

Bonus Round

USB 56K Modem

YAC

Hue Lights

They are very cool, although I am disappointed in both the native app and the Tap device (each ‘Tap’ sets a scene, or turns a light on, but I would’ve liked the option for a second tap to turn it off again.) Maybe my light switch phobia isn’t really that deep rooted!?

PC/Server

Nothing special other than an always on server running WHS 2011. Wish I could upgrade to Windows 2012, but as this machine is pretty important to a peaceful home life, I’m not touching it!

I have used EventGhost for many years, originally as a way of using a crappy media remote to control my XBMC machine. I’ll try and break this down into components.

Eventghost has some deep ties with Python (yay!) and basically produces a list of events of things that occur on the system as they happen. System Idle, Screensaver on etc. But can also take plugins which can generate events (or do certain things based on an event triggering). I won’t go into too much detail, there are plenty of tutorials in the basics out there. I won’t go into too much detail for all the plugins, but link back to the forums which should get you up and running.

This is used to determine whether it is dark outside. I don’t want my lights on if I don’t need them on. This plugin is an absolute mindbender. I’m sure in the mind of the developer it makes sense, but I really struggle with it.

I ignore a lot of its functionality and simply have it fire an event at sunset and sunrise. I can also call the plugin from Python to determine if it is dark yet.



Hue Lights Plugin http://www.eventghost.net/forum/viewtopic.php?f=9&t=6770

Not a lot to say about this plugin, other than how great it is! Developer adds features fairly often and I have found it super easy to use!

Used, unsurprisingly to control my lights. I have discovered it also shows events for the Tap which I may utilise at some point.



SerialPort

This is a standard plugin and I use it to communicate with my Arduino. There is a section for this later.



XBMC2

Another standard plugin which I use to both control, and receive information from my Kodi boxes.

If you haven’t yet discovered PushBullet then I suggest you go out and install it on your mobile now!

Otherwise, this is a plugin which allows you to ‘push’ to your computer. This is used to receive a notification from my wife’s iPhone for geofencing purposes.

AutoRemote is part of a family of Android apps made by joaoapps. They tie neatly into the Tasker app for Android.

AutoRemote is a way of sending and receiving messages from phone to pc. This is used to control the lights using my Android, and to notifications from my Moto X for geofencing purposes.



Timer

Another built in plugin which is used for timing events. Nice and simple.



EventGhost Macros

EventGhost works on the principle of Macros. These are self contained units to perform a function.

I have loads of different macros, some of which will be useless to other people. However, I’ve attached the xml for anyone to play with here. http://pastebin.com/R4bMHvkB

A few of the key macros:



On_TV_Play

– If Kodi sends out an event that it is playing something

XBMC2.Player.OnPlay.episode – Event sent by Kodi when something is played

XBMC2.Player.OnPlay.* – Same as above, used as a catch all

SunTracker: Check if time now is inside calculated virtual range: IsItDark? – Checks if it is dark. I don’t want lights changing in the day

The rest of the actions are used to control the hue lights as you see fit. For reference I turn a main light off (over the TV), and dim two others.



Update that we are home in an evening and turn on the lights if it is dark

PushBullet.Note.Home – Event which is sent from my wifes iPhone when she gets near to the house.

AutoRemote.Message.Ho – Event which is sent from my Moto X when I get near to the house.

AutoRemote: Sending MotionOff to Note2/MotoG – Not going into this today – I have an old Note2 and MotoG set up as security webcams and this deactivates them if we are home

SunTracker: Check if time now is inside calculated virtual range: HasTheSunSet? – Checks if it is dark. I don’t want lights changing in the day.

Check if this it has ran once today – This is a python script. If the macro has ran once don’t run it again. I have copied it out below

If the macro has ran once then the global variable hasitran will equal 1, and we should stop running this macro.



if eg.globals.hasitran == 1:

eg.StopMacro() Serial Port: Write Data: O – This was used when I had remote sockets and told them to turn on Serial Port: Write Data: O – This was used when I had remote sockets and told them to turn on

Jump to “TurnLightsOnIfOff _OnDimIfPlaying,ElseFull” and return – Jumps to a bit of logic on how to handle the lights explained below

LoungeOn – another python script (below). this sends a message back to the MotoX which is handled by Tasker to change an icon on/off (so I can tell the status of the lights remotely)

Sets a global variable (eg.globals.lounge) to 1 this means that the lounge lights are on.

Then sends a message to the mobile that the lights are on



eg.globals.lounge=1

eg.plugins.AutoRemote.SendMessage(u’MotoX’, u’goo.gl/xxx’, u’xxxxx’, u’LoungeOn’, u”, u”, u”, ”, u”, u”) Serial Port: Write Data: P – This was used when I had remote sockets and told them to turn on Serial Port: Write Data: P – This was used when I had remote sockets and told them to turn on

BedOn – same as LoungeOn

itHasRan – a final python script which sets a variable to say this macro has ran once, just earlier by Check if this it has ran once today. Python Below

Sets a global variable (eg.globals.hasitran) to 1 this means that macro has been ran once.



eg.globals.hasitran=1

eg.globals.hasitran=1 TurnLightsOnIfOff _OnDimIfPlaying,ElseFull is a python script to do the following

If the lights are on then don’t do anything

If the lights are off AND something is playing, then turn them on but set to TV Playing profile

If the lights are off AND nothing is playing, then turn them on and set to TV paused profile.



player = eg.plugins.XBMC2.JSONRPC(u’Player.GetActivePlayers’, u”, True, True) player = str(player).strip(‘[]’) baseline = [{u’playerid’: 1, u’type’: u’video’}] baseline = str(baseline).strip(‘[]’) if eg.plugins.PhilipsHue.isOn(u’02 – Lounge Lamp’) == True: print “Light_On_Doing_Nothing” else: print “light_off_turn_it_on” eg.plugins.PhilipsHue.groupOn(u’00 – All lights’, u”) if player == baseline: print “Playing – lights dim” eg.TriggerEvent(“On_TV_Play”) else: print “Not Playing – lights bright”

eg.TriggerEvent(“On_TV_Pause”)

MeAway / WifeAway

These are used to switch the lights off – I also have a macro to switch them off at sunrise (we don’t always leave in the dark!) but that is pretty standard:

An message is sent from my, or my wife’s phone, when we leave the area.

This then runs the following python script.



eg.globals.meaway=1 //Sets a global variable that I am away

if eg.globals.meaway==1 and eg.globals.wifeaway==1: //Checks that I am away, and so is my Wife. If so then turn the lights off.

print (‘Both Away – Lets turn lights off’)

eg.plugins.PhilipsHue.groupOff(u’00 – All lights’, u”)



else: print (‘wife still at home’) There is then two more events which set the variable back to 0 when we each arrive home. If anyone wants any of the other macros explaining then let me know and I will add them here. Hopefully above is a good taster of the logic used.



Arduino

The Arduino and 433Mhz transceiver are quite a simple set up. A library exists for 433 communications and I have just used that –

Use the following link to hook up the components

I have attached my code here http://pastebin.com/JBHBC1d0

It has a few parts which aren’t used any more (lazy coding). But what is does is the following:

– On receiving a signal (from the remote or motion sensor) print to the serial port which button was pressed (4 rows of on/off keys) or that motion was detected.

– This is then picked up by Eventghost as an event which fires the appropriate macro.

– The opposite is true, in eventghost a macro can write back to the serial port. In this case the arduino then fires out a signal for the remote switches to action on/off.

Again I can expand on this is anyone wishes.



Moto X

I’ll do this section at a later date. Its complicated!

As an overview.

Set up Tasker, AutoLocation and AutoRemote using online tutorials. Set Tasker to send AutoRemote messages when entering and leaving an AutoLocation area around the house.



Bonus Round

Coming Soon!!!