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.clear();
g.setFontVector(30).setFontAlign(0,0);
g.drawString(value?"ON":"OFF", g.getWidth()/2, g.getHeight()/2);
g.flip();
NRF.setAdvertising({ 0x2A56 : [value]});
}
update();
setWatch(function() {
value = !value;
update();
}, 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 :)
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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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 :)