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
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ā¦
OK, some news
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. 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
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ā¦
Glad it works for you, too
Local fetching is always preferable to cloud Depending on testing with a Powerfox I can make the integration.
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
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
@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.