Anwendungsbeispiel JsonMod #2: CORONA Verbreitung

Begonnen von herrmannj, 22 März 2020, 21:11:18

Vorheriges Thema - Nächstes Thema

herrmannj

Jetzt wünsche ich der look down würde mich auch betreffen  :) :)

@Dracolein:
wo kommen denn die Umlaute in Deinen pic her? sind die auch als reading name? Mit der neuesten Version sollte das nicht sein. FHEM wird beim start meckern weil das dann keine gültigen readingnamen "wären".

Zu den meldungen im log: kenn ich so nicht. Vermutung: das ist das ";;\" am Ende der Einträge. Die können da weg ein ";" reicht.

@Andy89
sollte natürlich nicht. Welcher Art ist der Fehler denn? Was passiert? Fehlermeldungen?
API_LAST_RES_HUMAN kann ich machen.

@yersinia
ja, würde als workaround funktionieren. Aber ich gehe dem Fehler bei Andy nach wenn ich den Fehler verstehe.



Andy89

Zitat von: herrmannj am 26 März 2020, 11:20:41
@Andy89
sollte natürlich nicht. Welcher Art ist der Fehler denn? Was passiert? Fehlermeldungen?
der Fehler ist, dass überhaupt keine Readings für "Iran, " erzeugt werden. Es beschwert sich nur das Userreading, dass es nicht durch 0 teilen kann, weil es kein Reading findet.
Hier der Auszug aus dem Log (von unten nach oben lesen):
2020.03.26 11:29:47.622 5: [coronaSpread] event:[Iran_procent_todayCases: Error evaluating coronaSpread userReading Iran_procent_todayCases: Illegal division by zero at (eval 272275) line 1.
], device:[coronaSpread]
2020.03.26 11:29:47.622 5: [coronaSpread] event:[Iran_procent_todayDeaths: Error evaluating coronaSpread userReading Iran_procent_todayDeaths: Illegal division by zero at (eval 272266) line 1.
2020.03.26 11:29:47.622 5: [coronaSpread] event:[Germany_todayDeaths: 16], device:[coronaSpread]

2020.03.26 11:29:47.619 1: Error evaluating coronaSpread userReading Iran_procent_todayCases: Illegal division by zero at (eval 272275) line 1.
2020.03.26 11:29:47.619 3: eval: {ReadingsVal("coronaSpread","Iran_todayCases","")/ReadingsVal("coronaSpread","Iran_cases","")*100}
2020.03.26 11:29:47.619 1: PERL WARNING: Argument "" isn't numeric in division (/) at (eval 272275) line 1.

2020.03.26 11:29:47.617 1: Error evaluating coronaSpread userReading Iran_procent_todayDeaths: Illegal division by zero at (eval 272266) line 1.
2020.03.26 11:29:47.617 3: eval: {ReadingsVal("coronaSpread","Iran_todayDeaths","")/ReadingsVal("coronaSpread","Iran_deaths","")*100}
2020.03.26 11:29:47.617 1: PERL WARNING: Argument "" isn't numeric in division (/) at (eval 272266) line 1.
2020.03.26 11:29:47.217 4: [coronaSpread] next request: 2020.03.26 11:31:00


Wenn ich das Device auf verbose 5 Stelle, wird mein Log eh mit allem zugemüllt, weil JsonMod scheinbar auf alles reagiert. Nochmal ein Auszug aus dem Log
2020.03.26 11:29:47.693 5: [coronaSpread] event:[UptimeSec: 220844], device:[MQTT2_Gosund004]
2020.03.26 11:29:47.693 5: [coronaSpread] event:[Time: 2020-03-26T11:29:47], device:[MQTT2_Gosund004]
2020.03.26 11:29:47.682 5: [coronaSpread] event:[state: Updated stats for: MQTT2_Gosund004], device:[statistics_Strom_Gosund]
], device:[coronaSpread]

FHEM 6.0 auf rPi4 docker (mit Alexa & Siri); dbLog, FTUI, Sonos, XiaomiMapCreator auf rPi4 docker;
raspimatic auf rPi3+ > diverse Aktoren und Sensoren;
LGW > (PCA301),EC3000,LaCrosse; MQTT2 > WLAN-Steckdosen,Xiaomi Map;
Harmony Hub;Sonos;Onkyo AVR;RGB WLAN Controller;Netatmo;Withings;Unifi;AMAD

TWART016

Zitat von: Andy89 am 26 März 2020, 08:49:18
Hier noch meine Welt Zahlen:
defmod coronaSpreadWorld JsonMod https://corona.lmao.ninja/all
attr coronaSpreadWorld event-on-change-reading .*
attr coronaSpreadWorld interval */10 * * * *
attr coronaSpreadWorld readingList single(jsonPathf('$.deaths', '%s'), 'world_deaths', 'N/A');;\
single(jsonPathf('$.cases', '%s'), 'world_cases', 'N/A');;\
single(jsonPathf('$.recovered', '%s'), 'world_recovered', 'N/A');;\
single(jsonPathf('$.updated', '%s'), 'world_updated', 'N/A');;
attr coronaSpreadWorld room Status
attr coronaSpreadWorld userReadings updated_human  {setlocale(LC_TIME,"de_DE.utf8");; POSIX::strftime ("%a %d.%m.%Y %H:%M", localtime(ReadingsVal("coronaSpreadWorld","world_updated",0)/1000))}

Bei mir werden hier keine Readings erstellt

defmod coronaSpreadWorld JsonMod https://corona.lmao.ninja/all
attr coronaSpreadWorld event-on-change-reading .*
attr coronaSpreadWorld interval */1 * * * *
attr coronaSpreadWorld readingList single(jsonPathf('$.deaths', '%s'), 'world_deaths', 'N/A');;\
single(jsonPathf('$.cases', '%s'), 'world_cases', 'N/A');;\
single(jsonPathf('$.recovered', '%s'), 'world_recovered', 'N/A');;\
single(jsonPathf('$.updated', '%s'), 'world_updated', 'N/A');;
attr coronaSpreadWorld userReadings updated_human  {setlocale(LC_TIME,"de_DE.utf8");; POSIX::strftime ("%a %d.%m.%Y %H:%M", localtime(ReadingsVal("coronaSpreadWorld","world_updated",0)/1000))}

herrmannj

#78
kannst Du mal testweise diesen Teil rausnehmen:
{ReadingsVal("coronaSpread","Iran_todayCases","")/ReadingsVal("coronaSpread","Iran_cases","")*100}
Also, wenn die das Land umbenennen dann ändert sich ja auch der Name des Readings. Das sollte problemlos funktionieren (Theorie). Der alte Name wird entfernt und das Land wird neu angelegt.

Dein ReadingsVal(... 'Iran',...) läuft dann ins nirvana. Bei default dort erst mal anstelle von "" eine 1 rein (gibt dann Division / 1). Oder | und erst mal ganz weg, weil bringt ja nix. (Das Komma im Land könnte trotzdem Probleme machen, da müsste ich dann ran. Theoretisch (tm) sollte es aber funktionieren)

Nachtrag. Ah, Iran wird auch nicht als "Iran Islamic Republic of" angelegt ? modifizier mal user reading, mal schauen was passiert. Sonst muss ich heute Abend schauen.

Nachtrag2: verbose 5 . Jo, das grenze ich mal ein.

Andy89

Zitat von: TWART016 am 26 März 2020, 11:45:26
Bei mir werden hier keine Readings erstellt
hast du heute schon ein FHEM Update gemacht? Das hat erst danach funktioniert.

Ich habe das Interval und die Userreadings nochmal angepasst, damit es zu den anderen Zahlen passt.
defmod coronaSpreadWorld JsonMod https://corona.lmao.ninja/all
attr coronaSpreadWorld event-on-change-reading .*
attr coronaSpreadWorld interval 1/10 * * * *
attr coronaSpreadWorld readingList single(jsonPathf('$.deaths', '%s'), 'world_deaths', 'N/A');;\
single(jsonPathf('$.cases', '%s'), 'world_cases', 'N/A');;\
single(jsonPathf('$.recovered', '%s'), 'world_recovered', 'N/A');;\
single(jsonPathf('$.updated', '%s'), 'world_updated', 'N/A');;
attr coronaSpreadWorld room Status
attr coronaSpreadWorld stateFormat Welt Fälle: world_active
attr coronaSpreadWorld userReadings updated_human  {setlocale(LC_TIME,"de_DE.utf8");; POSIX::strftime ("%Y-%m-%d %H:%M:00", localtime(ReadingsVal("coronaSpreadWorld","world_updated",0)/1000))},\
world_active {ReadingsVal("coronaSpreadWorld","world_cases",0)-ReadingsVal("coronaSpreadWorld","world_deaths",0)-ReadingsVal("coronaSpreadWorld","world_recovered",0)},\
world_casesPerOneMillion {ReadingsVal("coronaSpreadWorld","world_cases",0)/7773.452460}


FHEM 6.0 auf rPi4 docker (mit Alexa & Siri); dbLog, FTUI, Sonos, XiaomiMapCreator auf rPi4 docker;
raspimatic auf rPi3+ > diverse Aktoren und Sensoren;
LGW > (PCA301),EC3000,LaCrosse; MQTT2 > WLAN-Steckdosen,Xiaomi Map;
Harmony Hub;Sonos;Onkyo AVR;RGB WLAN Controller;Netatmo;Withings;Unifi;AMAD

Andy89

#80
Zitat von: herrmannj am 26 März 2020, 11:55:07
Nachtrag. Ah, Iran wird auch nicht als "Iran Islamic Republic of" angelegt ? modifizier mal user reading, mal schauen was passiert. Sonst muss ich heute Abend schauen.
genau. Das ist das Problem, dass das Reading nicht angelegt wird.
Das Userreading ist "mein" Problem. Wenn ich das lösche, gibt natürlich auch keinen Fehler im Log. Aber das Reading "Iran, Islamic Republic of_XXX" wird dennoch nicht angelegt. JsonMod ignoriert das einfach. Alle anderen Readings werden korrekt ausgeführt.

Ich versteh nicht, wieso die heute in ihrer API das Land umbennen mussten  ???

Nachtrag: falls du es überhaupt liest. Ich wollte gerade nochmal wegen verbose 5 nachfragen, aber das hast du ja schon in Nachtrag 2 erwähnt  ;D
FHEM 6.0 auf rPi4 docker (mit Alexa & Siri); dbLog, FTUI, Sonos, XiaomiMapCreator auf rPi4 docker;
raspimatic auf rPi3+ > diverse Aktoren und Sensoren;
LGW > (PCA301),EC3000,LaCrosse; MQTT2 > WLAN-Steckdosen,Xiaomi Map;
Harmony Hub;Sonos;Onkyo AVR;RGB WLAN Controller;Netatmo;Withings;Unifi;AMAD

herrmannj

Noch'n Nachtrag. Klar, mindestens bei den Space im Land werde ich nochmal ran müssen. Aktuell sollten die gelöscht werden um einen ReadingNamen daraus zu generieren. Da ist es sicher besser space durch '_' zu ersetzen. Todo.

herrmannj

#82
Zitat von: Andy89 am 26 März 2020, 12:02:30
genau. Das ist das Problem, dass das Reading nicht angelegt wird.
Das Userreading ist "mein" Problem. Wenn ich das lösche, gibt natürlich auch keinen Fehler im Log. Aber das Reading "Iran, Islamic Republic of_XXX" wird dennoch nicht angelegt. JsonMod ignoriert das einfach. Alle anderen Readings werden korrekt ausgeführt.

Ich versteh nicht, wieso die heute in ihrer API das Land umbennen mussten  ???
ok, verstehe. Ja, das schau ich mir an. Also, ist nicht so schlimm, JsonMod soll ja als "Universal Maschine" eben auch mit den seltensten Konstellationen klar kommen, von daher ist es gut das die dass gemacht haben, dann kann ichs fixen.

Edit: Wegen der Api, die hat sich schon dutzende Male geändert. Aber das ist auch ok, gerade hier kann man das ja fix nachziehen. Ein "festes Modul" käme da garnicht hinterher. Ist halt eine "dynamische" Lage ;)

edit2: verbose. Klar ;)

TWART016

Zitat von: Andy89 am 26 März 2020, 11:57:03
hast du heute schon ein FHEM Update gemacht? Das hat erst danach funktioniert.

Ja, ein Update habe ich gemacht. Keine sind mehr verfügbar.

yersinia

#84
Zitat von: herrmannj am 26 März 2020, 11:20:41@yersinia
ja, würde als workaround funktionieren. Aber ich gehe dem Fehler bei Andy nach wenn ich den Fehler verstehe.
Hier der Workaround mit ISO3 Länderkürzel, wer weniger mag kann auch die ISO3 durch ISO2 ersetzen. Länderkürzel entsprechend abändern. es gibt ein weiteres Reading _country, welches das Land aufnimmt.
Als Eingabe für das Attribut ReadingsList:
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_country'), property('country'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_cases'), property('cases'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_todayCases'), property('todayCases'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_active'), property('active'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_deaths'), property('deaths'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_todayDeaths'), property('todayDeaths'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_recovered'), property('recovered'));
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_casesPerOneMillion'), property('casesPerOneMillion'));

oder als Raw:
attr coronaSpread readingList multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_country'), property('country'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_cases'), property('cases'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_todayCases'), property('todayCases'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_active'), property('active'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_deaths'), property('deaths'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_todayDeaths'), property('todayDeaths'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_recovered'), property('recovered'));;\
multi(jsonPath("\$.[?(\@.['countryInfo'].['iso3'] in ['DEU', 'CHN', 'CAN', 'NLD', 'GBR', 'ITA', 'ESP', 'FRA', 'USA'])]"), concat(property('countryInfo.iso3'), '_casesPerOneMillion'), property('casesPerOneMillion'));;


Dann ist mir egal, ob es China oder PRC oder China, People Republic of ist. ;)

EDIT: ergibt Readings wie diese:
[...]
READINGS:
     2020-03-26 14:25:00   CAN_active      3188
     2020-03-26 14:25:00   CAN_cases       3409
     2020-03-26 14:25:00   CAN_casesPerOneMillion 90
     2020-03-26 14:25:00   CAN_country     Canada
     2020-03-26 14:25:00   CAN_deaths      36
     2020-03-26 14:25:00   CAN_recovered   185
     2020-03-26 14:25:00   CAN_todayCases  0
     2020-03-26 14:25:00   CAN_todayDeaths 0
     2020-03-26 14:25:00   CHN_active      3947
     2020-03-26 14:25:00   CHN_cases       81285
     2020-03-26 14:25:00   CHN_casesPerOneMillion 56
     2020-03-26 14:25:00   CHN_country     China
     2020-03-26 14:25:00   CHN_deaths      3287
     2020-03-26 14:25:00   CHN_recovered   74051
     2020-03-26 14:25:00   CHN_todayCases  67
     2020-03-26 14:25:00   CHN_todayDeaths 6
     2020-03-26 14:25:00   DEU_active      35389
     2020-03-26 14:25:00   DEU_cases       39572
     2020-03-26 14:25:00   DEU_casesPerOneMillion 472
     2020-03-26 14:25:00   DEU_country     Germany
     2020-03-26 14:25:00   DEU_deaths      224
     2020-03-26 14:25:00   DEU_recovered   3959
     2020-03-26 14:25:00   DEU_todayCases  2249
     2020-03-26 14:25:00   DEU_todayDeaths 18
[...]


ISO Codes kann man sich aus der Quelle raussuchen oder Wikipedia bemühen.
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | 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

fh168

Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-

herrmannj

Hallo robin,

Gefällt mir. Aber schau mal den thread hier in Ruhe durch. Die hier erarbeitete Lösung ist vielseitiger, flexibler und umfangreicher.

vg
Joerg

Gisbert

Hallo Jörg,

ich hatte gestern deine Defimition aus dem 1. Thread probiert, und das hat soweit funktioniert.

Dann habe ich die Definition erweitert (mehr Länder und weitere Abfragen), bekomme dann aber keine neuen Readings, stattdessen einen log-Eintrag.

Meine raw-Definition:

defmod coronaSpread JsonMod https://corona.lmao.ninja/countries
attr coronaSpread interval */30 * * * *
attr coronaSpread readingList multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_cases'), property('cases'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_todayCases'), property('todayCases'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_active'), property('active'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_deaths'), property('deaths'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_deathstoday'), property('todayDeaths'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_recovered'), property('recovered'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_critical'), property('critical'));;\
multi(jsonPath("\$.[?(\@.country in ['Austria', 'Germany', 'Italy', 'Spain', 'France', UK', 'USA'])]"), concat(property('country'), '_cpm'), property('casesPerOneMillion'));;


Der log-Eintrag bei jeder Abfrage:
2020.03.27 03:00:00 3:  IP: corona.lmao.ninja -> 104.18.36.204
2020.03.27 03:00:00 3:  https://corona.lmao.ninja/countries: HTTP response code 200
2020.03.27 03:00:01 2:  [coronaSpread] error while evaluating readingList: unbalanced square brackets in JsonPath filter:  at .//FHEM/98_JsonMod.pm line 1276.


Kannst du schauen, ob ich ggf. was falsch verstanden habe?

Viele​ Grüße​ Gisbert​
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

herrmannj


Gisbert

Hallo Jörg,

wollte gerade meinen Beitrag editieren, da mir das fehlende Hochkomma bei UK auch aufgefallen war. Damit bleiben die log-Einträge jetzt aus, aber neue Readings leider auch. Ich werde das bis morgen beobachten und melde mich dann ggf.

Viele​n Dank und viele​ Grüße​
Gisbert​
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome