Autor Thema: [geloest] expandJSON welche regex  (Gelesen 358 mal)

Offline ch.eick

  • Sr. Member
  • ****
  • Beiträge: 977
[geloest] expandJSON welche regex
« am: 30 März 2020, 13:58:03 »
Hallo zusammen,
ich habe mal wieder einen Knoten im Kopf.
Welche regex muesste ich fuer dieses json eintragen, damit es in readings umgesetzt wird?
Das output wird durch ein python Skript befuellt und dieses Listing waere nur ein Beispiel, wie die Daten aussehen.
Mit verbose 5 erscheinen bisher keine Fehlermeldungen im Log.
[{"id": "devices:local", "type": "device"}, {"id": "devices:local:ac", "type": "device:ac"}, {"id": "devices:local:battery", "type": "device:battery"}, {"id": "devices:local:powermeter", "type": "device:powermeter"}, {"id": "devices:local:pv1", "type": "device:pv"}, {"id": "devices:local:pv2", "type": "device:pv"}, {"id": "devices:prober", "type": "device"}, {"id": "scb:event", "type": "service"}, {"id": "scb:export", "type": "service"}, {"id": "scb:logging:logger1", "type": "service"}, {"id": "scb:logging:logger2", "type": "service"}, {"id": "scb:modbus", "type": "service"}, {"id": "scb:network", "type": "service"}, {"id": "scb:rse", "type": "service"}, {"id": "scb:statistic:EnergyFlow", "type": "service"}, {"id": "scb:time", "type": "service"}]
   
Folgendes habe ich bereits versucht, aber das ist stochern im dunkeln...
Plenticore_Status:output:[(\{.*\})]

Plenticore_Status:output:\{.*\}

Plenticore_Status:output:.\{.*}

Mit json.dumps() formatiert sieht das ganze so aus.
[
    {
        "id": "devices:local",
        "type": "device"
    },
    {
        "id": "devices:local:ac",
        "type": "device:ac"
    },
    {
        "id": "devices:local:battery",
        "type": "device:battery"
    },
    {
        "id": "devices:local:powermeter",
        "type": "device:powermeter"
    },
    {
        "id": "devices:local:pv1",
        "type": "device:pv"
    },
    {
        "id": "devices:local:pv2",
        "type": "device:pv"
    },
    {
        "id": "devices:prober",
        "type": "device"
    },
    {
        "id": "scb:event",
        "type": "service"
    },
    {
        "id": "scb:export",
        "type": "service"
    },
    {
        "id": "scb:logging:logger1",
        "type": "service"
    },
    {
        "id": "scb:logging:logger2",
        "type": "service"
    },
    {
        "id": "scb:modbus",
        "type": "service"
    },
    {
        "id": "scb:network",
        "type": "service"
    },
    {
        "id": "scb:rse",
        "type": "service"
    },
    {
        "id": "scb:statistic:EnergyFlow",
        "type": "service"
    },
    {
        "id": "scb:time",
        "type": "service"
    }
]

Denkbar fuer mich waere dann so etwas
output01id devices:local
output01type device
output02id ....

Internals:
   CFGFN     
   DEF        Plenticore_Status:output:.\{.*}
   FUUID      5e7e4120-f33f-61a8-e8da-b419ae490d8d667a
   NAME       Plenticore_Status
   NOTIFYDEV  Plenticore_Status
   NR         43718
   NTFY_ORDER 50-Plenticore_Status
   STATE      active
   TYPE       expandJSON
   s_regexp   Plenticore_Status:output:.\{.*}
   t_regexp   .*
   version    1.13
   Helper:
     DBLOG:
       state:
         LogDB:
           TIME       1585332512.05747
           VALUE      active
   READINGS:
     2020-03-28 16:14:07   output          [{"id": "devices:local", "type": "device"}, {"id": "devices:local:ac", "type": "device:ac"}, {"id": "devices:local:battery", "type": "device:battery"}, {"id": "devices:local:powermeter", "type": "device:powermeter"}, {"id": "devices:local:pv1", "type": "device:pv"}, {"id": "devices:local:pv2", "type": "device:pv"}, {"id": "devices:prober", "type": "device"}, {"id": "scb:event", "type": "service"}, {"id": "scb:export", "type": "service"}, {"id": "scb:logging:logger1", "type": "service"}, {"id": "scb:logging:logger2", "type": "service"}, {"id": "scb:modbus", "type": "service"}, {"id": "scb:network", "type": "service"}, {"id": "scb:rse", "type": "service"}, {"id": "scb:statistic:EnergyFlow", "type": "service"}, {"id": "scb:time", "type": "service"}]
     2020-03-28 16:13:51   state           active
Attributes:
   DbLogExclude .*
   alias      Plenticore_Status
   comment    Das Device wird über ein Python Skript im reading output befüllt.
   addReadingsPrefix 1

   room       Strom->Photovoltaik

Vielen Dank fuer einen Hinweis in die richtige Suchrichtung
       Christian
« Letzte Änderung: 30 März 2020, 16:44:15 von ch.eick »
RPI4; Docker; CUNX; Eltako FSB61NP; 230V zentral verschaltet; SamsungTV H-Serie; DLNARenderer; TV.pl;  Sonos; Vallox; Luxtronik; 2x FB7490; Stromzähler mit DvLIR; wunderground; clever-tanken; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP

Offline ch.eick

  • Sr. Member
  • ****
  • Beiträge: 977
Antw:expandJSON welche regex
« Antwort #1 am: 30 März 2020, 14:01:32 »
Was bereits funktioniert waere soetwas....

setreading Plenticore_Status output {"moduleid": "devices:local", "settings": [{"id": "Battery:MinSoc", "value": "15"}]}

Internals:
   CFGFN     
   DEF        Plenticore_Status:output:.\{.*}
   FUUID      5e7e4120-f33f-61a8-e8da-b419ae490d8d667a
   NAME       Plenticore_Status
   NOTIFYDEV  Plenticore_Status
   NR         43718
   NTFY_ORDER 50-Plenticore_Status
   STATE      2020-03-30 13:58:46
   TYPE       expandJSON
   s_regexp   Plenticore_Status:output:.\{.*}
   t_regexp   .*
   version    1.13
   Helper:
     DBLOG:
       state:
         LogDB:
           TIME       1585332512.05747
           VALUE      active
   OLDREADINGS:
   READINGS:
     2020-03-30 13:58:46   output  {"moduleid": "devices:local", "settings": [{"id": "Battery:MinSoc", "value": "15"}]}
     2020-03-30 13:58:46   output_moduleid devices:local
     2020-03-30 13:58:46   output_settings_01_id Battery:MinSoc
     2020-03-30 13:58:46   output_settings_01_value 15
   helper:
     addReadingsPrefix 1
Attributes:
   DbLogExclude .*
   addReadingsPrefix 1
   alias      Plenticore_Status
   comment    Das Device wird über ein Python Skript im reading output befüllt.

   room       Strom->Photovoltaik
RPI4; Docker; CUNX; Eltako FSB61NP; 230V zentral verschaltet; SamsungTV H-Serie; DLNARenderer; TV.pl;  Sonos; Vallox; Luxtronik; 2x FB7490; Stromzähler mit DvLIR; wunderground; clever-tanken; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP

Offline ch.eick

  • Sr. Member
  • ****
  • Beiträge: 977
Antw:expandJSON welche regex
« Antwort #2 am: 30 März 2020, 14:37:26 »
Und hier noch einmal Testdaten vom Plenticore Status...
RPI4; Docker; CUNX; Eltako FSB61NP; 230V zentral verschaltet; SamsungTV H-Serie; DLNARenderer; TV.pl;  Sonos; Vallox; Luxtronik; 2x FB7490; Stromzähler mit DvLIR; wunderground; clever-tanken; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP

Offline ch.eick

  • Sr. Member
  • ****
  • Beiträge: 977
Antw:expandJSON welche regex
« Antwort #3 am: 30 März 2020, 16:18:19 »
Ich habe mich jetzt nochmal durch die Testdaten gearbeitet und es schein eine etwas merkwuerdige Struktur zu sein.

Hier das erkante Schema
{"moduleid": "devices:local", "settings": [ {...}, {...} ]},
{"moduleid": "scb:export", "settings": [ {...}, {...} ]},
...

Wenn ich die json Struktur nur fuer eine moduleid einlese, dann kommt folgendes heraus
     2020-03-30 16:04:14   output_moduleid devices:local
     2020-03-30 16:04:14   output_settings_01_access readonly
     2020-03-30 16:04:14   output_settings_01_id ActivePower:ExtCtrl:Enable
     2020-03-30 16:04:14   output_settings_01_max 1
     2020-03-30 16:04:14   output_settings_01_min 0
     2020-03-30 16:04:14   output_settings_01_type byte
     2020-03-30 16:04:14   output_settings_02_access readonly
     2020-03-30 16:04:14   output_settings_02_id ActivePower:ExtCtrl:ModeGradientEnable
     2020-03-30 16:04:14   output_settings_02_max 1
     2020-03-30 16:04:14   output_settings_02_min 0
     2020-03-30 16:04:14   output_settings_02_type byte
     2020-03-30 16:04:14   output_settings_03_access readonly
     2020-03-30 16:04:14   output_settings_03_id ActivePower:ExtCtrl:ModeGradientFactor
     2020-03-30 16:04:14   output_settings_03_min 0.0
     2020-03-30 16:04:14   output_settings_03_type double
     2020-03-30 16:04:14   output_settings_03_unit W/s
     2020-03-30 16:04:14   output_settings_04_access readonly
     2020-03-30 16:04:14   output_settings_04_id ActivePower:ExtCtrl:ModeGradientLowPriorityFactor
     2020-03-30 16:04:14   output_settings_04_min 0.0
     2020-03-30 16:04:14   output_settings_04_type double
     2020-03-30 16:04:14   output_settings_04_unit W/s
     2020-03-30 16:04:14   output_settings_05_access readonly
     2020-03-30 16:04:14   output_settings_05_id ActivePower:ExtCtrl:ModePT1Enable
     2020-03-30 16:04:14   output_settings_05_max 1
     2020-03-30 16:04:14   output_settings_05_min 0
     2020-03-30 16:04:14   output_settings_05_type byte

Was hier also nicht funktioniert ist, dass es eine doppelte Durchzaehlung gibt.
  output_modileid_01
  output_modileid_01_settings_01_access
  output_modileid_01_settings_01_id
  ...

Des weiteren gibt es bei den Settings mehrere Hundert, was bei der Nummernformatierung (001,002,..) nicht beruecksichtigt wird.
RPI4; Docker; CUNX; Eltako FSB61NP; 230V zentral verschaltet; SamsungTV H-Serie; DLNARenderer; TV.pl;  Sonos; Vallox; Luxtronik; 2x FB7490; Stromzähler mit DvLIR; wunderground; clever-tanken; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP

Offline ch.eick

  • Sr. Member
  • ****
  • Beiträge: 977
Antw:expandJSON welche regex
« Antwort #4 am: 30 März 2020, 16:40:07 »
Wer lange sucht....

Bei der json Struktur vom Plenticore fehlt etwas, das die Struktur wiederum als Array darstellt. Umklammert man das ganze aus der "Plenticore_test_json.txt" Datei mit folgender Zusatzinformation, dann laesst sich alles soweit einlesen.
{"DEVICEID": "Plenticore", "MODULES": <Inhalt der Datei> }
Das Ergebnis im expandJSON device sieht dann wie folgt aus
     2020-03-30 16:29:29   output_DEVICEid Plenticore
     2020-03-30 16:29:29   output_MODULES_01_moduleid devices:local
     2020-03-30 16:29:29   output_MODULES_01_settings_01_access readonly
     2020-03-30 16:29:29   output_MODULES_01_settings_01_id ActivePower:ExtCtrl:Enable
     2020-03-30 16:29:29   output_MODULES_01_settings_01_max 1
     2020-03-30 16:29:29   output_MODULES_01_settings_01_min 0
     2020-03-30 16:29:29   output_MODULES_01_settings_01_type byte
     2020-03-30 16:29:29   output_MODULES_01_settings_02_access readonly
     2020-03-30 16:29:29   output_MODULES_01_settings_02_id ActivePower:ExtCtrl:ModeGradientEnable
     2020-03-30 16:29:29   output_MODULES_01_settings_02_max 1
     2020-03-30 16:29:29   output_MODULES_01_settings_02_min 0
     2020-03-30 16:29:29   output_MODULES_01_settings_02_type byte
     2020-03-30 16:29:29   output_MODULES_01_settings_03_access readonly
     2020-03-30 16:29:29   output_MODULES_01_settings_03_id ActivePower:ExtCtrl:ModeGradientFactor
     2020-03-30 16:29:29   output_MODULES_01_settings_03_min 0.0
     2020-03-30 16:29:29   output_MODULES_01_settings_03_type double
     2020-03-30 16:29:29   output_MODULES_01_settings_03_unit W/s
     2020-03-30 16:29:29   output_MODULES_01_settings_04_access readonly
     2020-03-30 16:29:29   output_MODULES_01_settings_04_id ActivePower:ExtCtrl:ModeGradientLowPriorityFactor
     2020-03-30 16:29:29   output_MODULES_01_settings_04_min 0.0
     2020-03-30 16:29:29   output_MODULES_01_settings_04_type double
     2020-03-30 16:29:29   output_MODULES_01_settings_04_unit W/s

snip

     2020-03-30 16:29:29   output_MODULES_01_settings_98_access readonly
     2020-03-30 16:29:29   output_MODULES_01_settings_98_id ConfigurationPreset:Available:PresetId12
     2020-03-30 16:29:29   output_MODULES_01_settings_98_type uint32
     2020-03-30 16:29:29   output_MODULES_01_settings_99_access readonly
     2020-03-30 16:29:29   output_MODULES_01_settings_99_id ConfigurationPreset:Available:PresetId13
     2020-03-30 16:29:29   output_MODULES_01_settings_99_type uint32

     2020-03-30 16:29:29   output_MODULES_02_moduleid scb:export
     2020-03-30 16:29:29   output_MODULES_02_settings_01_access readonly
     2020-03-30 16:29:29   output_MODULES_02_settings_01_id AvailablePortals
     2020-03-30 16:29:29   output_MODULES_02_settings_01_type uint32
     2020-03-30 16:29:29   output_MODULES_02_settings_02_access readwrite
     2020-03-30 16:29:29   output_MODULES_02_settings_02_id ExportEnable
     2020-03-30 16:29:29   output_MODULES_02_settings_02_max 1
     2020-03-30 16:29:29   output_MODULES_02_settings_02_min 0
     2020-03-30 16:29:29   output_MODULES_02_settings_02_type byte
     2020-03-30 16:29:29   output_MODULES_02_settings_03_access readonly
     2020-03-30 16:29:29   output_MODULES_02_settings_03_id LastExport
     2020-03-30 16:29:29   output_MODULES_02_settings_03_type uint64
     2020-03-30 16:29:29   output_MODULES_02_settings_04_access readonly
     2020-03-30 16:29:29   output_MODULES_02_settings_04_id LastExportOk
     2020-03-30 16:29:29   output_MODULES_02_settings_04_type uint64
     2020-03-30 16:29:29   output_MODULES_02_settings_05_access readwrite
     2020-03-30 16:29:29   output_MODULES_02_settings_05_id Portal
     2020-03-30 16:29:29   output_MODULES_02_settings_05_type uint32

     2020-03-30 16:29:29   output_MODULES_03_moduleid scb:logging:logger1
     2020-03-30 16:29:29   output_MODULES_03_settings_01_access readwrite
     2020-03-30 16:29:29   output_MODULES_03_settings_01_default 300
     2020-03-30 16:29:29   output_MODULES_03_settings_01_id Logintervall
     2020-03-30 16:29:29   output_MODULES_03_settings_01_max 10000
     2020-03-30 16:29:29   output_MODULES_03_settings_01_min 1
     2020-03-30 16:29:29   output_MODULES_03_settings_01_type uint32
     2020-03-30 16:29:29   output_MODULES_03_settings_01_unit s

     2020-03-30 16:29:29   output_MODULES_04_moduleid scb:logging:logger2
     2020-03-30 16:29:29   output_MODULES_04_settings_01_access readwrite
     2020-03-30 16:29:29   output_MODULES_04_settings_01_default 300
     2020-03-30 16:29:29   output_MODULES_04_settings_01_id Logintervall
     2020-03-30 16:29:29   output_MODULES_04_settings_01_max 10000
     2020-03-30 16:29:29   output_MODULES_04_settings_01_min 1
     2020-03-30 16:29:29   output_MODULES_04_settings_01_type uint32
     2020-03-30 16:29:29   output_MODULES_04_settings_01_unit s

     2020-03-30 16:29:29   output_MODULES_05_moduleid scb:modbus
     2020-03-30 16:29:29   output_MODULES_05_settings_01_access readwrite
     2020-03-30 16:29:29   output_MODULES_05_settings_01_id ModbusEnable
     2020-03-30 16:29:29   output_MODULES_05_settings_01_type bool
     2020-03-30 16:29:29   output_MODULES_05_settings_02_access readwrite
     2020-03-30 16:29:29   output_MODULES_05_settings_02_id ModbusUnitId
     2020-03-30 16:29:29   output_MODULES_05_settings_02_max 255
     2020-03-30 16:29:29   output_MODULES_05_settings_02_min 1
     2020-03-30 16:29:29   output_MODULES_05_settings_02_type uint16

     2020-03-30 16:29:29   output_MODULES_06_moduleid scb:network
     2020-03-30 16:29:29   output_MODULES_06_settings_01_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_01_id Hostname
     2020-03-30 16:29:29   output_MODULES_06_settings_01_max 63
     2020-03-30 16:29:29   output_MODULES_06_settings_01_min 1
     2020-03-30 16:29:29   output_MODULES_06_settings_01_type string
     2020-03-30 16:29:29   output_MODULES_06_settings_02_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_02_id IPv4Address
     2020-03-30 16:29:29   output_MODULES_06_settings_02_type string
     2020-03-30 16:29:29   output_MODULES_06_settings_03_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_03_id IPv4Auto
     2020-03-30 16:29:29   output_MODULES_06_settings_03_max 1
     2020-03-30 16:29:29   output_MODULES_06_settings_03_min 0
     2020-03-30 16:29:29   output_MODULES_06_settings_03_type byte
     2020-03-30 16:29:29   output_MODULES_06_settings_04_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_04_id IPv4AutoDNS
     2020-03-30 16:29:29   output_MODULES_06_settings_04_max 1
     2020-03-30 16:29:29   output_MODULES_06_settings_04_min 0
     2020-03-30 16:29:29   output_MODULES_06_settings_04_type byte
     2020-03-30 16:29:29   output_MODULES_06_settings_05_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_05_id IPv4DNS1
     2020-03-30 16:29:29   output_MODULES_06_settings_05_type string
     2020-03-30 16:29:29   output_MODULES_06_settings_06_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_06_id IPv4DNS2
     2020-03-30 16:29:29   output_MODULES_06_settings_06_type string
     2020-03-30 16:29:29   output_MODULES_06_settings_07_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_07_id IPv4Enable
     2020-03-30 16:29:29   output_MODULES_06_settings_07_max 1
     2020-03-30 16:29:29   output_MODULES_06_settings_07_min 0
     2020-03-30 16:29:29   output_MODULES_06_settings_07_type byte
     2020-03-30 16:29:29   output_MODULES_06_settings_08_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_08_id IPv4Gateway
     2020-03-30 16:29:29   output_MODULES_06_settings_08_type string
     2020-03-30 16:29:29   output_MODULES_06_settings_09_access readwrite
     2020-03-30 16:29:29   output_MODULES_06_settings_09_id IPv4Subnetmask
     2020-03-30 16:29:29   output_MODULES_06_settings_09_type string
     2020-03-30 16:29:29   output_MODULES_06_settings_10_access readonly
     2020-03-30 16:29:29   output_MODULES_06_settings_10_id MACaddr
     2020-03-30 16:29:29   output_MODULES_06_settings_10_type string

     2020-03-30 16:29:29   output_MODULES_07_moduleid scb:rse
     2020-03-30 16:29:29   output_MODULES_07_settings_01_access readonly
     2020-03-30 16:29:29   output_MODULES_07_settings_01_id Inverter:PowerCtrlBroadcast:Mode
     2020-03-30 16:29:29   output_MODULES_07_settings_01_max 2
     2020-03-30 16:29:29   output_MODULES_07_settings_01_min 0
     2020-03-30 16:29:29   output_MODULES_07_settings_01_type byte

     2020-03-30 16:29:29   output_MODULES_08_moduleid scb:time
     2020-03-30 16:29:29   output_MODULES_08_settings_01_access readonly
     2020-03-30 16:29:29   output_MODULES_08_settings_01_id AvailableTimezones
     2020-03-30 16:29:29   output_MODULES_08_settings_01_type string
     2020-03-30 16:29:29   output_MODULES_08_settings_02_access readwrite
     2020-03-30 16:29:29   output_MODULES_08_settings_02_id DateTime
     2020-03-30 16:29:29   output_MODULES_08_settings_02_type string
     2020-03-30 16:29:29   output_MODULES_08_settings_03_access readwrite
     2020-03-30 16:29:29   output_MODULES_08_settings_03_id NTPservers
     2020-03-30 16:29:29   output_MODULES_08_settings_03_type string
     2020-03-30 16:29:29   output_MODULES_08_settings_04_access readwrite
     2020-03-30 16:29:29   output_MODULES_08_settings_04_id NTPuse
     2020-03-30 16:29:29   output_MODULES_08_settings_04_type string
     2020-03-30 16:29:29   output_MODULES_08_settings_05_access readwrite
     2020-03-30 16:29:29   output_MODULES_08_settings_05_id Timezone
     2020-03-30 16:29:29   output_MODULES_08_settings_05_type string

Die Unschoenheit mit der dreistelligen Readingsanzahl besteht natuerlich weiter, aber wer liest schon soooo viele Informationen ein, aber das ist ein anderes Thema.

Vielen Dank an alle, die zugehoert haben... ;-)
     Christian
« Letzte Änderung: 30 März 2020, 16:43:16 von ch.eick »
RPI4; Docker; CUNX; Eltako FSB61NP; 230V zentral verschaltet; SamsungTV H-Serie; DLNARenderer; TV.pl;  Sonos; Vallox; Luxtronik; 2x FB7490; Stromzähler mit DvLIR; wunderground; clever-tanken; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP

Offline ch.eick

  • Sr. Member
  • ****
  • Beiträge: 977
Antw:[geloest] expandJSON welche regex
« Antwort #5 am: 29 August 2020, 12:01:48 »
Sooo, ab jetzt ist das Wiki die erste Quelle der Wahl!
https://wiki.fhem.de/wiki/Kostal_Plenticore_10_Plus
RPI4; Docker; CUNX; Eltako FSB61NP; 230V zentral verschaltet; SamsungTV H-Serie; DLNARenderer; TV.pl;  Sonos; Vallox; Luxtronik; 2x FB7490; Stromzähler mit DvLIR; wunderground; clever-tanken; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP