Skip to content

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.

@var-au
Copy link

var-au commented Apr 22, 2025

LGTM, code works, Datetime workaround as per PR comments seems to work well to

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.

2 participants