BTHome Electricity Meter

UPDATE 8/12/22 - updated to use the new BTHome v2 protocol, will only work with HA 2022.12.0 or above!

UPDATE 5/10/22 - new code uses BTHome to allow easy set up with Home Assistant and Discovery - see post 8 for setup instructions. Thanks!

TL:DR: Puck.js, LDR, modified Passive BLE Monitor component and code for Puck.js here.

Just a little project that got me scratching my head over the last few weeks!

I have a ‘smart’ electricity meter I wanted to integrate with HA but because it’s a SMETS1 and I’m no longer with my electric company it’s now as useful as nipples on a fish.

My meter is outside my house, so I wanted something inexpensive, battery-powered (sorry HA Glow), long-lasting, and without having to interfere with any of the high-amp wiring coming into the house. I also wanted accuracy without fiddly linear calibration - CT clamps have issues here.

I based this project on Gordon Williams’ Puck.js board - it’s a £30 CR2032-powered board with 6-12 months battery life, a button, LEDs, magnetometer, compass, themometer, IR, and more. Gordon has already made a smart meter project with this using a light dependent resistor soldered to D1 and D2 to measure the LED flashes on a standard 1000 Imp/kWh electricity meter.

I have modified this project so that it also calculates the active electricity usage in the house in watts. Data is broadcast as a byte array over BLE advertising to minimise power consumption. To read the data I have made a custom version of the Passive BLE Monitor component, which can be found here. The required code for the Puck.js is included in the repository (puckjs_energymeter.js). New version uses BTHome - see above

Alternatively you can buy an iNode for a similar price - this is already integrated into the BLE Passive Monitor component, however it only updates once per minute, battery reporting is less accurate, and I had issues trying to get hold of one. Plus the Puck.js allows for a lot more customisation if you know what you’re doing!

2 Likes

Also, if you’re like me and you’re finding your HA is just a bit too far from the meter to get reliable readings, here’s a template for an ESP32 flashed with ESPHome which can act as a hub for the meter and forward the data on to HA. You can also use this if you don’t want to use the Passive BLE Monitor integration:

esphome:
  name: electricity-meter
  platform: ESP32
  board: esp32dev

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "[otapassword]"

wifi:
  ssid: "[ssid]"
  password: "[password]"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Electricity-Meter"
    password: "[password]"

captive_portal:

sensor:
  - platform: template
    name: "energy"
    id: energy
    state_class: "total_increasing"
    unit_of_measurement: "kWh"
    device_class: "energy"

  - platform: template
    name: "power"
    id: power
    unit_of_measurement: "W"
    device_class: "power"

  - platform: template
    name: "battery"
    id: battery
    unit_of_measurement: "%"
    device_class: "battery"

  - platform: template
    name: "batteryVoltage"
    id: batteryVoltage
    unit_of_measurement: "V"
    device_class: "voltage"

esp32_ble_tracker:
  scan_parameters:
    active: false
  on_ble_manufacturer_data_advertise:
    - mac_address: [mac]
      manufacturer_id: 83a0
      then:
        - lambda: |-
            float value1 = ((x[0]) + (x[1] << 8) + (x[2] << 16) + (x[3] << 24));
            id(energy).publish_state(value1 / 1000);
            float value2 = (x[4]) + (x[5] << 8);
            id(power).publish_state(value2);
            float value3 = (x[6]);
            id(battery).publish_state(value3);
            float value4 = (x[7]);
            id(batteryVoltage).publish_state(value4 / 10);

Hey! Spent months on puck.js =) and your code is so small…
How do I get the total energy use for a day? I get instant, but no total.
Also, in my puck.js code I had to modify so that it sends Zero for instant power in between cycles, as during the day it will just stay on its last value, as most energy is coming from solar

Impossible to find a puck.js in stock at the moment but this is a really great solution! I was looking at doing something similar but could only find one pre-made solution - the “Frient Electricity meter interface” that was battery powered.

How have you found battery life so far? The Frient (at double the price) lasts 2 years from it’s AA batteries, imagine the puck is only managing around 6 months of constant reporting from the cell battery?

I think my first battery was dodgy as it only lasted a couple of months - replaced it back in November and I’m still on 83% battery so it seems to be lasting a long time!

Maybe a better quality battery than the generally cheap ones that devices are supplied with. Is that with it consistently pushing out data? Surprised it lasts that long to be honest but great that it does, especially if I can find one for £30 as that’s half the cost of the Frient pre-build one!

This image should illustrate just how often it’s sending data - often a few times per minute. Frankly I’m astounded at how battery efficient it is!!

(This is normal daily battery variation by the way; it’s been averaging at 83% for weeks)

I’ve made a new version of this which uses the BTHome protocol to broadcast electricity metrics - this means that your bluetooth-enabled HA device can connect to the meter directly with Discovery enabled, or you can use an ESP32 with bluetooth_proxy to widen your BLE network.

See bthome-electricity-meter/README.md at main · aegjoyce/bthome-electricity-meter · GitHub for instructions and code!

I don’t suppose you know of any puck.js alternatives? I’m happy with the DIY aspect but it’s a bit too expensive in the UK as for £15 odd more you can often buy the frient electric meter reader which has a better battery capacity, includes the photoresistor and integrates directly.

It would be so much easier if I had accessible power in my outdoor electric meter cabinet but sadly I’m stuck with battery operated devices there.

I don’t know any alternatives. The only place I can see the Frient for sale is Vesternet where it’s £63. Lowest price it’s had on Amazon was £54 but it’s usually around £60.

Also the Frient is only compatible with 1000 imp / kWh meters, if you try to put it on a meter with a different imp rate (in the UK many are 3200 or 4000 imp) then you’ll have to make a whole load of template sensors in HA to convert the readings to the correct numbers. With the Puck you can change this in the code for accurate readings.

Battery life on mine is about 8 months on a single CR2032.

Yeah it’s noticeably shot up recently with the energy crisis sadly. I believe Z2M provides options in order to change the reading offsets. Seems like a similar battery life if the puck is also sending real time readings every few seconds at least.

Nice project. Is it ok that I add a link from the BTHome website to your project github?

Sure, no problem! I might need to check my code though as I’ve just seen v2 has come out so want to make sure it’s still compatible

Sure, but remember that V2 will be supported in 2022.12. PR is submitted, but not yet in HA 2022.11

Haha I just found that out the hard way, spent an hour wondering why my HA wasn’t picking up the rewritten sensor!

I’ve created a BTHome v2 branch in my project repo and will push it to main once I can test it in 2022.12. Let me know if you want me to change or clarify anything on the repo for anyone accessing from the BTHome website :+1:

1 Like

New version released to support BTHome v2 protocol - only compatible with HA 2022.12.0 or later. See the repo for updated code!

1 Like

Has anyone found any alternatives to a Puck.js? I like the idea of a battery powered LDR sensor for my electricity meter but £30 seems a bit steep for me when the replacement MQTT smart meter interface is around £60

Ooh, what’s the smart meter you’re looking at?

Its the IHD replacement from hildebrand:

If your meter is supported by the hildebrand products it means it’s either SMETS2 or a migrated SMETS1 meter. That means you can just access the energy use from their “bright” app and API without the need of any additional hardware. Are you looking for something to publish the real time usage rather than 30 minute intervals?