Integration with Home Assistant

Posted on
  • Hello all,

    I'm wondering whether there are any projects on setting up the Bangle.js with Home Assistant? Currently, I have some smart switches and the Home Assistant set up. I'm wondering whether I can control them from my watch.

    I'm aware of some home automation projects, like this one. But it is not set up for Bangle.js unfortunately.

    I accidentally found something related to this in one of @Gordon 's old videos at here

    . In the video (at 1:15), it appears that the watch is directly controlling the light. That is exactly what I'm looking for.

    I hope I can get some help from the forum. Thanks!

  • Hi! There's actually been some work on which should allow it to integrate with Home Assistant (as a bridge to/from Bluetooth LE). The contributor didn't document it though and I haven't had a chance to try it yet.

    My understanding is as long as EspruinoHub is using the same MQTT server, devices found by EspruinoHub should just pop up

    Otherwise this works with Bangle.js and could be integrated with Home Assistant pretty easily:

    it appears that the watch is directly controlling the light. That is exactly what I'm looking for.

    Well, that was actually done using this code:

    I never actually committed the app I used for that, but can do if you need it (although chances are you don't have those bulbs). I'd be happy to help with support for different bulb types if needed...

  • Hi @Gordon, Thanks for the reply. I'm pretty new to home automation. It looks like the smart plugs I want to control use WIFI connection. I have multiple smart plugs and they are directly connected to my router. I don't have/need a hub as a result.

    Do you have any suggestions for this situation?

    Wild guessing here. Can I maybe send action/message through gadgetbridge and then somehow gadgetbridge can relay the message to my Home Assistant app on Android? I'm not sure how difficult this is for a JS beginner.


  • Unfortunately Gadgetbridge doesn't provide any bridging to the internet - it's pretty privacy focused so they've taken the decision not to ever allow the app itself to access the internet to give users piece of mind. That makes things pretty difficult for us though!

    I think the best bet is to go with Home Assistant for now. I'll try and look into how well EspruinoHub works with it, but one solution is to use Home Assistant with an ESP32 running EspHome:­sor/ble_presence.html?highlight=bluetoot­h

    That would then be able to track Bluetooth LE devices (like the Bangle) and you could trigger events based on that.

  • Thank you for the suggestion. So this means that my Bangle.js needs to be connected with my Home Assistant server via BLE, correct? And I suppose I need an app on Bangle.js to send messages like turn on and off?

  • Well, what'd happen is the Bangle.js is 'advertising' - so not actually connected to anything at all.

    Then Home Assistant would be able to receive the advertisements and figure out based what is in them whether it should turn the light on or off.

    But yes, you'd need an app on the Bangle for that - but it'd be super simple. Basically just something that calls NRF.setAdvertising(...) with one value or another.

  • Thank you! I think it makes sense to me now. I will need to get my hand dirty before I report back.

  • Ok, just an update on this - I had a go, and it needed some changes but it works great!

    I tried to document it at­home-assistant-integration, but basically:

    • Update to the latest EspruinoHub
    • Enable the MQTT option in HomeAssistant and point it at 'localhost'
    • All your devices appear!

    On the Bangle, or some other Espruino device you can now do:

    var value = false;
    function update() {
      g.drawString(value?"ON":"OFF", g.getWidth()/2, g.getHeight()/2);
      NRF.setAdvertising({ 0x2A56 : [value]});
    setWatch(function() {
      value = !value;
    }, BTN, {repeat:true});

    When it's not connected to any other device it'll start advertising when running the code above, and pressing BTN1 will change what it advertises from a 0 to a 1 and back. You can then hook onto that with a rule in Home Assistant :)

  • Hi @Gordon. I just realize that to pursue the Bangle.js->ESP32->EspHome->Home Assistant path, I actually need an ESP board. Correct? I'm a beginner on ESP projects. Do you have any suggestions for where I can start? e.g. are there any starter's kit? Thank you!

  • It looks great. What about when the bangle is connected, e.g. with my phone via gadgetbridge? Will the messages only be sent to my phone rather than broadcasted? Thanks.

  • Using what I'd mentioned in the last post you shouldn't need an ESP32 - it can all be done from just the one Raspberry Pi.

    What about when the bangle is connected, e.g. with my phone via gadgetbridge?

    Yes, when you're connected there won't be any advertising so the data won't be sent. However if you're writing this as an app you could just momentarily disconnect from your phone by calling NRF.disconnect()

  • Awesome! I got it got working with my Bangle.js watch! Things are actually easier than I expected. Thank you very much.

    I plan to prototype a small app so that I can actually run it on my watch! Will report back.

  • Could you explain 0x2A56? It looks like a service ID but I couldn't find any reference for this number particularly. Am I using the correct manual?

    By the way, the device name showing up in my Homeassistant has digital in the name. But I don't understand where you change that/specify that?

    Thank you

  • Hi! 0x2A56 is based on­/master/org.bluetooth.characteristic.dig­ital.xml (for some reason the Bluetooth SIG stopped hosting pages on these which makes them harder to find)

    It's handled by EspruinoHub here:­blob/master/lib/attributes.js#L257

    Basically you need to advertise a UUID type and so we (ab)use the Bluetooth 'digital input' service type. You could also use analog, or there are a bunch of other ones there.

    There's also the ability to use Espruino's own UUID (0x0590) and then you can even send JSON (although since there are so few bytes available you're quite limited)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Integration with Home Assistant

Posted by Avatar for Weiming @Weiming