Powerpal smart energy monitor

I have now also finished the Emerald Electricity Advisor ESPHome component if anyone has one of these instead of the Powerpal:

Just like the Powerpal component, it’s not PR’d to ESPhome yet, but you can use it via external_components like this:

external_components:
external_components:
  - source: github://WeekendWarrior1/esphome@emerald_ble
    # requires ble_client and ble_tracker because I had to add some small features to authenticate properly
    components: [ ble_client, esp32_ble_tracker, emerald_ble ]

# optional requirement used with daily energy sensor
time:
  - platform: homeassistant
    id: homeassistant_time

esp32_ble_tracker:

ble_client:
  - mac_address: 30:1B:97:01:02:03
    id: emerald_advisor

sensor:
  - platform: emerald_ble
    ble_client_id: emerald_advisor
    power:
      name: "Emerald Power"
    daily_energy:
      name: "Emerald Daily Energy"
    energy:
      name: "Emerald Total Energy"
    battery_level:
      name: "Emerald Battery"
    pairing_code: 123123
    pulses_per_kwh: 1000
    time_id: homeassistant_time # daily energy still works without a time_id, but recommended to include one to properly handle daylight savings, etc.

What it looks like in Home Assistant:
image

(Like above, Emerald Total Energy is used to integrate the usage into the HA Energy Dashboard)
Also like above, the component still needs a bit of a cleanup and extra features but I hope some people find it useful.
A little bit more documentation is in the readme:

I am not very familiar with ESPHome. But I do have an ESP32. Can I install this?

I tried my hand at this and get the following error.

Whoops sorry, there was a bug in the change I made to the power units.
Please try again with the same yaml

I have it working now and reporting into my Energy dashboard. I havent checked the Accuracy though. The total consumption doesnt seem to be resetting everyday. Is that directly coming out of Powerpal?

Hi SincHome, really glad to see you got it working.

The Powerpal ESPHome component currently has an internal counter (total of pulses since boot) which it uses to increment the Powerpal Total Energy entity. I used this functionality after looking at how a different ESPHome energy meter reader handled passing energy data back to Home Assistant (and let me add, Home Assistant only likes usage data for the energy dashboard in a few specific formats, one of them being this implementation).
There are downsides to this solution though, namely how to handle persistance on the ESPHome after a reboot, without hammering writes to the ESP’s flash.

Since this solution could be better, I would like to move to a resetting Total Daily Energy sensor, (which will require the NTP/time component added to the ESPHome device), but I have not completed that yet.

PS. Please let me know if your collected data doesn’t match your Powerpal application’s dashboards.

HI Weekend Warrior1

I got my powerpal installed today, so will be trying to get the device to speak using the esphome

One question. When I load the data into the information into the esphome yaml, it seems to note like having a capital W in kWh. See below

When I change it to lowercase, its fine

I haven’t compiled it yet, and I saw the above post showing an error when using the localcase w.

So just wanted to clarify which is the correct setting

Thanks again for an awesome tool

Please use lower case ‘w’
(I tried to use the correct SI unit but turns out esphome yaml only wants lowercase keys (which honestly is not a bad thing, just something I didn’t realise at the time))
I will update any documentation that still has the uppercase ‘W’ now.

I’m happy to read that some other people are already finding the component useful :grinning:

Hi Weekend Warror1

I’ve just had a look at the past 2 days and the data is spot on! This is a great tool and I’ve been waiting for something like this for a while as I don’t have any apple devices as required by the previous solutions.

Is the data reported out of the powerpal the number of pulses and the kWh is calculated on the ESP? I only ask because on the app when it shows real time Wattage the numbers seem more precise where as the values reported by the ESP are always round numbers even with 5 decimal points. At the end of the day the total wattage is realistically the same.

In addition to your code, I have added a restart button to my ESP. I just flick it on when I want to connect my phone to sync the data. Once it syncs I quickly disconnect my phone from the powerpal and the ESP resumes. Its been working great so far!

Hi SincHome,

Glad to read that the data matches the android application!

Is the data reported out of the powerpal the number of pulses and the kWh is calculated on the ESP?

Yeap, this code just gets number of pulses and then converts them before sending them to HASS/MQTT.

I only ask because on the app when it shows real time Wattage the numbers seem more precise where as the values reported by the ESP are always round numbers even with 5 decimal points.

  • The Powerpal Application does a couple of extra things to get a much more accurate “instantaneous” measurement, as it subscribes to notifications from the Powerpal every time a pulse is read, and then uses the time delta between the last 2 pulses to display the instantaneous usage. Whilst this is neat, I presume it’s better for Powerpal battery life to not ask for notifications of every pulse, and isn’t useful to us.
  • I have also observed the round numbers in the power sensor and I think there is a possible bug in the power calculation maths, I will have a better look tonight.

At the end of the day the total wattage is realistically the same.

Regardless of the above bug, this calculation is much simpler and looks like I didn’t mess it up lol :slightly_smiling_face:

In addition to your code, I have added a restart button to my ESP. I just flick it on when I want to connect my phone to sync the data. Once it syncs I quickly disconnect my phone from the powerpal and the ESP resumes. Its been working great so far!

Nice!
One thing to watch out for is that since we can’t upload historic data to HASS, your ESPHome device will miss any energy updates it should receive whilst you have it disconnected from the Powerpal, and will throw your total measurements out by the same value (also out of curiosity, if you’re logging this to HASS, how does your built in energy dashboard handle this reset? I was under the impression that the counter reset makes HASS think it’s a new day or something?)

The Bot seems to be just a tad smart-arse and unable to respond to my query of why the Bluetooth link dropped out after 4 days and is unable to relink to my relatively new smartphone.
[Smart-arse: giving a WikiLink to short-hair tabby cats, rather than answering the question.]
PowerPal service seems just over-simple, giving the brush-off rather than doing its job.
Hughrster

I am having issue connecting to my emerald device. Please take a look at log snapshot.

Hi Abhishek,

Can you please post the yaml you are using?
I can see there are a couple of Emerald’s in the vicinity, can you triple check that you have the correct MAC address and pairing code?

Hi Weekend Worrier,

Here it is

esphome:
name: emerald-ble-bridge

esp32:
board: esp32dev
framework:
type: arduino

external_components:

  • source: github://WeekendWarrior1/esphome@emerald_ble

    requires ble_client and ble_tracker because I had to add some small features to authenticate properly

    components: [ ble_client, esp32_ble_tracker, emerald_ble ]

logger:
level: VERBOSE
logs:
mqtt.component: DEBUG
mqtt.client: ERROR

api:

ota:

wifi:
ssid: “xxx”
password: “xxx”

ap:
ssid: “emeraldble Fallback Hotspot”
password: “xxx”

esp32_ble_tracker:

ble_client:

  • mac_address: 30:1B:97:64:39:BB
    id: emerald_advisor

sensor:

  • platform: emerald_ble
    ble_client_id: emerald_advisor
    power:
    name: “Emerald Power”
    energy:
    name: “Emerald Total Energy”
    battery_level:
    name: “Emerald Battery”
    pairing_code: 12xxx3
    pulses_per_kwh: 1000

I can see a new error as well.

Hi Abhiush,

Can you please let me know what firmware your Emerald is running?
You can find it by using a phone app like NRF-connect and bonding with the emerald (you will need to put in your pairing code):


You will have to press the ‘Read Value’ arrow next to the Firmware Revision String to grab it.

Hi WeekendWarrior1,

Kindly find the attached. Also just wondering if emerald can handle multiple connection / pairing etc.

BTW … it is some time randomly getting connected as well. but it still is throwing lots of error messages. Here is the log

INFO Reading configuration /config/esphome/emerald-ble-bridge.yaml...
INFO Starting log output from emerald-ble-bridge.local using esphome API
INFO Successfully connected to emerald-ble-bridge.local
[12:53:08][I][app:102]: ESPHome version 2022.4.0 compiled on May  5 2022, 10:25:01
[12:53:08][C][wifi:491]: WiFi:
[12:53:08][C][wifi:353]:   Local MAC: 08:3A:F2:6E:0F:78
[12:53:08][C][wifi:354]:   SSID: 'Optus_B50550'[redacted]
[12:53:08][C][wifi:355]:   IP Address: 192.xx.xx.xx
[12:53:08][C][wifi:357]:   BSSID: 5C:B1:3E:B5:05:52[redacted]
[12:53:08][C][wifi:358]:   Hostname: 'emerald-ble-bridge'
[12:53:08][C][wifi:360]:   Signal strength: -64 dB ▂▄▆█
[12:53:08][V][wifi:362]:   Priority: 0.0
[12:53:08][C][wifi:364]:   Channel: 1
[12:53:08][C][logger:233]: Logger:
[12:53:08][C][logger:234]:   Level: VERBOSE
[12:53:08][C][logger:235]:   Log Baud Rate: 115200
[12:53:08][C][logger:236]:   Hardware UART: UART0
[12:53:08][C][logger:238]:   Level for 'mqtt.component': DEBUG
[12:53:08][C][logger:238]:   Level for 'mqtt.client': ERROR
[12:53:08][C][emerald_ble:013]: EMERALD
[12:53:08][C][emerald_ble:014]:  Battery 'Emerald Battery'
[12:53:08][C][emerald_ble:014]:    Device Class: 'battery'
[12:53:08][C][emerald_ble:014]:    State Class: ''
[12:53:08][C][emerald_ble:014]:    Unit of Measurement: '%'
[12:53:08][C][emerald_ble:014]:    Accuracy Decimals: 0
[12:53:08][C][emerald_ble:015]:  Power 'Emerald Power'
[12:53:09][C][emerald_ble:015]:    Device Class: 'power'
[12:53:09][C][emerald_ble:016]:  Energy 'Emerald Total Energy'
[12:53:09][C][emerald_ble:016]:    Device Class: 'energy'
[12:53:09][C][emerald_ble:016]:    State Class: 'total_increasing'
[12:53:09][C][emerald_ble:016]:    Unit of Measurement: 'kWh'
[12:53:09][C][emerald_ble:016]:    Accuracy Decimals: 5
[12:53:09][C][esp32_ble_tracker:726]: BLE Tracker:
[12:53:09][C][esp32_ble_tracker:727]:   Scan Duration: 300 s
[12:53:09][C][esp32_ble_tracker:728]:   Scan Interval: 320.0 ms
[12:53:09][C][esp32_ble_tracker:729]:   Scan Window: 30.0 ms
[12:53:09][C][esp32_ble_tracker:730]:   Scan Type: ACTIVE
[12:53:09][C][ble_client:035]: BLE Client:
[12:53:09][C][ble_client:036]:   Address: 30:1b:97:64:39:bb
[12:53:09][C][mdns:084]: mDNS:
[12:53:09][C][mdns:085]:   Hostname: emerald-ble-bridge
[12:53:09][V][mdns:086]:   Services:
[12:53:09][V][mdns:088]:   - _esphomelib, _tcp, 6053
[12:53:09][V][mdns:090]:     TXT: version = 2022.4.0
[12:53:09][V][mdns:090]:     TXT: mac = 083af26e0f78
[12:53:09][V][mdns:090]:     TXT: platform = ESP32
[12:53:09][V][mdns:090]:     TXT: board = esp32dev
[12:53:09][C][ota:085]: Over-The-Air Updates:
[12:53:09][C][api:138]: API Server:
[12:53:09][C][api:139]:   Address: emerald-ble-bridge.local:6053
[12:53:09][C][api:143]:   Using noise encryption: NO
[12:53:40][D][ble_client:047]: Found device at MAC address [30:1B:97:64:39:BB]
[12:53:40][I][ble_client:085]: Attempting BLE connection to 30:1b:97:64:39:bb
[12:53:46][V][ble_client:147]: [30:1b:97:64:39:bb] ESP_GATTC_DISCONNECT_EVT, reason 62
[12:53:46][V][ble_client:115]: [30:1b:97:64:39:bb] ESP_GATTC_OPEN_EVT
[12:53:46][W][ble_client:117]: connect to 30:1b:97:64:39:bb failed, status=133
[12:53:46][D][esp32_ble_tracker:231]: Starting scan...
[12:53:46][D][esp32_ble_tracker:740]: Found device 23:CA:E8:8B:4D:DB RSSI=-45
[12:53:46][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:53:46][D][esp32_ble_tracker:740]: Found device 1F:22:75:93:10:11 RSSI=-82
[12:53:46][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:54:15][D][esp32_ble_tracker:740]: Found device 30:1B:97:63:48:63 RSSI=-78
[12:54:15][D][esp32_ble_tracker:761]:   Address Type: PUBLIC
[12:54:15][D][esp32_ble_tracker:763]:   Name: 'EIAdv 2107126480'
[12:54:54][D][ble_client:047]: Found device at MAC address [30:1B:97:64:39:BB]
[12:54:54][I][ble_client:085]: Attempting BLE connection to 30:1b:97:64:39:bb
[12:55:04][V][ble_client:147]: [30:1b:97:64:39:bb] ESP_GATTC_DISCONNECT_EVT, reason 62
[12:55:04][V][ble_client:115]: [30:1b:97:64:39:bb] ESP_GATTC_OPEN_EVT
[12:55:04][W][ble_client:117]: connect to 30:1b:97:64:39:bb failed, status=133
[12:55:04][D][esp32_ble_tracker:231]: Starting scan...
[12:55:06][D][esp32_ble_tracker:740]: Found device 1F:22:75:93:10:11 RSSI=-85
[12:55:06][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:55:07][D][esp32_ble_tracker:740]: Found device 23:CA:E8:8B:4D:DB RSSI=-45
[12:55:07][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:56:00][D][esp32_ble_tracker:740]: Found device 58:32:EF:08:58:90 RSSI=-43
[12:56:00][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:56:12][D][esp32_ble_tracker:740]: Found device 30:1B:97:64:36:9A RSSI=-85
[12:56:12][D][esp32_ble_tracker:761]:   Address Type: PUBLIC
[12:56:12][D][esp32_ble_tracker:763]:   Name: 'EIAdv 2107126114'
[12:56:23][D][esp32_ble_tracker:740]: Found device 30:1B:97:63:48:63 RSSI=-78
[12:56:23][D][esp32_ble_tracker:761]:   Address Type: PUBLIC
[12:56:23][D][esp32_ble_tracker:763]:   Name: 'EIAdv 2107126480'
[12:57:09][D][ble_client:047]: Found device at MAC address [30:1B:97:64:39:BB]
[12:57:09][I][ble_client:085]: Attempting BLE connection to 30:1b:97:64:39:bb
[12:57:19][V][ble_client:124]: [30:1b:97:64:39:bb] ESP_GATTC_CONNECT_EVT
[12:57:19][V][ble_client:115]: [30:1b:97:64:39:bb] ESP_GATTC_OPEN_EVT
[12:57:25][I][ble_client:220]: auth complete. remote BD_ADDR: 301b976439bb
[12:57:25][V][ble_client:225]: auth success. address type = 0 auth mode = 5
[12:57:25][I][emerald_ble:203]: [30:1b:97:64:39:bb] Writing auto upload code to Emerald
[12:57:25][W][ble_client:177]: No descriptor found for notify of handle 0x15
[12:57:25][W][ble_client:177]: No descriptor found for notify of handle 0x1d
[12:57:29][V][ble_client:139]: cfg_mtu status 0, mtu 23
[12:57:29][E][emerald_ble:148]: [30:1b:97:64:39:bb] ESP_GATTC_WRITE_CHAR_EVT (Write confirmed)
[12:57:29][V][ble_client:164]: [30:1b:97:64:39:bb] ESP_GATTC_SEARCH_CMPL_EVT
[12:57:29][I][ble_client:166]: Service UUID: 0x1800
[12:57:29][I][ble_client:167]:   start_handle: 0x1  end_handle: 0x7
[12:57:29][I][ble_client:380]:  characteristic 0x2A00, handle 0x3, properties 0x12
[12:57:29][I][ble_client:380]:  characteristic 0x2A01, handle 0x5, properties 0x2
[12:57:29][I][ble_client:380]:  characteristic 0x2A04, handle 0x7, properties 0x2
[12:57:29][I][ble_client:166]: Service UUID: 0x1801
[12:57:29][I][ble_client:167]:   start_handle: 0x8  end_handle: 0xb
[12:57:29][I][ble_client:380]:  characteristic 0x2A05, handle 0xa, properties 0x20
[12:57:29][V][ble_client:415]:    descriptor 0x2902, handle 0xb
[12:57:29][I][ble_client:166]: Service UUID: 0x180A
[12:57:29][I][ble_client:167]:   start_handle: 0xc  end_handle: 0x12
[12:57:29][I][ble_client:380]:  characteristic 0x2A29, handle 0xe, properties 0x2
[12:57:29][I][ble_client:380]:  characteristic 0x2A25, handle 0x10, properties 0x2
[12:57:29][I][ble_client:380]:  characteristic 0x2A26, handle 0x12, properties 0x2
[12:57:29][I][ble_client:166]: Service UUID: 0x1910
[12:57:29][I][ble_client:167]:   start_handle: 0x13  end_handle: 0x1a
[12:57:29][I][ble_client:380]:  characteristic 0x2B10, handle 0x15, properties 0x12
[12:57:29][V][ble_client:415]:    descriptor 0x2902, handle 0x16
[12:57:29][I][ble_client:167]:   start_handle: 0x1b  end_handle: 0x1e
[12:57:29][I][ble_client:380]:  characteristic 0x2A19, handle 0x1d, properties 0x12
[12:57:29][V][ble_client:415]:    descriptor 0x2902, handle 0x1e
[12:57:29][I][ble_client:166]: Service UUID: 00010203-0405-0607-0809-0A0B0C0D1912
[12:57:29][I][ble_client:167]:   start_handle: 0x1f  end_handle: 0x22
[12:57:29][I][ble_client:380]:  characteristic 00010203-0405-0607-0809-0A0B0C0D2B12, handle 0x21, properties 0x6
[12:57:29][V][ble_client:415]:    descriptor 0x2901, handle 0x22
[12:57:29][D][esp32_ble_tracker:231]: Starting scan...
[12:57:29][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.21 s).
[12:57:29][V][component:200]: Components should block for at most 20-30ms.
[12:57:29][D][esp32_ble_tracker:740]: Found device 1F:22:75:93:10:11 RSSI=-85
[12:57:29][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:57:30][E][emerald_ble:124]: [30:1b:97:64:39:bb] ESP_GATTC_READ_CHAR_EVT (Received READ)
[12:57:32][D][esp32_ble_tracker:740]: Found device 23:CA:E8:8B:4D:DB RSSI=-46
[12:57:32][D][esp32_ble_tracker:761]:   Address Type: RANDOM
[12:57:33][I][ota:105]: Boot seems successful, resetting boot loop counter.
[12:57:33][D][esp32.preferences:114]: Saving preferences to flash...
[12:57:44][E][emerald_ble:160]: [30:1b:97:64:39:bb] Received Notification
[12:57:44][D][emerald_ble:165]: Recieved time read notification
[12:57:44][D][emerald_ble:058]: DEC(11): 0x0001020a06594cce400000
[12:57:44][I][emerald_ble:080]: Timestamp: , Pulses: 0, Average Watts within interval: 0.000000 W
[12:57:44][V][sensor:074]: 'Emerald Power': Received new state 0.000000
[12:57:44][D][sensor:125]: 'Emerald Power': Sending state 0.00000 W with 5 decimals of accuracy
[12:57:44][V][sensor:074]: 'Emerald Total Energy': Received new state 0.000000
[12:57:44][D][sensor:125]: 'Emerald Total Energy': Sending state 0.00000 kWh with 5 decimals of accuracy
[12:57:44][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.07 s).
[12:57:44][V][component:200]: Components should block for at most 20-30ms.
[12:58:13][E][emerald_ble:160]: [30:1b:97:64:39:bb] Received Notification
[12:58:13][D][emerald_ble:165]: Recieved time read notification
[12:58:13][D][emerald_ble:058]: DEC(11): 0x0001020a06594cce5e0000
[12:58:13][I][emerald_ble:080]: Timestamp: , Pulses: 0, Average Watts within interval: 0.000000 W
[12:58:13][V][sensor:074]: 'Emerald Power': Received new state 0.000000
[12:58:13][D][sensor:125]: 'Emerald Power': Sending state 0.00000 W with 5 decimals of accuracy
[12:58:13][V][sensor:074]: 'Emerald Total Energy': Received new state 0.000000
[12:58:13][D][sensor:125]: 'Emerald Total Energy': Sending state 0.00000 kWh with 5 decimals of accuracy
[12:58:13][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.06 s).
[12:58:13][V][component:200]: Components should block for at most 20-30ms.
[12:58:44][E][emerald_ble:160]: [30:1b:97:64:39:bb] Received Notification
[12:58:44][D][emerald_ble:165]: Recieved time read notification
[12:58:44][D][emerald_ble:058]: DEC(11): 0x0001020a06594cce800000
[12:58:44][I][emerald_ble:080]: Timestamp: , Pulses: 0, Average Watts within interval: 0.000000 W
[12:58:44][V][sensor:074]: 'Emerald Power': Received new state 0.000000
[12:58:44][D][sensor:125]: 'Emerald Power': Sending state 0.00000 W with 5 decimals of accuracy
[12:58:44][V][sensor:074]: 'Emerald Total Energy': Received new state 0.000000
[12:58:44][D][sensor:125]: 'Emerald Total Energy': Sending state 0.00000 kWh with 5 decimals of accuracy
[12:58:44][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.05 s).
[12:58:44][V][component:200]: Components should block for at most 20-30ms.
[12:59:14][E][emerald_ble:160]: [30:1b:97:64:39:bb] Received Notification
[12:59:14][D][emerald_ble:165]: Recieved time read notification
[12:59:14][D][emerald_ble:058]: DEC(11): 0x0001020a06594cce9e0000
[12:59:14][I][emerald_ble:080]: Timestamp: , Pulses: 0, Average Watts within interval: 0.000000 W
[12:59:14][V][sensor:074]: 'Emerald Power': Received new state 0.000000
[12:59:14][D][sensor:125]: 'Emerald Power': Sending state 0.00000 W with 5 decimals of accuracy
[12:59:14][V][sensor:074]: 'Emerald Total Energy': Received new state 0.000000
[12:59:14][D][sensor:125]: 'Emerald Total Energy': Sending state 0.00000 kWh with 5 decimals of accuracy
[12:59:14][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.06 s).
[12:59:14][V][component:200]: Components should block for at most 20-30ms.
[12:59:20][D][esp32_ble_tracker:740]: Found device 30:1B:97:63:48:63 RSSI=-88
[12:59:20][D][esp32_ble_tracker:761]:   Address Type: PUBLIC
[12:59:20][D][esp32_ble_tracker:763]:   Name: 'EIAdv 2107126480'