BME280 Weather Sensor

I had been eyeing a few temperature sensors on Adafruit for a while: I wanted to add a couple of sensors to get temperature and humidity. One sensor in particular would give me data that I don’t have so far: barometric pressure. This sensor is the BME280

Adafruit BME280

Adafruit BME280

I didn’t want to buy straight off Adafruit as the shipping costs were more expensive than the sensor itself (since they ship from the USA). I however found a retailer in the UK: Proto-Pic

It was pretty straight forward to add the sensor to the Raspberry Pi: 4 wires to solder on the sensor, and to the I2C / Power on the Pi.

Once connected, a quick check to confirm the I2C address of the sensor:

pi@raspberrypi $ sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77

(Note you may need to replace the 0 with a 1 depending on the version of your Raspberry Pi)

By default, the i2c address is 0x77. If you add a jumper from SDO to GND, the address will change to 0x76. See Adafruit’s tutorial for more info.

From there on, I just skipped to the last page to get the python script. Downloaded, installed, and it’s working.

One point to note is that I actually ordered a BMP280 from Proto-Pic which does not provide humidity data:

pi@raspberrypi $ sudo python Adafruit_BME280_Example.py 
Timestamp = 124328.000
Temp = 24.3 deg C
Pressure = 1000 hPa
Humidity = 0 %

 




Using 2 PIR sensors on 1 GPIO Port

I have an issue in my kitchen where the PIR, although optimally placed, is still too far to detect the small movements we make when we eat at the table.

I wanted to add another PIR close to the table, but I didn’t want to use another GPIO port on the Raspberry Pi when all I needed was another sensor for the same overall status: movement in the kitchen or not, (regardless of which sensor picks it up).

So what I’m after is a logical OR gate: if PIR1 OR PIR2 is on, then the status is on, otherwise it’s off.

The answer is actually quite simple and only requires 3 components: 2 diodes and a resistor:

OR Diode Logic Gate

OR Diode Logic Gate

  • Connect [3] to the output of PIR1
  • Connect [4] to the output of PIR2
  • Connect [1] to the GPIO port on the Raspberry Pi

Et voila! 2 PIRs for improved motion coverage, but only 1 GPIO port used 😎




Google TTS is dead. Long Live Voice RSS

Google changed once again the way their translate_TTS service works 🙁

Having trawled the interweb for an answer, having even signed up for an API key on the new Google Translate API V2, it’s just become impossible to download the text-to-speech audio files.

I have tried various free TTS options – see previous post here – and none were really “fit for purpose” as they really sounded metallic computerised voices, but I’ve just found Voice RSS.

Now Voice RSS is really nowhere as good as Google’s TTS quality, but in the grand scheme of things, it’s probably the next best thing, especially as it can be used almost as a direct replacement using wget.

You’ll have to sign up for an API key first, but provided you need less than 350 requests / day (with each request being smaller than 100kb), it’s free 🙂

The command goes as follows:

http://api.voicerss.org/?key=[your API Key]&hl-en-gb&r=1&f=48khz_16bit_stereo&src=hello+world

It’s also a bit slower than Google to return the audio files so I’ll probably review my commands to do the complete download and play them all one after the other.

 




LightwaveRF Socket Kit

Until now I was using HomeEasy HE830s Remote Controlled Sockets, but they appear to have developed a fault where they will turn themselves on randomly and get locked so become somewhat useless.

While I try and I claim warranty on them, I also need a few more sockets to help with Holiday lighting when I’m away as well as Christmas lighting automation.

So I purchased a set of LightwaveRF JSJSLW381 Remote On/Off Socket Kit to help with this:

LightwaveRF JSJSLW381 Remote On/Off Socket Kit

LightwaveRF JSJSLW381 Remote On/Off Socket Kit

Plus it gives me another remote to control my events in DomotiGa 🙂

They are easy enough to pair/connect to: simply plug them and they enter into pairing mode. Then send an ON command from the remote or DomotiGa and you’re set.

Note: I’m not planning on actually controlling the sockets with the remote but from my DomotiGa server, though I could do both if I wanted: the LightwaveRF JSJSLW381 Remote On/Off Sockets can be paired with up to 3 devices/remotes (vs 6 for other LightWaveRF devices..). Instead I will use the remote to trigger events in DomotiGa so I don’t need to access my PC or my Phone (although the latest integration with Siri is proving quite useful)




Controlling my home with Siri

With all this automation taking place, I’m getting lazier by the day. Even having to unlock my phone and open the bookmark for SmartVISU to activate a mood scene it taking too long / requiring too many actions.

Since Apple added HomeKit with its iOS 8, there’s now a way to integrate this with DomotiGa so I can control my devices with Siri! Yes voice control is finally here 😎

This is how it’s done. Note: this assumes you have DomotiGa already set up and running and know your way around Linux.

Installation

Installing on a Raspberry Pi? do this first:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libkrb5-dev

You’ll also need the Avahi package:

sudo apt-get install libavahi-compat-libdnssd-dev

Homebridge is published through NPM, if npm isn’t yet installed on your system, do this first:

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs

Then install HomeBridge “globally” by typing:

sudo npm install -g homebridge

Then install the DomotiGa plugin (Thanks Samfox2):

sudo npm install -g homebridge-domotiga

Now that HomeBridge and DomotiGa plugins are installed you need to add your own config file. Create a file called config.
NOTE: Your config.json file MUST live in your home directory inside .homebridge.
You can start by copying / pasting the below sample and update to reflect your setup:

{
"bridge": {
"name": "DomotiGa",
"username": "CC:22:3D:E3:CE:32",
"port": 51826,
"pin": "031-45-154" 
},

"description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",

"accessories": [
{
"accessory": "Domotiga",
"name": "Sensor garden",
"host": "localhost",
"port": "9090",
"service": "TempHygroMeter",
"device": "81",
"valueTemperature": "1",
"valueHumidity": "2",
"valueBattery": "4",
"lowbattery": "3000" 
},
{
"accessory": "Domotiga",
"name": "PC",
"host": "192.168.0.xxx",
"port": "9090",
"service": "Contact",
"device": "77",
"valueContact": "1",
"valueBattery": "2",
"lowbattery": "3000" 
},
{
"accessory": "Domotiga",
"name": "Printer",
"host": "192.168.0.xxx",
"port": "9090",
"service": "Switch",
"device": "79",
"valueSwitch": "1" 
} 
]
}

 

To run HomeBridge, type:

`homebridge`

You may get warning messages as per below. These can be ignored. You should however not get any error message:

Homebridge Warnings

Homebridge Warnings

iOS App

Now you need an app on your iOS device. You can use Eve By Elgato Systems
https://itunes.apple.com/gb/app/elgato-eve/id917695792

In Eve, simply add an accessory:

Eve - Add Accessory

Eve – Add Accessory

(You’ll probably be asked to create a home the first time, call it anything you want, like “Home”.)

Tap on “Identify Accessory”:

Eve - Identify Accessory

Eve – Identify Accessory

Enter the code as per your config.json file, in this example: 031-45-154

You’re set up !

Hold your home button and ask Siri all kinds of stuff. On of my favourites is “Set Mood Scene Movies on” which sets my lighting accordingly 🙂

Troubleshooting

If you cannot see your accessories (DomotiGa device), try the following steps:

  1. Stop HomeBridge
  2. Delete the “Persist” folder in your home directory inside .homebridge.
  3. Try and change the username in your config.json file (anything else)
  4. On your iOS device, go to Settings > HomeKit and delete your Home
  5. Close Eve (double press the home button and swipe Eve up)
  6. Restart HomeBridge
  7. Restart Eve

Here are a few screenshots from Elgato’s website on what Eve can do:

eve-landing-ipadiphone_2 eve-app-screen-simple eve-app-screen-fingertip_1 eve-app-screen-glance




Smart Letterbox

My letterbox is on the outside door, in the porch, behind the front door. So when the postman comes and delivers, I don’t always notice it. It also means that I will sometime open the front door just to check if post has been delivered yet.

I was wondering, how can I make my letterbox smarter so it alerts me when post has been delivered? Answer: use a sensor designed for door/window security.

I therefore purchased a Home Easy Remote Control Magnetic Switch Unit (HE305) from http://wirelesshomes.co.uk/

Home Easy HE305

Home Easy Remote Control Magnetic Switch Unit HE305

The idea behind this is that when the 2 piece are away from each other, a signal is sent and captured by my RFXTrx Transceiver so I can add rules in DomotiGa.

To achieve this I purchased a cheap letterbox from B&Q that I fitted in the internal part of the porch door, which gets lifted when post is pushed through:

Letterbox

Letterbox

Now when post is delivered, an audio announcement is played on the speakers and an email is sent. I also log each entry to keep track of delivery times, just because I can 😎

Important Note: Even though this is an Home Easy device, the AC protocol needs to be enabled in RFXCom Commander for the signal to be picked up in DomotiGa.




Smart Doorbell

I’ve now changed the “dumb” doorbell with a “smart” one; the previous doorbell was a standard push button with a wireless receiver that plugs on a socket.

Problems:

  • There was only 1 receiver
  • The receiver was not a pass-through, meaning it would occupy a socket on the wall
  • There was no way of adjusting the ringer volume

I’ve purchased a Byron SX-20T kit which resolves the above issues as there are 2 receivers in the kit and they are both pass-through so I don’t lose a socket. They also both have a rotating control button to adjust the volume (handy for the one that’s upstairs when our little one is sleeping)

Byron SX-20T

Byron SX-20T

But the best thing about it is that it uses the 433MHz frequency which is recognised by the RfxTrx433 so I can automate actions in DomotiGa when the doorbell is pushed, and here is what happens when someone does:

  1. Play the same tune as the receivers on the server’s speakers, effectively providing the equivalent to a 3rd receiver (sample tunes available here)
  2. Log the time and date the doorbell was pressed for future use (e.g. “Hey dear courier, nobody rang the bell when you tried to deliver that parcel and left it outside for someone to steal it, and I can prove it”)
  3. Send an automated email to inform me that a visitor passed by.

What’s Next?

I’m planning on adding some “proper” CCTVs to the house – the ones I had before were cheap and not so cheerful so  I got rid of them. When I do, I can then send a picture of the CCTV with the notification email.




Google Text-To-Speech

[8th Feb 2016] Note: this article is now obsolete, please check my newer article on Voice RSS


For some time I was using Google’s free Text-To-Speech  which provides a very simple way of converting text into speech:

http://translate.google.com/translate_tts?tl=en&q=Hello+world!

This enabled me to be greeted each morning with the weather forecast for the day.

However early August Google changed their website and forced users to enter a captcha to stop automated access, with the message “Our systems have detected unusual traffic from your computer network. This page checks to see if it’s really you sending the requests, and not a robot.“.

Seeing as I was using this in bash / python scripts, TTS would no longer work.

While looking for alternative (free) solutions, I tried various TTS solutions including epeak, festival, pico2wave, and Mbrola voices, but it was far off the quality provided by Google’s TTS engine.

Anyhow, not giving up, and after a lot of digging, I found the solution, I just had to add more parameters to Google URL. I’ve added the new link below with the new parameter in bold below. Also note the revised parameter for the translated language:

http://translate.google.com/translate_tts?ie=UTF-8&tl=en_GB&total=1&idx=0&client=t&q=Hello+world!

Now to call this from a bash script, use the below commands:

wget -q -U "Mozilla/5.0" -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en_GB&total=1&idx=0&client=t&q=Hello+World!"
mpg123 -q output.mp3

Notes:

  • Google will not accept access unless it thinks it’s a browser, to we have to use wget to output the sound into an mp3 using the -U “Mozilla/5.0” command.
  • Google has a limit of 100 characters per request

Now all I have to do in DomotiGa is to create an event triggered on a movement sensor with a condition based on hour of the day (typically 04:00 – 12:00), ensuring it will only run once in a set period (8h). This way, as soon as I enter the living room in the morning, I get greeted with the weather forecast for the day 😎
I use a free wunderground account to extract weather data from an xml file and achieve the above.




New version of DomotiGa & SmartVISU = New Plots

DomotiGa was upgraded over the Easter weekend as well as a new version of SmartVISU bringing an improvement on plots.

Whereas before the plot function would pull the complete list of values to build the chart (and therefore would just time out, especially with my CurrentCost power consumption as it updates every 5 sec), the revised version has a new parameter for the maximum number of points to return.

This means I can now plot ANY of my devices’ values:

SmartVISU Plots

SmartVISU Plots

The easiest way to know where to put that new value (mine’s set to 2500 as any higher seems to time out) is to open widgets\plot.html

/**
* A simple widget for plotting charts
*
* @param unique id for this widget
* @param series of item/s. More item/s in array form: [ item1 , item2 ]
* @param the mode: 'avg', 'sum', 'min', 'max'
* @param the minimum time (x-axis): '1h', '2h'... (duration-format)
* @param the maximum time (x-axis): '', '1h', '2h'... (duration-format, default: now)
* @param the minimum y-axis (optional)
* @param the maximum y-axis (optional)
* @param the number of points in the period
* @param label/s for each series (optional)
* @param color/s for each series e. g. '#f00' for red (optional, default: sutiable for design)
* @param type/s for each series: 'line', 'stair', 'spline', 'area', 'areaspline', 'column' (optional, default 'line')
* @param title/s for the x-axis and y-axis
* @param minimum time while zooming in sec (optional, duration-format)
* @param number of samples (points) (optional, default 100)
*
* @see misc/fundamentals#Array-Form
* @see misc/fundamentals#Duration-Format
*/

 




MCE Remote: getting lazier by the day

Now that I’ve set up Plex on my server and install Plex Home Theater on my PC, I can play movies on my PC and watch them on the TV in the living room (via SPDIF & HDMI cables).

Trouble is Plex Home Theater is designed to be controled by a remote and mice are not supported.

I’ve therefore purchased an MCE remote from Amazon. The beauty of this remote is that 1) it’s ridiculously cheap (the price was £6.95 when I bought it) and 2) it’s natively supported by Windows, no need for bloat software or drivers.

Emprex 3009ARF Wireless MCE Remote Control

Emprex 3009ARF Wireless MCE Remote Control

1 tiny annoyance though, the green Windows button is set up to launch Windows Media Center and there doesn’t appear to be a setting to change this.

MCE Windows Button

MCE Windows Button

After a bit of digging online, I found out that the green button launches C:\Windows\ehome\eshell.exe

So it should then be fairly easy to replace this file and put my own script instead right?

Wrong! For some reason Windows has this file set up in  such a way that you cannot delete or rename it. This is the way to go round the limitation:

  1. Navigate to C:\Windows\ehome\
  2. Right-click on eshell.exe > Properties
  3. Click on the Security tab
  4. By default, TrustedInstaller has all rights and you cannot change the rights for other groups / users

    eshell Properties

    eshell Properties

  5. Click on Advanced > Owner tab > Edit.

    eshell Owner

    eshell Owner

  6. Select the new Owner (your account) and Accept > OK
  7. Now select your user and enable Full Control

You can now rename eshell.exe and use a different program instead.

I have used AutoHotKey to write a script which would launch Plex Home Theater instead of Windows Media Center:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
run, "C:\Program Files (x86)\Plex Home Theater\Plex Home Theater.exe"

 

Now why stop there?

I would still need to get to the PC and manually set the default audio output to SPDIF, and I have to use my HomeEasy remote to activate a Movies mood scene in DomotiGa (I’ve synced a button with my RFXTrx433 so DomotiGa recognises the remote as a device).

So I created another AuthoHotKey script which constantly runs in the background and adjusts the default audio output depending on whether Plex Home Theater is running or not. And it also executes a Python script which will send a command via JSON-RPC to update a device on  DomotiGa.

Here are the scripts:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

MCE_Win = 0
DetectHiddenWindows, On
while(1)
{
winwait, Plex Home Theater
winminimize, Plex Home Theater
run, "C:\Program Files\Python 3.5\python.exe" "C:\Program Files\Python 3.5\MoodSceneMoviesOn.py"
; Sets audio out to SPDIF
runwait, "E:\Docs Communs\G12.exe"
winactivate, Plex Home Theater
winmaximize, Plex Home Theater
MCE_Win = 1
sleep, 5000
while(MCE_Win)
{
IfWinNotExist, Plex Home Theater
MCE_Win = 0
sleep, 2000
}
run, "C:\Program Files\Python 3.5\python.exe" "C:\Program Files\Python 3.5\MoodSceneMoviesOff.py"
; Sets audio out to PC Speakers
run, "E:\Docs Communs\G8.exe"
}

 

import requests, subprocess
import json, json as simplejson

def Domotiga_API(Method, Device_Id, Valuenum, Value):
url = "http://192.168.0.24:9090" 
data={'jsonrpc': '2.0', 'method': '' + Method + '', 'params': {'device_id': Device_Id, 'valuenum': '' + str(Valuenum) + '', 'value': '' + str(Value) + ''}, 'id': 1}
headers = {'Content-type': 'application/json', 'Accept-Encoding': 'text/plain', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)
c = r.content
result = simplejson.loads(c)
#print result

Domotiga_API("device.set", 21, 1, "On")

Now I simply need to sit on the sofa and press the green button, and the following happens “automatically”:

  • Plex Home Theater starts
  • Default audio set to SPDIF on my Windows PC so the sound goes to the amplifier
  • Speakers connected to the server  announce “Mood Scene: Movies, Activated
  • The lights in the kitchen and living room turn off
  • A red light for the right ambiance gets turned on

Isn’t life beautiful? 🙂

[Edit – 20/05/2016] This doesn’t seem to work under Windows 10. MCE is technically dead under Windows 10, yet I can still start MCE manually and the remove appears to still send some of the commands, only nothing happens when pressing the MCE button. I’ll share more once I have an update