GithubHelp home page GithubHelp logo

aegjoyce / bthome-electricity-meter Goto Github PK

View Code? Open in Web Editor NEW
27.0 27.0 2.0 26 KB

Code for an impulse-based electricity meter using Puck.js and BTHome for Home Assistant

License: GNU General Public License v3.0

JavaScript 100.00%

bthome-electricity-meter's People

Contributors

aegjoyce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bthome-electricity-meter's Issues

Puck for media control on Home assistant

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

imp variable not used fully for energy calculation

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.