Poweropti / powerfox powermeter integration

Hi,

I did it this way:

rest:
  - authentication: basic
    username: !secret powerfox_user
    password: !secret powerfox_pw
    scan_interval: 10
    resource: "https://backend.powerfox.energy/api/2.0/my/main/current?unit=kwh"
    sensor:
      - name: "powerfox_all_values"
        value_template: "OK"
        json_attributes:
          - "Watt"
          - "A_Plus"
          - "A_Plus_HT"
          - "A_Plus_NT"
          - "A_Minus"
          - "Timestamp"

this way I get all values ​​as attributes.

Advantage: you only ask 1x against the API.
and then I have individual templates that makes individual sensors out of the attributes:

template:          
  - sensor:
    - name: "powerfox_aktuell"
      state: "{{ state_attr('sensor.powerfox_all_values', 'Watt') }}"
      unit_of_measurement: "Wh"
      device_class: "power"
      state_class: "measurement" 
      unique_id: "123456789987654321"
  - sensor:
    - name: "bezug_powerfox"
      state: "{{ state_attr('sensor.powerfox_all_values', 'A_Plus') }}"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing" 
      unique_id: "12345678998765432"
  - sensor:
    - name: "verkauf_powerfox"
      state: "{{ state_attr('sensor.powerfox_all_values', 'A_Minus') }}"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing" 
      unique_id: "1234567899876543"


With all informations, I can build the Energy-Dachboard:

then it looks like:

6 Likes

it’s said if you don’t pay, you can only get the data locally in the app… thus there must be a way to make it happen but that is also something I am interested in.

hope someone can help out here :slight_smile:

Best, goeste

Is there still interest in making an integration for this? I would like to dive in to see what is possible

1 Like

an integration would be great!

1 Like

Their API documentation is so well described it must be something nice to make, but I could use some help with temporarily accessing powerfox so that I can test whether the data is being fetched correctly.

Hi plaxtika, would you kind enough to tell me where in the home assistant I need to add the script for this to work? Both my powerfox and synology running home assistant are in the same network.

Thank you very much!

Did you ever find out where to add it? I am at the same point currently. Thanks for you help!

Hi there, where exactly did you enter this code? I’m new to home assistant. Thanks for your help!

As there are some problems with the API calls to the powerfox backend currently, I tried to get the data directly from the device.
Took some time to figure it out, but I’m able to read the values now.
Working on integrating that in my ha config now

There’s a local RPC endpoint at http://IP of the device/rpc
All you need is the correct json payload for the RESTful sensor.
Returns json with the result encoded in the value result as base64 string.
Decoding that gives another json with all the data you need

2 Likes

Sounds great, i prefer to use a solution without any cloud connection. That’s why I also switched to a esp8266 meter reader. But using the powerfox hardware directly would be awesome.

And powerfox demands money at some point, in addition to the collected data:
“*ab dem 4. Jahr der Nutzung fällt ein jährliches Entgelt in Höhe von 4,99 € / Jahr (bei Zustimmung zur Information zu Mehrwertdiensten) bzw. 8,99 € / Jahr an. Der Service kann mit einer Frist von 4 Wochen jeweils zum Jahresende gekündigt werden.”

hi Tobias, could you please post your findings till now?
I also want to try… thanks.

hi klaas, sorry the late response.
powerfox makes a lot of problems the last 2 months. so I don’t think am integration through the cloud makes sense now.
but there is a possibility to switch to local data only…

1 Like

OK, some news :slight_smile:
I got it working.

I captured the HTTP Requests that the Android app did when switched to local mode.
As this is HTTP and no HTTPS, the request is readable with a packet sniffer.
Not sure, if this is the same for everyone.

So here’s the code for the RESTful sensor:

rest:
  - resource: http://192.168.x.x/rpc
    method: POST
    payload: '{"id":1,"jsonrpc":"2.0","method":"getConfig","params":{"key":"latest_data"}}'
    scan_interval: 10
    headers:
      Content-Type: application/json
    sensor:
      - name: "poweropti_local"
        json_attributes:
          - "jsonrpc"
          - "id"
          - "result"
        value_template: >
            {% set json = value_json.result | base64_decode %}
            {% set Timestmp = (json | from_json())[0].t %}
            {% set zaehlernummer = (json | from_json())[0].m %}
            {% set A_Plus = (json | from_json())[0].d[0].v %}
            {% set A_Plus_HT = (json | from_json())[0].d[1].v %}
            {% set A_Plus_NT = (json | from_json())[0].d[2].v %}
            {% set A_Minus = (json | from_json())[0].d[3].v %}
            {% set timestmp2 = (json | from_json())[1].t %}
            {% set watt = (json | from_json())[1].d[0].v %}
            {{ '{"Watt":' + (watt | string)  + ',"Timestamp":' + (Timestmp | string)  + ',"A_Plus":' + (((A_Plus | float) / 1000) | string) + ',"A_Minus":' + (((A_Minus | float) / 1000) | string) + '}' }}


As you can see, there are two A_Plus and A_Minus values. I didn’t see any differences. They were the same during my tests. Not sure if this is some kind of error checking.
Just found that those are HT and NT. :wink: Corrected in code

Just set your poweropti IP in resource

I return a json string for the next part (the sensors):

template:
  - sensor:
      - name: "Strom aktuell"
        unit_of_measurement: "W"
        device_class: "power"
        state_class: "measurement"
        state: >
            {{ (states('sensor.poweropti_local')|from_json).Watt }}
      - name: "Strom Bezug"
        unit_of_measurement: "kWh"
        device_class: "energy"
        state_class: "total_increasing"
        state: >
            {{ (states('sensor.poweropti_local')|from_json).A_Plus }}
      - name: "Strom-Netz-Lieferung"
        unit_of_measurement: "kWh"
        device_class: "energy"
        state_class: "total_increasing"
        state: >
            {{ (states('sensor.poweropti_local')|from_json).A_Minus }}

Have fun trying

9 Likes

Can confirm this works perfectly. I changed the scan interval to 1 and now get essentially realtime power values. It might now be even faster than my Shelly 3EM…:thinking:

1 Like

Glad it works for you, too :+1:t2:

1 Like

Local fetching is always preferable to cloud :wink: Depending on testing with a Powerfox I can make the integration.

2 Likes

I tested this in front of the actual meter and saw only minimal delay (maybe 1-2 seconds) and perfect accuracy from what I can tell
Compared to the Shelly, it is (obviously) a bit more accurate but the Shelly is about 1 Second faster to react to changes. I tested by showing both sensors on the dashboard and turning on the Toaster. Saw the uptick in consumption just slightly sooner with the Shelly, but it’s really negligible.
I can’t test reliability or anything yet, but I don’t see any reason for issues…unless Powerfox changes something deliberately.

Works for 8 hours now here.
Just let’s hope they don’t “close” the http backend with an “update” some time.
I changed my former web sensors to the new config, so energy dashboard still has all statistics

Yeah, I messed that up and the stats are now gone from my Energy Dashboard, but it’s Ok. My rooftop solar is only going to arrive next week, so that’s when the stats get interesting

Edit: I managed to get the stats back…all perfect now

1 Like

this sounds great! I will test it tomorrow… to understand: an internet connection is not needed any more, or? so we cut the connection on the router an powerfox can’t change something an the software, right?