Poweropti / powerfox powermeter integration

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