FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: ch.eick am 28 März 2020, 16:21:50

Titel: expandJSON welche regex
Beitrag von: ch.eick am 28 März 2020, 16:21:50
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

reading01id devices:local
reading01type device



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.

   room       Strom->Photovoltaik


Vielen Dank fuer einen Hinweis in die richtige Suchrichtung
       Christian