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.

[pcsh lang="bash" tab_size="4" message="" hl_lines="" provider="manual"]

    echo "deb xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
    echo "deb-src xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
    sudo apt-key adv --keyserver hkp:// --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 :

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!

So much to learn, so little time.


29 thoughts on “Toying with HA-BRIDGE

  1. Peter,

    In addition to the ${intensity.percent} for 0-100, there is also an ${intensity.byte} for 0-255, which could be used for RGB values, and there is also an ${intensity.math()} that may be useful for the temp value you are looking for. If in fact saying Alexa turn heat up results in a 25% rise then you can divide that by 25 to give you 1. I have not tried this yet.


    1. I thought of that - and thanks for those extra functions - but I don't think that helps. Of course you can scale 0-100, 0-255, 0-anything - but that still does not allow you to both turn the heating up and down by 1 degree AND obtain an exact temperature reading... need to be able to differentiate between up/down - and an actual value....

  2. ... I understand now, you want to be able to use the same device "room heating" to either set a direct temperature "Alexa set room heating to 22" and also be able to say "Alexa turn room heating down". However, the single dim command will not give you this.

  3. So there is still room in this world for the more complicated version we developed on HTTPS 🙂 Still - no doubt there is still more to learn about HA-Bridge.

    Currently I have on my HTTPS Node-Red code the following..
    Alexa - tell computer to:

    give me the heating status (response "The heating is set to A and is currently at B")
    Set the heating to X
    turn the heating up
    turn the heating down
    set the heating to default

    If I can do that with something like Ha-Bridge without SSL harrassment - I'll change 🙂

      1. Ok, so at least we know - and I've had confirmation of some of the limits of HA-Bridge.. so for output only - HA-Bridge seems excellent - I now have it in my PI startup to run all the time... but for ultimate control - and getting voice feedback - it is looking like the HTTPS solution is the best. So now it is down to gaining knowledge on that subject. I managed one commercial certificate - easy ... the free one seems easy too - but one of my routers does not want to redirect 443 - and if that is happening to me - it will happen to others.

    1. I can't help you with getting Alexa to return the status but one thing that might help is that she does respond correctly to Raise/Lower Device By 1/2etc. Sometimes there are rounding difficulties and you get 2 instead of 1 but perhaps using byte and then math will give a finer grained response. Also I use multiple device names to get different responses so for instance using Temperature for individual adjustments and Heating for defaults and scenes. I then use Node-Red to manipulate the desired outcome

  4. Yeah I'm using the increase/decrease by 1, 2 etc commands.

    Have asked bws to store the last set level and use that instead of resetting to 100 when the on command is used.. No good having having the heating going to max when you say Alexa turn on thermostat lol

    1. Ok guys I've tried "raise office thing by one" - "increase office thing by one" - not having it - am I missing something as you both seem to be suggesting this can be done. My device emulated is VERA and I can turn it on or off or set a value - but I cannot seem to get this up and down by one - what is the exact wording?

      1. Only difference between the setup you show in your screen shot and mine is the Vera emulation. I leave that blank and I was curious why you set it to Vera.

      2. And to be specific my commands are "Alexa raise temoerature by one" and "Alexa lower. Temperature by one" and obvious variants of this. Also there are rumours that Amazon will shortly allow push commands to developers to allow them to get Alexa to make announcements. This may be a solution to your status requests - the sticking point appears to be not making her seem nagging.

        1. "by one" works. Sadly "by one degree" doesn't - but hey - that's a step forward. Thanks!

          Alexa announcements would be a major step forward - the "OK" response is pretty naff - doesn't tell you if you've succeeded or failed - just that you said something 🙂

  5. Hi Pete, I am sending http requests to node red to drive lightwave devices. The dimmer stages go 0-32 so do the maths with intensity as mentioned above. Once the value is in node red you could just re scale 50% would be setpoint 0% say -2 deg 100% +2. So if you reguest Alexa to turn down woukd reduce current setpoint by 1DegC

    1. Well, considering I'd never even looked at HA-Bridge until yesterday morning - I don't think I'm doing too badly 🙂 I hope folk find your link useful - I have it now installed and running - it is limited because it can't send audio feedback on command completion and other issues - this ( ) is by far a better solution but it does need https: which I'm discovering can be very easy or very hard - and a little bit of Node-Red programming but the flexibility is of course amazing. However - clearly there is room for both solutions.

      With a background in Adventures (I wrote one of the early Adventure interpreters so I've an idea about parsing text) I have great plans for my Node-Red program - and right now I'm relying on it to handle heating and other aspects of home control but there can be no doubt - HA-Bridge is a nice piece of work for simple ON-OFF control.

      1. Thanks Pete. I've added a link to this post to the bottom of mine and updated to 3.2.2. Wish I had the time to play with Node Red more as it certainly looks like the way forward. Will have to wait another 5yrs until the kids are grown up!

    1. I'll check it out - but as I have Mosquitto MQTT broker at the centre of my home control, I'm already using HA-Bridge and firing out MQTT messages to it without any issue..

      The one thing that's really missing however is customisable voice feedback... that "OK" is not very re-assuring...

  6. Pete
    I have several modified remote sockets using sonoff innards, but with this dimming functionality available with HA bridge, what about mains dimming.
    I'm looking at the MPDMv4 from Tindie. Have you or anyone any experience with this?

    1. Pete, I have a MPDMv4, and I have it connected via a sonoff that I have picked up gpio 14, GND, and 5v supply from inside the sonoff to run the dimmer. I have the dimmer 240v input running from the Sonoff's switched output. The Sonoff is running Espeasy, and I'm using Domoticz to run everything. Going to try HA-Bridge tonight with my google home.......

    1. Thanks for pointing this out.
      Until now I only used the Node-ReD Wemo Emulator because its also easy to configure and use.
      But THIS one looks nice and indeed dead-simple.
      Had a quick look into the code and will give it a shot.

Comments are closed.