Weird. I just checked home assistant and values are starting to come in!! Sweet. Once again excellent work on this
Thanks for the response.
I tried adding this but its giving error on validation. Perhaps i am doing something wrongâŚ
Apologies, it actually needs to be nested in the configuration of the specific sensor, not the root component:
sensor:
- platform: emerald_ble
ble_client_id: emerald_advisor
power:
name: "Emerald Power"
force_update: true
energy:
name: "Emerald Total Energy"
battery_level:
name: "Emerald Battery"
pairing_code: 123123
pulses_per_kwh: 1000
Yes. My 2 cents is that we are relying on powerpal the hardware to capture data. If powerpal runs out of battery, our project wonât work if we donât have it replaced. So, if the data stream continues even we take on this project, weâll have more persuason to get powerpal the company to have it replaced.
I was looking for projects on capturing power consumptions and I was about to start on Klaas Schouteâs Home Assistant Glow project, I stumbled upon this thread and lurked for couple of weeks. I decided Iâll hop onto this but I have no experience on esphome (I am a tasmota user with around 6 flashed devices). It took me 5 days to successfully (I think) flash the first esphome with WeekendWarrior1âs external component (wasted time on serial port driver problem and no git on my machines etc). I called mine âpowerpalmateâ. I could see it in Home Assistant integration tab now and I could see it as enabled. However, I could not see those 3 entities in âDeveloper Tools/Statesâ - âPowerpal Powerâ, âPowerpal Total Energyâ and âPowerpal Batteryâ. Am I missing something? How do I know I indeed sucessfully flashed and configured properly in HA? Hope some one could give me some ideas. The following is my powerpalmate.yaml:
esphome:
name: powerpalmate
esp32:
board: esp32dev
framework:
type: arduino
external_components:
- source: github://WeekendWarrior1/esphome@powerpal_ble
components: [ ble_client, powerpal_ble ]
api:
ota:
wifi:
ssid: "my_wireless_ssid"
password: "my_password"
ap:
ssid: "powerpalmate Fallback Hotspot"
password: "my_fallback_secret"
manual_ip:
static_ip: my_powerpalmate_addr
gateway: my_gateway
subnet: my_subnet_mask
esp32_ble_tracker:
ble_client:
- mac_address: got_it_from_
id: powerpal
sensor:
- platform: powerpal_ble
ble_client_id: powerpal
power:
name: "Powerpal Power"
energy:
name: "Powerpal Total Energy"
battery_level:
name: "Powerpal Battery"
pairing_code: my_pairing_code
notification_interval: 1
pulses_per_kwh: 800
Hi possum,
Your yaml looks good to me.
Perhaps you could add the logger component to your esphome device yaml: Logger Component â ESPHome
logger:
level: DEBUG
And then however you ran esphome to flash your device (esphome upload powerpalmate.yaml
?), you can run it with the logs
command instead (esphome logs powerpalmate.yaml
), and hopefully you may get greater insight into any issues there are between your esp32 and HA
Good point!
I have figured/planned out the features I need to develop to get the esphome powerpal uploading data to the cloud in an easy to configure manner, and I should have it complete in the coming days.
I have put together a little script that should be able to retrieve your Powerpal device ID and Authorization API key from the Powerpal directly, without having to mess around with the MITM proxy stuff or asking permission from Powerpal directly:
I would really appreciate it if some people could help test it out for me!
Requirements:
- Needs to be run on a computer with bluetooth
- Should work on Linux/Windows/Mac, but I have only tested it on Linux
- Python3.2 or newer installed
Running it:
Clone the repo: git clone https://github.com/WeekendWarrior1/powerpal_ble.git
cd powerpal_ble/auth_extraction
pip install bleak
python3 retrieve_api_key.py
Just managed to set up a Powerpal at my new place and came across this thread. Tried out your PY script to grab the authentication key on my VM running HassOS but it threw this error:
Connected: True
Traceback (most recent call last):
File "/config/powerpalauthkey.py", line 68, in <module>
asyncio. run(main((sys.argv[1] if len(sys.argv) >= 2 else None), (sys.argv[2] if len(
sys argv) 3 else None
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in
run
return loop. run_unt il_complete(main)
File "/usr/lib/python3 .9/asyncio/base-events.py", line 642, in run-until- complete
return future.result ()
File "/config/powerpalauthkey.py", line 31, in main
paired
await client pair(2)
File "/usr/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 479
in pair
assert-reply(reply)
File "/usr/lib/python3.9/site-packages/bleak/backends/bluezdbus/utils.py", line 23, i
n assert-reply
raise BleakDBusError (reply.error-name, reply.body)
bleak.exc . BleakDBusError: [org.bluez .Error . AuthenticationFailed] Authentication Failed
Not sure what any of it means. I am currently running the passive BLE integration to pull data from my Xiaomi temp/humidity sensors and sensor lights so this might be interfering? Not sure?
Has anyone managed to get direct integration via BLE and a bluetooth dongle working? Not really interested in purchasing a ESP32 to grab the data and cloud-based integration⌠well prefer not to have to send the data only to pull it back down again via the cloud.
Hi JJW.AU, thanks so much for trying the script for me, and thanks for the error logs. I wonder if this is something I need to address on headless systems, since for me on Gnome I think I had an OS pairing prompt appear. Something for me to investigate. I donât believe your passive BLE integration was interfering.
In theory, yes, a custom HASS component could likely be put together to connect to a Powerpal now that I have reverse engineered the BLE protocol, but here a few of my thoughts on the matter:
- Python (and other language) BLE libraries seem to be a bit mediocre, through what seems to be no fault of their own. (It seems building software libraries targetting windows, linux and Mac bluetooth/ble stacks is not easy)
- It seems it is not recommended to build HASS components that connect to bluetooth devices (the Powerpal doesnât send itâs measurement data in itâs advertisement packets like the LYWSD03MMC do)
- To paint a clearer picture of possible issues, the script you ran from your VM is probably a good candidate of a prototype HASS component (uses python BLE to connect + authenticate, write and read values) and it looks like there may be issues around Bluez/Bleak auth.
- An esp32 with the ESPHome components I have built âjust worksâ for < $10 AU, seems hard to beat
- At the end of the day (and I hope this doesnât sound rude), Iâm not really interested in debugging peopleâs OS bluetooth device and driver issues
So whilst I also agree that it would be neater from a data perspective to pull it in directly through HASS instead of using another (albeit cheap and low power) device to retrieve it and pass it on, from a software perspective it seems to be a headache.
Cool makes sense. Given that the ESP32 is so cheap I should probably buy some to play with. The integration with Home Assistant seems easy enough. But using PowerPal seems redundant as you could probably just wire up a LDR to the ESP and script it to count pulses directly?
IMO diy ESP pulse_counter energy meter solutions all have one major failing, powering the ESP device. Iâm not a sparky so itâs not legal to do my own 230VAC â 5VDC inside the meter box, and I donât have a mains socket anywhere near my meter box to place a USB charger.
Powerpal/Emerald conveniently have battery lives of >5 years and are free from the VIC government
True. Didnât think of that. Not sure how power hungry the ESP32 is but I wonder if it would last a while if run off 3AA batteries or maybe 4 NiMH ? Maybe a small solar panel to top up the batteries too
Unfortunately, ESPâs are nearly always terrible on battery, they just suck so much juice compared to battery-life focus designed MCUs. You can conserve battery by deep sleeping them, but since you need to be counting pulses I donât think you will be able to sleep it low enough (you could use the esp32 ULP to count the pulses but thatâs quite complicated, I think that requires writing some code in assembly?)
I have added powerpal cloud upload functionality to the ESPHome component!
It retrieves your powerpal apikey from the powerpal, and stores 15 measurements before uploading them all at once.
logger:
level: VERBOSE
# required even if you're not using the powerpal_cloud_uploader
http_request:
id: powerpal_cloud_uploader
esp32_ble_tracker:
ble_client:
- mac_address: DF:5C:55:01:02:03
id: powerpal
sensor:
- platform: powerpal_ble
ble_client_id: powerpal
power:
name: "Powerpal Power"
energy:
name: "Powerpal Total Energy"
battery_level:
name: "Powerpal Battery"
pairing_code: 123123
notification_interval: 1
pulses_per_kwh: 1000
http_request_id: powerpal_cloud_uploader
cost_per_kwh: 0.1872 #dollars per kWh
# powerpal_device_id: 0000abcd #optional, component will retrieve from your Powerpal if not set
# powerpal_apikey: 4a89e298-b17b-43e7-a0c1-fcd1412e98ef #optional, component will retrieve from your Powerpal if not set
Currently it doesnât support on_peak
being toggled, (and is set to false
), so perhaps do not use this if you use the peak/not peak functionality of the app.
Best to keep logging on in case anything doesnât work, thanks.
Thanks @WeekendWarrior1 for the emerald integration. I now have it working and home assistant showing the data.
Have you made any progress on the daily total energy ntp idea? Cheers!
How to do this? I have downloaded the csv but can you tell mw how do I import this file to influxDB and show it in Grafana?
Iâm struggling to find my Powerpalâs mac address. Itâs not showing up in either esp32_ble_tracker or using the nRF Connect app on my iPhone. In both cases, it is picking up a device called âElAdv 2107015912â, but I assume thatâs a neighbourâs Emerald Advisor rather than my Powerpal (mine does say Powerpal on the bottom). My iPhone and iPad can connect to it, and I have killed both the apps just in case. Does the Powerpal mac always start with âDF:5C:55â? I have none that match that, and Iâm standing right beside it. Any ideas?
Hi Michael,
Could you take a quick look on the sticker on the base of your powerpal?
I think the MAC address is documented there.
After a bit of a delay, the Daily Energy Sensor functionality is now complete for both the Emerald and the Powerpal.
You can use it by adding a time component (not 100% required as the components will fall back to the timestamps supplied to them on measurement updates from the devices, but highly recommended because of things like daylight savings), and a daily_energy
sensor to your yaml:
time:
- platform: homeassistant
id: homeassistant_time
sensor:
- platform: emerald_ble/powerpal_ble
...
daily_energy:
name: "Emerald/Powerpal Daily Energy"
...
time_id: homeassistant_time
Havenât been able to test the Powerpal component very well, so please let me know of any errors or if it fails to reset.