Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Powerpal Readings API sensors #2

Open
wants to merge 7 commits into
base: powerpal_ble
Choose a base branch
from

Conversation

azz
Copy link

@azz azz commented Jan 13, 2025

I was getting astronomical figures reported to Powerpal Cloud!

Turned out the "Watt Hours" sensor was off by a factor of my meter pulse rate (3.200) squared. After some quick algebra I realised the calculation inside this module was incorrect.

For reference, my rest_command looks like this:

rest_command:
  send_readings_to_powerpal_cloud:
    url: "https://readings.powerpal.net/api/v1/meter_reading/{{POWERPAL_DEVICE_ID}}"
    method: POST
    headers:
      authorization: "{{POWERPAL_API_KEY}}"
      accept: ""
    payload: >-
       {% set readings = [{
            "is_peak": false, 
            "pulses": states('sensor.powerpal_pulses') | int, 
            "timestamp": now() | as_timestamp | int // 60 * 60,
            "watt_hours": states('sensor.powerpal_watt_hours') | float
        }] %}
        {{ readings | to_json }}
    content_type: 'application/json'
    verify_ssl: true

and I have an automation that kicks off for each change to the "Daily Pulses" sensor:

alias: PowerPal - Send Readings to Cloud
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.powerpal_daily_pulses
    from: null
    enabled: true
conditions: []
actions:
  - action: rest_command.send_readings_to_powerpal_cloud
    metadata: {}
    data: {}
    response_variable: api_response
mode: single

Interestingly, I noticed that the "Powerpal Timestamp" sensor only seems to update every 2-3 minutes, instead of every minute. It appears that while a set of values is produced every minute, sometimes the timestamp in the BLE packet doesn't change, so in my automation I have just used now() | as_timestamp | int // 60 * 60, which seems to do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant