aegjoyce / bthome-electricity-meter Goto Github PK
View Code? Open in Web Editor NEWCode for an impulse-based electricity meter using Puck.js and BTHome for Home Assistant
License: GNU General Public License v3.0
Code for an impulse-based electricity meter using Puck.js and BTHome for Home Assistant
License: GNU General Public License v3.0
Hello,
i like your solution with puck.js for power metering. However it is relatively expensive for what it is.
Is it possible for you to adjust your code to utilize much cheaper solution from Seeed Stuidio? It's just 1/4 of the price of puck.js and has more updated nrf chip on it.
Looking forward to hear from you back
thanks
Wow this is great!
I found this while I was looking for hints on how to convert from my current espruino hub/mqtt script to a BThome for Home Assistant. I must confess my eyes cross at the hex code.
I currently use my puck for simple control of my Sonos on my desk. Just a simple on/off and up/down volume control via a long/short set of button pushes.
I successfully send BLE advertising for battery (0x180F), on/off (UUID digital 0x2A56), volume (UUID alert_level 0x2A06) cause those were the only standards I could see that espruino hub worked with. These get converted by the espruiono hub on a pi pico to send as mqtt then into an automation. Works grand.
But I'd like to get the hub out of the picture if possible and try bthome off a esphome device I am also using near my desk for presence detection.
Can I be cheeky and ask for some help on converting this? Keep in mind I am a hacker so the below may not be perfect.
This is what I now have on my puck.
var SWBtn = require("SWButton");
var buttonState = 0;
var advData = {};
var idleTimeout;
var mySWBtn = new SWBtn(function(k){
if (k === "S" ) { // single button press
buttonState = !buttonState;
advData[0x2A56] = buttonState; //UUID digital
advData[0x2A06] = 0; ///UUID alert_level 0-no level
}
else if (k === "L" ) { // long button press
advData[0x2A06] = 1; //UUID alert_level mid level
}
else if (k === "SS") { // double short press
advData[0x2A06] = 2; ///UUID alert_level high level
}
updateAdvertising(advData);
});
//start with advertising temperature and battery level
setInterval(function () {
advData[0x180F] = [E.getBattery()];
NRF.setAdvertising(advData);
}, 1*60*1000); // 1 min
function updateAdvertising(advData) {
NRF.setAdvertising(advData);
if (idleTimeout) clearTimeout(idleTimeout);
idleTimeout = setTimeout(function() {
idleTimeout = undefined;
advData[0x2A06] = 0; ///UUID alert_level 0-no level
NRF.setAdvertising(advData);
},2500);
}
I think I just need help "converting" what gets advertised to a bthome format?
Anyway - happy to see the puck being used on a home assistant project. It was a great device to learn on.
Thanks
Many thanks for the great code, got it running mostly successfully on my puck.js with HA.
My meter has a 1000 / kWh impulse rate, so I have updated the 'imp' variable accordingly, but I have noticed the reported energy rate is still out. I think it stems from Line 42:
energy = counter * 0.3125;
I think it should be the following to convert correctly based on different imp values:
energy = counter * 1000 / imp;
Thanks again
Ian
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.