Integration with Home Assistant #6501
Replies: 1 comment
-
Posted at 2021-03-19 by @gfwilliams Hi! There's actually been some work on https://github.com/espruino/EspruinoHub 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: https://www.espruino.com/BLE+Node-RED
Well, that was actually done using this code: http://www.espruino.com/BLE+Lightbulbs 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... Posted at 2021-03-19 by Weiming Hi @gfwilliams, 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. Thanks. Posted at 2021-03-22 by @gfwilliams 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: https://esphome.io/components/binary_sensor/ble_presence.html?highlight=bluetooth That would then be able to track Bluetooth LE devices (like the Bangle) and you could trigger events based on that. Posted at 2021-03-22 by Weiming 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? Posted at 2021-03-23 by @gfwilliams 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 Posted at 2021-03-23 by Weiming Thank you! I think it makes sense to me now. I will need to get my hand dirty before I report back. Posted at 2021-03-25 by @gfwilliams 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 https://github.com/espruino/EspruinoHub#home-assistant-integration, but basically:
On the Bangle, or some other Espruino device you can now do:
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 :) Posted at 2021-03-25 by Weiming Hi @gfwilliams. 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! Posted at 2021-03-25 by Weiming 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. Posted at 2021-03-26 by @gfwilliams 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.
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 Posted at 2021-03-26 by Weiming 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. Posted at 2021-03-26 by Weiming Could you explain By the way, the device name showing up in my Homeassistant has Thank you Posted at 2021-04-06 by @gfwilliams Hi! It's handled by EspruinoHub here: https://github.com/espruino/EspruinoHub/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 ( Posted at 2022-02-16 by Weiming
It would be nice to somehow reconnect to the previous device if the watch has a BLE connection before the advertisement. Do you have any references on how to do that? Thanks. Posted at 2022-02-16 by @gfwilliams
You can't - it's up to the phone/etc to reconnect, the Bangle can't do anything to force it I'm afraid. The Bangle could disconnect and then use Posted at 2022-09-16 by kab Coming back to this out of interest due to the new bluetooth proxy that home assistant has. Has anyone looked into BTHome https://bthome.io/ for home Assistant. I think if this was used the whole hub and mqtt could be skipped? Posted at 2022-09-21 by @gfwilliams Honestly, this sounds a lot like this: Bluetooth LE already has provision for advertising standard types of sensor, like for instance Temperature: https://github.com/oesmith/gatt-xml/blob/master/org.bluetooth.characteristic.temperature.xml The mentioned ATC Thermometer seems to advertise those by default as well. Ideally Home Assistant should support those actual standards out of the box if it's also supporting bthome (I'm not sure if it does though). But either way, it'd be trivial to make Espruino/Bangle.js advertise the bthome.io advertising - and I'd be very happy to ensure we host a module that allows that to be done easily Posted at 2022-09-21 by kab I agree. Yet another standard Is it just a matter of advertising the bthome code rather than the bluetooth std code. Posted at 2022-09-23 by @gfwilliams It's not quite that simple, but not far off. Based on
But effectively, normal Bluetooth might advertise:
and bthome will advertise:
For the same data because it's wrapping it in the UUID 0x1C18 to stay compatible with Bluetooth If you're sending lots of data then it'll be slightly more efficient, but for just 1 or 2 types of data it's actually less memory efficient. Posted at 2022-10-23 by kab I have to confess, all this hex stuff makes my eyes crossed (grin). If you ever get the above "trivial" bthome module done, that would be quite helpful. I'd love to do it myself but have run into alot of walls trying. Posted at 2022-12-22 by agdamsbo Hi! I see, that you have welcomed the new standard (though that XKCD is one of my favorites) with the bthometemp app. It's really neat, and I've just set up a ESP32 bluetooth proxy. Posted at 2022-12-26 by KTibow this bthome integration looks awesome, is there a good way to send custom data? Posted at 2023-01-13 by @gfwilliams I'm not sure if you spotted it, but I did post some code on https://forum.espruino.com/conversations/382301/#comment16798335 - sorry I missed this post when you made it last year though!
Do you have a link? I'm sure we could do something like that, yes. We now even have an app that will send temperature. There is already a home assistant app which uses Gadgetbridge and the home assistant Android app too.
There is But if you have a specific request, maybe contact the developers. It seems like an evolving standard :) Posted at 2023-03-18 by kab I am so glad you got back to this! I looked into your bangle app as an example to work from and get started. I am trying to take my puck which I use as a simple on/off/volume up/volume down button in Home Assistant based on button presses. I use the SwButton module to do the button click heavy lifting. 1 short press is toggle on and off via generic boolean (0x0F) I have it working w EspruinoHub and MQTT fine - but want to "upgrade" BTHome so I can use the PiZero with the EspruinoHub on it for something else, and I have a lot to BluetoothProxies around the house anyway. I wrote the following which seems to work fine except one issue -- the advertised count reverting to 0 after the button is pressed doesn't seem fast enough. Is that in my idletimeout? Anyway - any comments or ways to make this cleaner/faster appreciated
Thanks for getting to this despite it being "another standard" Posted at 2023-03-20 by @gfwilliams Looks good, although I guess you could keep advertising battery/temperature even when the button is pressed, and should probably advertise 0x0F/btnData.state all the time so home assistant knows the button is there all the time, just not pressed?
What exactly isn't it fast enough for? It's actually a bit unfortunate that they chose to do buttons this way, because it feels like either you have a short timeout and you risk the button press getting never received, or you have a long one and potentially other devices think the button is pressed more than once. If the button had been advertised as a 'press count' that just incremented when the button was pressed things would have been much easier - no timeout would be needed. Posted at 2023-03-20 by kab Thanks for the tips - as always very helpful - and again thanks for the bthome example. Posted at 2023-10-13 by user156756 Getting back to this with all the Home Assistant updates and saw that BTHome now has button events. Works lovely
Posted at 2023-10-16 by @gfwilliams That's great - thanks for letting us know! Are all those elements needed? Looking at https://bthome.io/format/ I see the I should make a Posted at 2023-11-24 by @gfwilliams Just added a library for this: https://www.espruino.com/BTHome I'd be interested to see if it all works ok for you. I notice that button events on their own don't seem to appear though, and in your code you have defined a button - do you have any ideas if that is needed? I'm struggling to find info on it... Posted at 2023-11-24 by @gfwilliams Actually I take that back - it works fine, I just didn't spot how the events come in (they're there when you look at the log for the device) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-03-18 by Weiming
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 @gfwilliams '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!
Beta Was this translation helpful? Give feedback.
All reactions