Poweropti / powerfox powermeter integration

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?

I havenā€™t tried to block internet access for the Poweropti, but I assume it would work as long as WiFi is available

I can cry. I have the poweropti+ device and I think just the port 443 is open :cry:

@theinl how did you fetch the rpc port in Android? with an app?

I simply checked the Poweropti ip in my Router

I used PCAPdroid. Should work with Wireshark on a machine in the same network, too.
For https you would need to break the SSL encryption. Not possible without tampering with the certificates. Transparent proxy with SSL inspection should work, but this is nothing an average home user has availableā€¦

Have you tried the request with HTTPS instead of http in the resource value?
Maybe the payloads are the same

Pretty sure for the timestamp youā€™ll need a connection to a NTP serverā€¦ Time wonā€™t be synced without.
Not sure how this affects the readings, as we just look at consumption and power.

Timestamp? I donā€™t remember asking about that. All I changed was the scan interval since 10 Seconds is a little too sluggish for my liking. I set it to one second, but on comparing it to my Shelly 3EM I believe there might actually be a hardcoded limit to 3 seconds. Doesnā€™t matter though, thatā€™s still speedy enough.