OH3: HTTP-Binding Powerfox Smartmeter

Hi everyone,

I have installed a Powerfox poweropti on my electric meter to read the consumption etc. I have set everything up and can read the current power consumption. But now I’m trying to read the monthly values to display them in a chart. I’ve added a new channel to my meter thing and created an item for the monthly values. The item always reads UNDEF.

Here’s the code of the thing:

UID: http:url:xxxxxxxxxx
label: Stromzähler
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: https://backend.powerfox.energy/api/2.0/my
  password: xxxxxxxxx
  refresh: 3
  commandMethod: GET
  contentType: application/json
  timeout: 3000
  username: xxxxxxxxxxxxxxxx
  bufferSize: 2048
location: Keller
channels:
  - id: Stromzaehler_AktuellerLeistungswert
    channelTypeUID: http:number
    label: Aktueller Leistungswert
    description: ""
    configuration:
      stateExtension: /main/current
      stateTransformation: JSONPATH:$.Watt
  - id: MonatlicheVerbrauch
    channelTypeUID: http:number
    label: Monatliche Verbrauch
    description: ""
    configuration:
      stateExtension: all/report?year=2021
      stateTransformation: JSONPATH:$.Consumption.ReportValues[*].Delta

The Stromzaehler_AktuellerLeistungswert channel works correctly and retrieves the correct value. The MonatlicheVerbrauch channel should retrieve all the available monthly values.

If I open https://backend.powerfox.energy/api/2.0/my/all/report?year=2021 in my browser I get the following:

{
"Consumption": {
"StartTime": 1619545500,
"Sum": 160.706,
"Max": 120.64399999999998,
"MaxCurrency": 30.157078533333326,
"ReportValues": [
{
"Delta": 120.64399999999998,
"DeltaCurrency": 30.157078533333326,
"Timestamp": 1619820000,
"Complete": true
},
{
"Delta": 40.06200000000001,
"DeltaCurrency": 10.15344376666667,
"Timestamp": 1617228000,
"Complete": true
}
],
"SumCurrency": 40.310522299999995
},

Delta holds the values I’m trying to retrieve. So is the state transformation correct? stateTransformation: JSONPATH:$.Consumption.ReportValues[*].Delta

Or do I have to do something differently since I’m retrieving two values?

Thanks for any assistance.

Rob

How are you expecting to represent two number values in one number channel?
Really that doesn’t matter, because the JSONPATH transformation can only return a single string, not a real array.

It’s usually smart to experiment with a string type channel to begin with, then you can see what is coming out of your transform even if it is not strictly numeric. You’re probably getting a string like “[120.6, 40.6]”.

1 Like

I switched to a string and hey it works. I was thinking in the right direction, but many thanks for your help and the tip.

Rob

Do let us know your eventual solution, for later readers.

Hi rossko57,

I will definitely post my solution as it is not as easy as I thought it would be, or I’m just not thinking in the right direction. Do you have any pointers for me? I need to get the monthly values into an item that stores the values in persistence. Once a month is enough. At the end of each month the Delta value is at its maximum. Do I have to do this via a time-based rule that triggers at midnight every month?

Any rough pointer would be greatly appreciated. I haven’t found a helpful example so far. Still searching though.

Regards,

Rob

I’ve no idea what your data means. From an outsiders view, you’ve multiple identically-named data elements with different timestamps. What do you need to extract?

Might be some relevant stuff here

I need to extract the Deltas = energy consumption per month. So for example, "Delta": 40.06200000000001 shows the cumulative consumption at the end of last month. Therefore, it is will now never change as it represents the final value for the last month. The "Delta": 127.49199999999996 is the difference between the consumption from last month and the current month. So I want to store the value at the end of each month and display these in a nice chart. In June there will obviously be three Delta values. So I don’t have to calculate anything. Just store the date on a monthly basis.

I’ll take a look at your link ASAP.

HTH

Rob

Okay, so there are many ‘Delta’ values. How can you know which is what? You have to use the associated timestamp.
So to get any meaning from Delta you have to also get its associated timestamp, and keep the association. It’s no good jumbling this Delta with that timestamp.

Which means extracting the data at the channel is useless here; isolated single chunks of data is no use.

Process the JSON in a rule, as per the linked example. It won’t be easy.

There might be a fingers-crossed cheat, just get all the Deltas and assume the biggest one is the most recent one.

Hi @Robert_Bevington

hope you meanwhile managed to get the relevant data :slight_smile:

Do you also have extracted current data into items? I am looking to identify when iam feeding power from my solar panel back into the provider network - to enable elements like washing machine or others to kick off running.

Cheers
Karsten