Pixometer integration

Would love to get pixometer data integrated in Home Assistant. As I don’t have enough python experience myself, I was wondering if anyone would have plans to do so? The free app let’s you easily scan and recognize meter reading and upload it into your pixometer account.
I know openHAB has this data integrated, so probably the openHAB approach and code could be used to make the same in Home Assistant?

Will also look forward into this topic to learn develop my own first custom integration, but for sure all assistant would be welcome :wink:

Update 01/23: I can’t change the ‘Solution’ reply of this topic, so just updating in here: my custom HACS integration is now available, see GitHub - myTselection/pixometer: Home Assistant custom component HACS for Pixometer app meter reading integration.

It seems according to the openhab page that it’s an API.
So a rest sensor could probably work

Hi, thx for your input! yes indeed, after some searching on openHab forum, found some pointer to the API.
https://pixometer.io/api/v1/

Will search a bit urther to get authentication config with rest sensor.

Update 01/2023: below manual solution became obsolete as I have now created a custom integration that facilitates this, see: GitHub - myTselection/pixometer: Home Assistant custom component HACS for Pixometer app meter reading integration.

Found some time to look into this, if anyone interested, see below. Feel free to suggest improvements, still trying out myself…

configuration.yaml:

sensor:
  - platform: rest
    name: Pixometer Token
    method: POST
    resource: https://pixometer.io/api/v1/access-token/
    payload: !secret pixometer_credentials
    scan_interval: 3600
    value_template: '{{"Bearer "+ value_json.access_token}}'
    headers:
      Content-Type: application/json
  - platform: rest
    name: Pixometer Electricity
    resource: https://pixometer.io/api/v1/readings/?meter_id=XXXXXXXX&o=-created
    headers:
        Authorization: '{{states("sensor.pixometer_token")}}'
    json_attributes:
      - results
    value_template: "{{ value_json.results[0].value }}"
    device_class: energy
    unit_of_measurement: "kWh"


utility_meter:
  energy:
    source: sensor.pixometer_electricity
    cycle: daily
    net_consumption: true

Updated my post to automatically fetch the access token with a separate rest sensor ‘Pixometer Token’, as this access token has limited time to live.

MyT, thanks a lot for digging into it.

If I try this, I get the log entry Template variable error: list object has no element 0 when rendering '{{ value_json.results[0].value }}. If I try the REST resource url of the meter reading in my Firefox Rested Addon, I get the following result

{
  "count": 0,
  "next": null,
  "previous": null,
  "results": []
}

It seems, the reading list is empty. However, if I browse the Pixometer Django API sites, there the full list is visible. At least a list that covers all meters, i.e., the result of https://pixometer.io/api/v1/readings/ without further arguments.

Any hints on this?

Another question: Why do you need the additional template sensor? The value of the reading is already stored in the rest sensor, isn’t it?

Cheers,
Micha

are you sure the meter is set correctly in the url? see https://pixometer.io/api/v1/meters/ meterid can also be found on this site: https://pixometer.io/portal/#/meters/list

true, I do some further calculations on it which I removed in the post, but for simple use it’s indeed not needed. I’ll remove it to simplify it in my original post

I checked the IDs several times and tried different ones. No success.
What is the parameter o=-created actually good for?

If reading the full list works, could I iterate through it and query the meter IDs in if-else statements - in a template expression?

Ordering, to make sure the latest reading is on top so it can be fetched at index 0

I have now created a custom component that can be integrated with HACS. For now, the repo is not registered as a standard HACS repo yet, so for now the repo is still to be added manually.
All info and instructions: GitHub - myTselection/pixometer: Home Assistant custom component HACS for Pixometer app meter reading integration.

Is this just for Energy, or can you use this is on water meters?

The app can scan (manually) scan any meter type by holding the camera in front of the meter. All the meters registered in your pixometer account are integrated in HA with this integration.

cool thanks!

cant use the app in Australia by the looks of it