Hauptmenü

HTTPMOD - JSON - ENPHASE

Begonnen von petitpunch, 07 Juli 2022, 12:58:44

Vorheriges Thema - Nächstes Thema

petitpunch

Hello,
i'm using Fhem since a while to control my house equipment (ZWAVE+KNX+HUE+ALEXA).

Today, i would like to parse data of my enphase solar panels. I can access to a json page with this data:


   {
   "production":[
      {
         "type":"inverters",
         "activeCount":7,
         "readingTime":1657190710,
         "wNow":544,
         "whLifetime":600913
      },
      {
         "type":"eim",
         "activeCount":0,
"measurementType":"production",
         "readingTime":1657190870,
         "wNow":-247.697,
         "whLifetime":0.0,
         "varhLeadLifetime":0.0,
         "varhLagLifetime":0.0,
         "vahLifetime":0.0,
         "rmsCurrent":1.993,
         "rmsVoltage":233.433,
         "reactPwr":237.304,
         "apprntPwr":382.255,
         "pwrFactor":-0.64,
         "whToday":0.0,
         "whLastSevenDays":0.0,
         "vahToday":0.0,
         "varhLeadToday":0.0,
         "varhLagToday":0.0,
         "lines":[
            {
               "wNow":-248.028,
               "whLifetime":0.0,
               "varhLeadLifetime":0.0,
               "varhLagLifetime":0.0,
               "vahLifetime":0.0,
               "rmsCurrent":1.647,
               "rmsVoltage":232.066,
               "reactPwr":237.304,
               "apprntPwr":381.782,
      ../..


(wNow is more than one time in this json but only the first is usefull)

I have used this code to retrieve the value of "wNow"   (production in realtime).


define ENPHASE HTTPMOD http://192.168.1.161/production.json?details=1 60\

setuuid ENPHASE 62c570b4-f33f-266d-54cd-8d2c41346a820026
attr ENPHASE userattr get01JSON get01Regex getData requestHeader stateFormat
attr ENPHASE enableCookies 1
attr ENPHASE icon measure_photovoltaic_inst
attr ENPHASE reading01JSON production
attr ENPHASE requestHeader1 Content-Type: application/json
attr ENPHASE requestHeader2 Accept: */*
attr ENPHASE room ENERGIE
attr ENPHASE stateFormat production-4 Watts/h



it is working but not clean at all.

this code read too much data :


production-1
production-10
production-11
production-12
production-13
production-14
../..
production-4
production-41
produ ../..


I could not log this to do a graph, this too heavy to storage and useless.

Could you help me to select only  production-4 ?  (wNow).

Other question...   could you help me to calculate and display in stateFormat the wNow in Kwh ?  (the value is displayed in watts).

Thank you


yersinia

#1
This is not a reply with a HTTPMOD solution - you might want to consider using JsonMod instead as the source is json format.

Below a raw proposal
defmod enphaseJM JsonMod http://192.168.1.161/production.json?details=1
attr enphaseJM interval 0 */2 * * *
attr enphaseJM readingList single(jsonPath('$.production.[3].wNow'), 'wNow', '-?-');;
attr enphaseJM stateFormat { my $ret ="";;\
  $ret .= sprintf("%.3f", (ReadingsNum($name,"wNow",0) / 1000));;\
  $ret .= " kWh";;\
  return $ret;;\
}
attr enphaseJM webCmd reread
attr enphaseJM room ENERGIE

It should generate one reading wNow of the fourth production array element (counting starts at 0).

Interval is every second minute:
attr enphaseJM interval */2 * * * *

stateFormat devides wNow by 1000 and shortens to two decimal places:
  $ret .= sprintf("%.3f", (ReadingsNum($name,"wNow",0) / 1000));;\

JsonMod does not have that many features as HTTPMOD so it can be not the proper solution for your case. But imho it is worth a try.

And, btw, next time please use code tags when pasting code - the #-button above the text input field.
viele Grüße, yersinia
----
FHEM 6.3 (SVN) on RPi 4B with RasPi OS Bullseye (perl 5.32.1) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

petitpunch

Hello Yersinia,

thank you for your solution.
i have tried it but there is a problem with it.

here is the msg:


API_LAST_MSG
invalid server response
API_LAST_RES
1657228705.22904
DEF
http://192.168.1.161/production.json?details=1
FUUID
62c74d3b-f33f-266d-7bb4-747177de0c76f979
NAME
enphaseJM
NEXT
2022-07-08 02:00:00
NR
917
SOURCE
http://192.168.1.161/production.json?details=1 (400)
STATE
???
SVN
24783 2021-07-21 22:37:12 UTC
TYPE
JsonMod

yersinia

#3
It seems that the request is not yet correct, returned status code is 400:
http://192.168.1.161/production.json?details=1 (400)
You may need to add httpheaders:
attr enphaseJM httpHeader Content-Type: application/json

defmod enphaseJM JsonMod http://192.168.1.161/production.json?details=1
attr enphaseJM interval 0 */2 * * *
attr enphaseJM readingList single(jsonPath('$.production.[3].wNow'), 'wNow', '-?-');;
attr enphaseJM stateFormat { my $ret ="";;\
  $ret .= sprintf("%.3f", (ReadingsNum($name,"wNow",0) / 1000));;\
  $ret .= " kWh";;\
  return $ret;;\
}
attr enphaseJM webCmd reread
attr enphaseJM httpHeader Content-Type: application/json
attr enphaseJM room ENERGIE


Do you need to provide credentials?
Can you reach the Json source from a browser as well?
viele Grüße, yersinia
----
FHEM 6.3 (SVN) on RPi 4B with RasPi OS Bullseye (perl 5.32.1) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

petitpunch



Hi,  better but the value of wNow is incorrect.
I think this is the result of readingTime perhaps: 

readingTime":1657278359,"wNow":1665,"


here is the result displayed:


API_LAST_MSG 200
API_LAST_RES 1657278336.83895
DEF http://192.168.1.161/production.json?details=1
FUUID 62c80f53-f33f-266d-d9ed-470ec85b9eae22fc
NAME enphaseJM
NEXT 2022-07-08 14:00:00
NR 919
SOURCE http://192.168.1.161/production.json?details=1 (200)
STATE 0.000 kWh
SVN 24783 2021-07-21 22:37:12 UTC
TYPE JsonMod
eventCount 23


i give you the full json page :


{"production":[{"type":"inverters","activeCount":7,"readingTime":1657278359,"wNow":1665,"whLifetime":615125},{"type":"eim","activeCount":0,"measurementType":"production","readingTime":1657278454,"wNow":-889.221,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":7.348,"rmsVoltage":232.416,"reactPwr":1354.887,"apprntPwr":1618.507,"pwrFactor":-0.55,"whToday":0.0,"whLastSevenDays":0.0,"vahToday":0.0,"varhLeadToday":0.0,"varhLagToday":0.0,"lines":[{"wNow":-889.584,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":7.001,"rmsVoltage":231.049,"reactPwr":1354.887,"apprntPwr":1618.033,"pwrFactor":-0.55,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0},{"wNow":0.363,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":0.347,"rmsVoltage":1.367,"reactPwr":0.0,"apprntPwr":0.474,"pwrFactor":0.0,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0}]}],"consumption":[{"type":"eim","activeCount":0,"measurementType":"total-consumption","readingTime":1657278454,"wNow":-2654.253,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":-3.621,"rmsVoltage":238.501,"reactPwr":-3088.573,"apprntPwr":-863.504,"pwrFactor":-1.0,"whToday":0.0,"whLastSevenDays":0.0,"vahToday":0.0,"varhLeadToday":0.0,"varhLagToday":0.0,"lines":[{"wNow":-2653.611,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":-3.809,"rmsVoltage":231.157,"reactPwr":-3088.573,"apprntPwr":-880.564,"pwrFactor":-1.0,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0},{"wNow":0.363,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":0.347,"rmsVoltage":3.682,"reactPwr":-0.0,"apprntPwr":1.277,"pwrFactor":0.28,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0},{"wNow":-1.004,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":-0.158,"rmsVoltage":9.344,"reactPwr":0.0,"apprntPwr":-1.477,"pwrFactor":-1.0,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0}]},{"type":"eim","activeCount":0,"measurementType":"net-consumption","readingTime":1657278454,"wNow":-1765.032,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":10.968,"rmsVoltage":244.586,"reactPwr":-1733.686,"apprntPwr":2496.852,"pwrFactor":-0.7,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0,"lines":[{"wNow":-1764.028,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":10.81,"rmsVoltage":231.265,"reactPwr":-1733.686,"apprntPwr":2495.701,"pwrFactor":-0.7,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0},{"wNow":0.0,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":-0.0,"rmsVoltage":5.997,"reactPwr":0.0,"apprntPwr":0.0,"pwrFactor":-1.0,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0},{"wNow":-1.004,"whLifetime":0.0,"varhLeadLifetime":0.0,"varhLagLifetime":0.0,"vahLifetime":0.0,"rmsCurrent":0.158,"rmsVoltage":7.324,"reactPwr":0.0,"apprntPwr":1.151,"pwrFactor":-1.0,"whToday":0,"whLastSevenDays":0,"vahToday":0,"varhLeadToday":0,"varhLagToday":0}]}],"storage":[{"type":"acb","activeCount":0,"readingTime":0,"wNow":0,"whNow":0,"state":"idle"}]}


thank you for your help.

yersinia

#5
When you try to set readingsList with complete(); it will show everything - this helps at the beginning:
attr enphaseJM readingList complete();;
Then you are able to narrow it down to the values you are interested in; here list of found readings based on Json data you provided:
READINGS:
     2022-07-08 13:13:51   consumption.0.activeCount 0
     2022-07-08 13:13:51   consumption.0.apprntPwr -863.504
     2022-07-08 13:13:51   consumption.0.lines.0.apprntPwr -880.564
     2022-07-08 13:13:51   consumption.0.lines.0.pwrFactor -1
     2022-07-08 13:13:51   consumption.0.lines.0.reactPwr -3088.573
     2022-07-08 13:13:51   consumption.0.lines.0.rmsCurrent -3.809
     2022-07-08 13:13:51   consumption.0.lines.0.rmsVoltage 231.157
     2022-07-08 13:13:51   consumption.0.lines.0.vahLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.0.vahToday 0
     2022-07-08 13:13:51   consumption.0.lines.0.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.0.varhLagToday 0
     2022-07-08 13:13:51   consumption.0.lines.0.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.0.varhLeadToday 0
     2022-07-08 13:13:51   consumption.0.lines.0.wNow -2653.611
     2022-07-08 13:13:51   consumption.0.lines.0.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.0.lines.0.whLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.0.whToday 0
     2022-07-08 13:13:51   consumption.0.lines.1.apprntPwr 1.277
     2022-07-08 13:13:51   consumption.0.lines.1.pwrFactor 0.28
     2022-07-08 13:13:51   consumption.0.lines.1.reactPwr 0
     2022-07-08 13:13:51   consumption.0.lines.1.rmsCurrent 0.347
     2022-07-08 13:13:51   consumption.0.lines.1.rmsVoltage 3.682
     2022-07-08 13:13:51   consumption.0.lines.1.vahLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.1.vahToday 0
     2022-07-08 13:13:51   consumption.0.lines.1.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.1.varhLagToday 0
     2022-07-08 13:13:51   consumption.0.lines.1.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.1.varhLeadToday 0
     2022-07-08 13:13:51   consumption.0.lines.1.wNow 0.363
     2022-07-08 13:13:51   consumption.0.lines.1.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.0.lines.1.whLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.1.whToday 0
     2022-07-08 13:13:51   consumption.0.lines.2.apprntPwr -1.477
     2022-07-08 13:13:51   consumption.0.lines.2.pwrFactor -1
     2022-07-08 13:13:51   consumption.0.lines.2.reactPwr 0
     2022-07-08 13:13:51   consumption.0.lines.2.rmsCurrent -0.158
     2022-07-08 13:13:51   consumption.0.lines.2.rmsVoltage 9.344
     2022-07-08 13:13:51   consumption.0.lines.2.vahLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.2.vahToday 0
     2022-07-08 13:13:51   consumption.0.lines.2.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.2.varhLagToday 0
     2022-07-08 13:13:51   consumption.0.lines.2.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.2.varhLeadToday 0
     2022-07-08 13:13:51   consumption.0.lines.2.wNow -1.004
     2022-07-08 13:13:51   consumption.0.lines.2.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.0.lines.2.whLifetime 0
     2022-07-08 13:13:51   consumption.0.lines.2.whToday 0
     2022-07-08 13:13:51   consumption.0.measurementType total-consumption
     2022-07-08 13:13:51   consumption.0.pwrFactor -1
     2022-07-08 13:13:51   consumption.0.reactPwr -3088.573
     2022-07-08 13:13:51   consumption.0.readingTime 1657278454
     2022-07-08 13:13:51   consumption.0.rmsCurrent -3.621
     2022-07-08 13:13:51   consumption.0.rmsVoltage 238.501
     2022-07-08 13:13:51   consumption.0.type eim
     2022-07-08 13:13:51   consumption.0.vahLifetime 0
     2022-07-08 13:13:51   consumption.0.vahToday 0
     2022-07-08 13:13:51   consumption.0.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.0.varhLagToday 0
     2022-07-08 13:13:51   consumption.0.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.0.varhLeadToday 0
     2022-07-08 13:13:51   consumption.0.wNow -2654.253
     2022-07-08 13:13:51   consumption.0.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.0.whLifetime 0
     2022-07-08 13:13:51   consumption.0.whToday 0
     2022-07-08 13:13:51   consumption.1.activeCount 0
     2022-07-08 13:13:51   consumption.1.apprntPwr 2496.852
     2022-07-08 13:13:51   consumption.1.lines.0.apprntPwr 2495.701
     2022-07-08 13:13:51   consumption.1.lines.0.pwrFactor -0.7
     2022-07-08 13:13:51   consumption.1.lines.0.reactPwr -1733.686
     2022-07-08 13:13:51   consumption.1.lines.0.rmsCurrent 10.81
     2022-07-08 13:13:51   consumption.1.lines.0.rmsVoltage 231.265
     2022-07-08 13:13:51   consumption.1.lines.0.vahLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.0.vahToday 0
     2022-07-08 13:13:51   consumption.1.lines.0.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.0.varhLagToday 0
     2022-07-08 13:13:51   consumption.1.lines.0.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.0.varhLeadToday 0
     2022-07-08 13:13:51   consumption.1.lines.0.wNow -1764.028
     2022-07-08 13:13:51   consumption.1.lines.0.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.1.lines.0.whLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.0.whToday 0
     2022-07-08 13:13:51   consumption.1.lines.1.apprntPwr 0
     2022-07-08 13:13:51   consumption.1.lines.1.pwrFactor -1
     2022-07-08 13:13:51   consumption.1.lines.1.reactPwr 0
     2022-07-08 13:13:51   consumption.1.lines.1.rmsCurrent 0
     2022-07-08 13:13:51   consumption.1.lines.1.rmsVoltage 5.997
     2022-07-08 13:13:51   consumption.1.lines.1.vahLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.1.vahToday 0
     2022-07-08 13:13:51   consumption.1.lines.1.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.1.varhLagToday 0
     2022-07-08 13:13:51   consumption.1.lines.1.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.1.varhLeadToday 0
     2022-07-08 13:13:51   consumption.1.lines.1.wNow 0
     2022-07-08 13:13:51   consumption.1.lines.1.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.1.lines.1.whLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.1.whToday 0
     2022-07-08 13:13:51   consumption.1.lines.2.apprntPwr 1.151
     2022-07-08 13:13:51   consumption.1.lines.2.pwrFactor -1
     2022-07-08 13:13:51   consumption.1.lines.2.reactPwr 0
     2022-07-08 13:13:51   consumption.1.lines.2.rmsCurrent 0.158
     2022-07-08 13:13:51   consumption.1.lines.2.rmsVoltage 7.324
     2022-07-08 13:13:51   consumption.1.lines.2.vahLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.2.vahToday 0
     2022-07-08 13:13:51   consumption.1.lines.2.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.2.varhLagToday 0
     2022-07-08 13:13:51   consumption.1.lines.2.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.2.varhLeadToday 0
     2022-07-08 13:13:51   consumption.1.lines.2.wNow -1.004
     2022-07-08 13:13:51   consumption.1.lines.2.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.1.lines.2.whLifetime 0
     2022-07-08 13:13:51   consumption.1.lines.2.whToday 0
     2022-07-08 13:13:51   consumption.1.measurementType net-consumption
     2022-07-08 13:13:51   consumption.1.pwrFactor -0.7
     2022-07-08 13:13:51   consumption.1.reactPwr -1733.686
     2022-07-08 13:13:51   consumption.1.readingTime 1657278454
     2022-07-08 13:13:51   consumption.1.rmsCurrent 10.968
     2022-07-08 13:13:51   consumption.1.rmsVoltage 244.586
     2022-07-08 13:13:51   consumption.1.type eim
     2022-07-08 13:13:51   consumption.1.vahLifetime 0
     2022-07-08 13:13:51   consumption.1.vahToday 0
     2022-07-08 13:13:51   consumption.1.varhLagLifetime 0
     2022-07-08 13:13:51   consumption.1.varhLagToday 0
     2022-07-08 13:13:51   consumption.1.varhLeadLifetime 0
     2022-07-08 13:13:51   consumption.1.varhLeadToday 0
     2022-07-08 13:13:51   consumption.1.wNow -1765.032
     2022-07-08 13:13:51   consumption.1.whLastSevenDays 0
     2022-07-08 13:13:51   consumption.1.whLifetime 0
     2022-07-08 13:13:51   consumption.1.whToday 0
     2022-07-08 13:13:51   production.0.activeCount 7
     2022-07-08 13:13:51   production.0.readingTime 1657278359
     2022-07-08 13:13:51   production.0.type inverters
     2022-07-08 13:13:51   production.0.wNow 1665
     2022-07-08 13:13:51   production.0.whLifetime 615125
     2022-07-08 13:13:51   production.1.activeCount 0
     2022-07-08 13:13:51   production.1.apprntPwr 1618.507
     2022-07-08 13:13:51   production.1.lines.0.apprntPwr 1618.033
     2022-07-08 13:13:51   production.1.lines.0.pwrFactor -0.55
     2022-07-08 13:13:51   production.1.lines.0.reactPwr 1354.887
     2022-07-08 13:13:51   production.1.lines.0.rmsCurrent 7.001
     2022-07-08 13:13:51   production.1.lines.0.rmsVoltage 231.049
     2022-07-08 13:13:51   production.1.lines.0.vahLifetime 0
     2022-07-08 13:13:51   production.1.lines.0.vahToday 0
     2022-07-08 13:13:51   production.1.lines.0.varhLagLifetime 0
     2022-07-08 13:13:51   production.1.lines.0.varhLagToday 0
     2022-07-08 13:13:51   production.1.lines.0.varhLeadLifetime 0
     2022-07-08 13:13:51   production.1.lines.0.varhLeadToday 0
     2022-07-08 13:13:51   production.1.lines.0.wNow -889.584
     2022-07-08 13:13:51   production.1.lines.0.whLastSevenDays 0
     2022-07-08 13:13:51   production.1.lines.0.whLifetime 0
     2022-07-08 13:13:51   production.1.lines.0.whToday 0
     2022-07-08 13:13:51   production.1.lines.1.apprntPwr 0.474
     2022-07-08 13:13:51   production.1.lines.1.pwrFactor 0
     2022-07-08 13:13:51   production.1.lines.1.reactPwr 0
     2022-07-08 13:13:51   production.1.lines.1.rmsCurrent 0.347
     2022-07-08 13:13:51   production.1.lines.1.rmsVoltage 1.367
     2022-07-08 13:13:51   production.1.lines.1.vahLifetime 0
     2022-07-08 13:13:51   production.1.lines.1.vahToday 0
     2022-07-08 13:13:51   production.1.lines.1.varhLagLifetime 0
     2022-07-08 13:13:51   production.1.lines.1.varhLagToday 0
     2022-07-08 13:13:51   production.1.lines.1.varhLeadLifetime 0
     2022-07-08 13:13:51   production.1.lines.1.varhLeadToday 0
     2022-07-08 13:13:51   production.1.lines.1.wNow 0.363
     2022-07-08 13:13:51   production.1.lines.1.whLastSevenDays 0
     2022-07-08 13:13:51   production.1.lines.1.whLifetime 0
     2022-07-08 13:13:51   production.1.lines.1.whToday 0
     2022-07-08 13:13:51   production.1.measurementType production
     2022-07-08 13:13:51   production.1.pwrFactor -0.55
     2022-07-08 13:13:51   production.1.reactPwr 1354.887
     2022-07-08 13:13:51   production.1.readingTime 1657278454
     2022-07-08 13:13:51   production.1.rmsCurrent 7.348
     2022-07-08 13:13:51   production.1.rmsVoltage 232.416
     2022-07-08 13:13:51   production.1.type eim
     2022-07-08 13:13:51   production.1.vahLifetime 0
     2022-07-08 13:13:51   production.1.vahToday 0
     2022-07-08 13:13:51   production.1.varhLagLifetime 0
     2022-07-08 13:13:51   production.1.varhLagToday 0
     2022-07-08 13:13:51   production.1.varhLeadLifetime 0
     2022-07-08 13:13:51   production.1.varhLeadToday 0
     2022-07-08 13:13:51   production.1.wNow -889.221
     2022-07-08 13:13:51   production.1.whLastSevenDays 0
     2022-07-08 13:13:51   production.1.whLifetime 0
     2022-07-08 13:13:51   production.1.whToday 0
     2022-07-08 13:13:51   storage.0.activeCount 0
     2022-07-08 13:13:51   storage.0.readingTime 0
     2022-07-08 13:13:51   storage.0.state idle
     2022-07-08 13:13:51   storage.0.type  acb
     2022-07-08 13:13:51   storage.0.wNow  0
     2022-07-08 13:13:51   storage.0.whNow 0


wNow appears four times under production:
2022-07-08 13:13:51   production.0.wNow 1665
2022-07-08 13:13:51   production.1.lines.0.wNow -889.584
2022-07-08 13:13:51   production.1.lines.1.wNow 0.363
2022-07-08 13:13:51   production.1.wNow -889.221

I guess you want the last one? Then you can use the JsonPath for it:
attr enphaseJM readingList single(jsonPath('$.production.[1].wNow'), 'wNow', '-?-');;

Complete Device raw:
defmod enphaseJM JsonMod http://192.168.1.161/production.json?details=1
attr enphaseJM interval 0 */2 * * *
attr enphaseJM readingList single(jsonPath('$.production.[1].wNow'), 'wNow', '-?-');;
attr enphaseJM stateFormat { my $ret ="";;\
  $ret .= sprintf("%.3f", (ReadingsNum($name,"wNow",0) / 1000));;\
  $ret .= " kWh";;\
  return $ret;;\
}
attr enphaseJM webCmd reread
attr enphaseJM httpHeader Content-Type: application/json
attr enphaseJM room ENERGIE
viele Grüße, yersinia
----
FHEM 6.3 (SVN) on RPi 4B with RasPi OS Bullseye (perl 5.32.1) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

petitpunch

it's working !
great !
many many thanks to you.

it's not easy to me to parse a json like that.

thank you !!

petitpunch

Hello,

since the new firmware (7) of the envoy-s, i can't read the url anymore.
Enphase has added a login/password to an online url with a redirection to my local interface when the login/password is validated.
here is a project on github for home assistant  : https://github.com/jrutski/home_assistant_envoy_d7_fw

is it possible to convert that in fhem ?



Christian83

Hallo,

ich habe ein Perl Modul zum Auslesen des Enphase Gateways gebaut.
Bei Interessen kann ich es gerne zur Verfügung stellen.

s00rb

Moin Christian,

ich wäre interessiert an dem Modul.
Aktuell gehe ich den Umweg über das Homekit Plugin "Enphase Envoy" um an die Daten meiner Anlage zu kommen und lasse mir die Daten per mqtt an FHEM schicken.
Leider steige ich durch die Datenflut und die API von enphase nicht wirklich durch.

Gruß Mario

Christian83

#10
Hi Mario,

anbei das Modul.
Edit: Altprogramm entfernt.

define <name> ENPHASE <IPAddr> <username>

username ist die mailadresse im Enlighten System.
Mit set <name> password <password> das Passwort für Enlighten hinterlegen.

get <name> LiveData - dann wird das Envoy ausgelesen.
Danach wird bei positiver Erzeugung aller 60 Sekunden sonst aller 300 Sekunden abgefragt. (Kann über Attribut updateinterval geändert werden).

Bei Fragen einfach melden.

s00rb

Coole Sache!
Hab vielen Dank! Ich werde testen und berichten.

Christian83

Bist du schon zum Testen gekommen?

Passt es? Fehlt was?

wolfganghabenicht

Moin,

habe es eingerichet, aber bei mir toggelt es dauerhaft zwischen 'reading token', getting session id' und 'getting token' hin und her.

Ich habe eine Session-ID zurückbekommen, aber der state toggelt weiterhin

Christian83

Zitat von: wolfganghabenicht am 23 Mai 2023, 13:05:20Moin,

habe es eingerichet, aber bei mir toggelt es dauerhaft zwischen 'reading token', getting session id' und 'getting token' hin und her.

Ich habe eine Session-ID zurückbekommen, aber der state toggelt weiterhin

Schalt mal verbose auf 5 und schreib das Log.
Dann sehe ich vielleicht was.