user156756
Member since Oct 2023 • Last active Feb 2024Most recent activity
-
-
-
- 5 comments
- 413 views
-
-
Coming back to this for a bit. Great to see a BTHome library. Quick and easy device/sensors into HA.
Works great with your example using a singlebutton press. I can see the event on the Home Assistant log.One thing I can't figure out is how to set up long press and double press events. This sends through both a double and a single press when I hit the puck button once
... function updateAdvertising() { NRF.setAdvertising(require("BTHome").getAdvertisement([ { type : "battery", v : E.getBattery() }, { type : "temperature", v : E.getTemperature() }, { type: "button_event", v: buttonState ? "press" : "none" }, { type: "button_event", v: buttonState ? "double_press" : "none" }, ]), { name : "Puck" }); ...
Feeling stupid - Thanks
-
-
Life moves on and different projects take priority... so selling my Bangle2.
Factory reset with latest firmware as of today. Excellent condition, buttons all work, battery charges - all lovely. In its original box, with original charging cable and an extra charging cable I picked up.
Asking £45. Will pay for Royal mail 2nd class shipping in the UK.
Please respond via DM.Have enjoyed this one - now onto other adventures in tiny things.
-
Getting back to this with all the Home Assistant updates and saw that BTHome now has button events. Works lovely
var SWBtn = require("https://raw.githubusercontent.com/muet/EspruinoDocs/master/modules/SWButton.js"); var buttonState = 0; var btnData = {}; var idleTimeout; if (!Puck.bleAdvert) Puck.bleAdvert = {}; // these get created with a puck button press var mySWBtn = new SWBtn(function(k){ if (k === "S" ) { // single button press buttonState = !buttonState; btnData.state = buttonState; btnData.btn = 0x01; btnData.press = + 0; } else if (k === "L" ) { // long button press btnData.press = 1; btnData.btn = 0x04; } else if (k === "SS") { // double short press btnData.press = 2; btnData.btn = 0x02; } updateBTHome(btnData); }); function initBTHome() { tempF = [(E.getTemperature()*9/5)+32]; Puck.bleAdvert[0xFCD2] = [ 0x40, /* BTHome Device Information bit 0: "Encryption flag" bit 1-4: "Reserved for future use" bit 5-7: "BTHome Version" */ 0x01, // Battery, 8 bit E.getBattery(), 0x02, // Temperature, 16 bit tempF&255,tempF>>8, 0x3A, // button event none 0x00, ]; NRF.setAdvertising(Puck.bleAdvert); } setInterval(function() { initBTHome(); //}, 1*60*1000); // 1 min }, 10000); // 10 sec function updateBTHome(btnData) { Puck.bleAdvert[0xFCD2] = [ 0x40, /* BTHome Device Information bit 0: "Encryption flag" bit 1-4: "Reserved for future use" bit 5-7: "BTHome Version" */ 0x09, // count1 button press, 1 bit btnData.press, 0x0F, // binary button state, uint8 (1 byte) btnData.state, 0x3A, // button event btnData.btn, ]; NRF.setAdvertising(Puck.bleAdvert); if (idleTimeout) clearTimeout(idleTimeout); idleTimeout = setTimeout(function() { idleTimeout = undefined; Puck.bleAdvert[0xFCD2][2] = 0; NRF.setAdvertising(Puck.bleAdvert); },2500); }
Rather than try to do the time calculations I am trying to use the SWButton.js module.
This seems to work. Have I got it correct?
Seems quite fast
Thanks