Tag Archives: Raspberry Pi

Toying with HA-BRIDGE

Thanks to readers in here I’m having a play with HA-Bridge to act as a device gateway between my home control (generally ESP8266) devices and Amazon Echo.

I’m only scratching the surface and haven’t gotten past “Alexa, turn X on”, “Alexa turn X off” and “Alexa set X to 30%”  but it’s a start and hopefully someone in here will fill in the blanks.

So, assuming you have an Amazon DOT or Echo (at £49 the DOT is the best toy I’ve bought for ages – just bought another one for the house – as this one is hiding in my office)…

The BEST way to control gadgets by voice up to now IMHO is using our own Node-Red software and an HTTPS certificate – but then – it’s not trivial as has been discussed elsewhere (unless you’ve done it before) to get the HTTPS and Amazon talking to each other.

So I played with simpler solutions (I like to try everything) but just recently decided to have a go at HA-Bridge – now – this IS EASY if you don’t go to the wrong repository etc…

First things first – Aidan was playing with this and he could not get anywhere as he had an old version of JAVA on his Raspberry Pi – he solved THAT problem as such. I found that I had to use root access for ALL of the code below.

    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
    sudo apt-get update
    sudo apt-get install oracle-java8-installer

So that's Java up to version 8. On a NEO AIR I got an error message when running “java –version” until I rebooted.

Now to install HA-Bridge - easy -  go to your PI directory on the Pi or similar - make a directory - called, say, "habridge" - and enter that directory. I grabbed the JAVA file directly in Windows and copied it across-  giving it execute permissions - not sure if that was necessary but I'm just repeating what I did.

All I did was grab the JAVA file from here.

So the general idea is that this Java file will run - and give you a web page in which you can create and run "devices" that the Dot or the Echo will recognise. But it will want to use Port 80 by default (normal web page port) and I of course have a web server there...  I tried running it - failed due to lack of permissions - so I ran it as ROOT - that failed due to the port being in use.

sudo java -jar -Dserver.port=82 ha-bridge-3.2.2.jar

I ran this - note the reference to port 82 - and lo - it works - ok - another matter getting it to run from power up but we’ll come to that.

Ok so THEN I discovered that my MQTT installation – Mosquitto did not include the client tools… so…

sudo apt-get install mosquitto mosquitto-clients -y

Off I went to a browser : 192.168.0.20:82

HA Bridge

Ok, here's the bit that floored me - this might save you a little work. I used MANUAL ADD to add these devices - here's one of them... these will respond to on, off and a value - and send MQTT messages accordingly. That's it - all you then have to do is tell Alexa to search for new devices - and use them.

So what we have here is only marginally better than the simple node-red node - i.e. we now have % lighting control - who is going to show us how to develop this to do temperature and other stuff!

HA Bridge

If you don't need user and password for your MQTT  (-P and –u) - don't use them.

The only thing that appears fairly useless is the middle item - intensity control - which could be used for lighting or heating. So "turn office television to 25" works - you get the value 25. "turn office television up" or "down" shifts the value by around 25% - and that's GREAT for lighting but no use for heating - I would want an actual value to set the heating to that value - but up and down to shift the temperature by - maybe 1 degree.

You can in fact say “turn X up by one”.

SO - easy voice control - create lots of devices... this whole operation other than blogging it took merely a few minutes and thanks to readers who pointed me in this direction.

This software does not seem able to control responses – you get “OK”  - how then would you ASK the thermometer to return it’s current value!?!?! Well, you can’t so there is still life in our HTTPS solution – but this is VERY easy to set up.

Having now followed the instructions here and here (see “writing a unit file in the latter link) made a “unit” startup file – I now have the whole thing running from power-up on the same Pi that runs Node-Red and Mosquitto.

Essentially here’s what I ran having created a UNIT file as per the first of those two links above.

sudo systemctl enable habridge.service

sudo systemctl  start habridge.service

That’s it – program runs – survives power cycle.

Here’s another explanation of how to do this! http://xbmcnut.blogspot.co.uk/2016/10/installing-ha-bridge-on-your-raspberry.html

So much to learn, so little time.

Facebooktwittergoogle_pluspinterestlinkedin

General Update

tmp11DFThe last couple of days has been interesting – we’ve been checking that the Raspberry Pi 2 script works properly – it turns out that it simply won’t work if you have any kind of root access to the Pi. I’d not realised by by giving myself SUDO access in winSCP – rather handy for editing files, I’d given myself the same access in the terminal – and hence all attempts at the script failed. Today after starting afresh with the November 2015 Jessie image from Raspberry Pi (NOT the Noobs setup) – and running as Pi user, the script (despite warnings) operates perfectly, installing Apache, Sqlite, Mosquitto with web sockets and Node-Red with a host of nodes including my own.

In other events, the ESP8266 code referred to elsewhere in the blog has taken a leap (not yet online – I’m off to Spain for a couple of weeks and I’ll get onto that on my return) and now handles (thanks to Richard Burton for his help) OTA.  Still working on OTA from an external site.  We’ve added OTA setup commands to the web interface.

Most importantly on the above we’ve found and modified a library to give a software second serial port able to run at 56k – hence enabling direct Nextion display interaction on an un-modified ESP-12 for example. I already have a display device with buttons controlling other ESPs on the network via MQTT commands – this could be so powerful and will allow for remote control display panels all over the place.

tmp762BThe Sonoff device continues to work well with our software, waiting to find out how much FLASH it has on-board to ensure we’ll be able to work with that,

Sunny SpainRight now I’m packing my bags as I’m off to work on a project for just under 2 weeks on the east coast of Spain near Barcelona – using ESP-12s and Raspberry Pis strangely enough so output on the blog will be somewhat reduced as I can’t take my toys with me. I’ve a new paper-white display and a fantastic new software-defined radio setup – but they’ll just have to wait for my return.

The Facebook page at www.facebook.com/esp8266wifi is seeing more Pi and review related material and I’ve decided it is time to move the non-ESP stuff off onto a page of it’s own – so please if you are a Facebook user, follow www.facebook.com/iotstuff

Facebooktwittergoogle_pluspinterestlinkedin