Inspiriert durch dieses Thema (https://forum.fhem.de/index.php?topic=109413.new;topicseen#new) habe ich die Funktion hashKeyRename in fhem.pl eigebaut, um JSONs der Sorte [{"name":"temp","value":"17"},{"name":"hum","value":"80"}] in besser auswertbare Readings umzuwandeln.
Dieses JSON wird in MQTT2_DEVICE mit der readingsList Zeile
topicName:.* { hashKeyRename(json2nameValue($EVENT), "^([0-9]+)_name:(.*)","^([0-9]+)_value") }
zu den Readings
Zitat
temp 17
hum 80
fuehren, ohne hashKeyRename schaut es so aus:
Zitat0_name temp
0_value 17
1_name hum
1_value 80
json2reading habe ich auch mit einem optionalen Parameter erweitert, damit kann man die Seite aus dem verlinkten Thema auch so abfragen:
define lmao at +*01:00 { HttpUtils_NonblockingGet({ url=>"https://corona.lmao.ninja/countries",\
callback=>sub($$$){ Log 1,"lmao:$_[1]" if($_[1]);;\
json2reading($defs{lmao},$_[2],undef,undef,'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')} }) }
Hab mir mit Svn_GetFile fhem.pl geladen, das at über die Kommandozeile angelegt, kein Fehler aber auch keine Readings.
Das Device ist Probably associated with coronaSpread aus dem anderen Thread. ?
Im Log steht:
2020.03.23 18:18:39 1: ERROR evaluating {return undef; { HttpUtils_NonblockingGet({ url=>"https://corona.lmao.ninja/countries",\ callback=>sub($$$){ Log 1,"lmao:$_[1]" if($_[1]);\ json2reading($defs{lmao},$_[2],undef,undef,'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')} }) }}: Too many arguments for main::json2reading at (eval 304) line 1, near "'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')"
Wenn ich auf DEF klicke und wieder auf modify lmao:
Too many arguments for main::json2reading at (eval 324) line 1, near "'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')"
Internals:
COMMAND { HttpUtils_NonblockingGet({ url=>"https://corona.lmao.ninja/countries",\ callback=>sub($$$){ Log 1,"lmao:$_[1]" if($_[1]);\ json2reading($defs{lmao},$_[2],undef,undef,'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')} }) }
DEF +*01:00 { HttpUtils_NonblockingGet({ url=>"https://corona.lmao.ninja/countries",\ callback=>sub($$$){ Log 1,"lmao:$_[1]" if($_[1]);\ json2reading($defs{lmao},$_[2],undef,undef,'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')} }) }
FUUID 5e78e8df-f33f-0353-d17d-e2754c59098ef9e7
NAME lmao
NR 35
NTM 19:05:06
PERIODIC yes
RELATIVE yes
REP -1
STATE Next: 19:05:06
TIMESPEC 01:00
TRIGGERTIME 1584986706.29755
TRIGGERTIME_FMT 2020-03-23 19:05:06
TYPE at
READINGS:
2020-03-23 18:05:06 state Next: 19:05:06
Attributes:
Gruß
Thomas
Ich weiß nicht was beim ersten mal schief lief, hab das Device mal gelöscht und nochmal mit
define lmao at +*01:00 { HttpUtils_NonblockingGet({ url=>"https://corona.lmao.ninja/countries",\
callback=>sub($$$){ Log 1,"lmao:$_[1]" if($_[1]);;\
json2reading($defs{lmao},$_[2],undef,undef,'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')} }) }
über die Kommandozeile versucht, dann kommt doch eine Meldung
Too many arguments for main::json2reading at (eval 360) line 1, near "'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy)","^([0-9]+)")')"
Danke fuer den Hinweis, ich habe die Warnung gefixt.
Nachtrag: der Inhalt schaut jetz anders aus, als heute Mittag, da gab es noch keine Links auf Bilder.
Stehe auf dem Schlauch, kein Warnung mehr, nix im Log, keine neuen Readings, das Device ist immer noch Probably associated with coronaSpread aus dem anderen Thread.
Ohne "set lmao execNow" werden die Daten erst eine Stunde nach dem Anlegen der Definition oder FHEM-Start abgeholt.
Danke, alles wie vorgesehen.
Wollte mal nachfragen ob ein Freeze von >7 Sekunden für normal anzusehen bei Ausführung der u. a. Definition :
2021.01.17 14:22:19 1: Perfmon: possible freeze starting at 14:22:12, delay is 7.289
defmod lmao at +*01:00 { HttpUtils_NonblockingGet({ url=>"https://corona.lmao.ninja/v2/countries",\
callback=>sub($$$){ Log 1,"lmao:$_[1]" if($_[1]);;\
json2reading($defs{lmao},$_[2],undef,undef,'hashKeyRename($ret,"^([0-9]+)_country:(Germany|Italy|Spain|USA|France|Poland)","^([0-9]+)")')} }) }
attr lmao room Test
setstate lmao Next: 15:07:31
setstate lmao 2021-01-17 14:14:55 France_active 2616134
setstate lmao 2021-01-17 14:14:55 France_activePerOneMillion 40031.16
setstate lmao 2021-01-17 14:14:55 France_cases 2894347
setstate lmao 2021-01-17 14:14:55 France_casesPerOneMillion 44288
setstate lmao 2021-01-17 14:14:55 France_continent Europe
setstate lmao 2021-01-17 14:14:55 France_country France
setstate lmao 2021-01-17 14:14:55 France_countryInfo__id 250
setstate lmao 2020-03-30 05:01:11 France_countryInfo_country France
setstate lmao 2021-01-17 14:14:55 France_countryInfo_flag https://disease.sh/assets/img/flags/fr.png
setstate lmao 2021-01-17 14:14:55 France_countryInfo_iso2 FR
setstate lmao 2021-01-17 14:14:55 France_countryInfo_iso3 FRA
setstate lmao 2021-01-17 14:14:55 France_countryInfo_lat 46
setstate lmao 2021-01-17 14:14:55 France_countryInfo_long 2
setstate lmao 2021-01-17 14:14:55 France_critical 2740
setstate lmao 2021-01-17 14:14:55 France_criticalPerOneMillion 41.93
setstate lmao 2021-01-17 14:14:55 France_deaths 70142
setstate lmao 2021-01-17 14:14:55 France_deathsPerOneMillion 1073
setstate lmao 2021-01-17 14:14:55 France_oneCasePerPeople 23
setstate lmao 2021-01-17 14:14:55 France_oneDeathPerPeople 932
setstate lmao 2021-01-17 14:14:55 France_oneTestPerPeople 2
setstate lmao 2021-01-17 14:14:55 France_population 65352445
setstate lmao 2021-01-17 14:14:55 France_recovered 208071
setstate lmao 2021-01-17 14:14:55 France_recoveredPerOneMillion 3183.83
setstate lmao 2021-01-17 14:14:55 France_tests 39548718
setstate lmao 2021-01-17 14:14:55 France_testsPerOneMillion 605160
setstate lmao 2021-01-17 14:14:55 France_todayCases 0
setstate lmao 2021-01-17 14:14:55 France_todayDeaths 0
setstate lmao 2021-01-17 14:14:55 France_todayRecovered 0
setstate lmao 2020-06-02 04:42:37 France_undefined 47
setstate lmao 2021-01-17 14:14:55 France_updated 1610888247729
setstate lmao 2021-01-17 14:14:55 Germany_active 333624
setstate lmao 2021-01-17 14:14:55 Germany_activePerOneMillion 3975.01
setstate lmao 2021-01-17 14:14:55 Germany_cases 2038645
setstate lmao 2021-01-17 14:14:55 Germany_casesPerOneMillion 24290
setstate lmao 2021-01-17 14:14:55 Germany_continent Europe
setstate lmao 2021-01-17 14:14:55 Germany_country Germany
setstate lmao 2021-01-17 14:14:55 Germany_countryInfo__id 276
setstate lmao 2020-03-30 05:01:11 Germany_countryInfo_country Germany
setstate lmao 2021-01-17 14:14:55 Germany_countryInfo_flag https://disease.sh/assets/img/flags/de.png
setstate lmao 2021-01-17 14:14:55 Germany_countryInfo_iso2 DE
setstate lmao 2021-01-17 14:14:55 Germany_countryInfo_iso3 DEU
setstate lmao 2021-01-17 14:14:55 Germany_countryInfo_lat 51
setstate lmao 2021-01-17 14:14:55 Germany_countryInfo_long 9
setstate lmao 2021-01-17 14:14:55 Germany_critical 5074
setstate lmao 2021-01-17 14:14:55 Germany_criticalPerOneMillion 60.45
setstate lmao 2021-01-17 14:14:55 Germany_deaths 47121
setstate lmao 2021-01-17 14:14:55 Germany_deathsPerOneMillion 561
setstate lmao 2021-01-17 14:14:55 Germany_oneCasePerPeople 41
setstate lmao 2021-01-17 14:14:55 Germany_oneDeathPerPeople 1781
setstate lmao 2021-01-17 14:14:55 Germany_oneTestPerPeople 2
setstate lmao 2021-01-17 14:14:55 Germany_population 83930260
setstate lmao 2021-01-17 14:14:55 Germany_recovered 1657900
setstate lmao 2021-01-17 14:14:55 Germany_recoveredPerOneMillion 19753.3
setstate lmao 2021-01-17 14:14:55 Germany_tests 36353196
setstate lmao 2021-01-17 14:14:55 Germany_testsPerOneMillion 433136
setstate lmao 2021-01-17 14:14:55 Germany_todayCases 0
setstate lmao 2021-01-17 14:14:55 Germany_todayDeaths 0
setstate lmao 2021-01-17 14:14:55 Germany_todayRecovered 0
setstate lmao 2020-06-02 04:42:37 Germany_undefined 21
setstate lmao 2021-01-17 14:14:55 Germany_updated 1610888247736
setstate lmao 2021-01-17 14:14:55 Italy_active 557717
setstate lmao 2021-01-17 14:14:55 Italy_activePerOneMillion 9231.72
setstate lmao 2021-01-17 14:14:55 Italy_cases 2368733
setstate lmao 2021-01-17 14:14:55 Italy_casesPerOneMillion 39209
setstate lmao 2021-01-17 14:14:55 Italy_continent Europe
setstate lmao 2021-01-17 14:14:55 Italy_country Italy
setstate lmao 2021-01-17 14:14:55 Italy_countryInfo__id 380
setstate lmao 2020-03-30 05:01:11 Italy_countryInfo_country Italy
setstate lmao 2021-01-17 14:14:55 Italy_countryInfo_flag https://disease.sh/assets/img/flags/it.png
setstate lmao 2021-01-17 14:14:55 Italy_countryInfo_iso2 IT
setstate lmao 2021-01-17 14:14:55 Italy_countryInfo_iso3 ITA
setstate lmao 2021-01-17 14:14:55 Italy_countryInfo_lat 42.8333
setstate lmao 2021-01-17 14:14:55 Italy_countryInfo_long 12.8333
setstate lmao 2021-01-17 14:14:55 Italy_critical 2520
setstate lmao 2021-01-17 14:14:55 Italy_criticalPerOneMillion 41.71
setstate lmao 2021-01-17 14:14:55 Italy_deaths 81800
setstate lmao 2021-01-17 14:14:55 Italy_deathsPerOneMillion 1354
setstate lmao 2021-01-17 14:14:55 Italy_oneCasePerPeople 26
setstate lmao 2021-01-17 14:14:55 Italy_oneDeathPerPeople 739
setstate lmao 2021-01-17 14:14:55 Italy_oneTestPerPeople 2
setstate lmao 2021-01-17 14:14:55 Italy_population 60413129
setstate lmao 2021-01-17 14:14:55 Italy_recovered 1729216
setstate lmao 2021-01-17 14:14:55 Italy_recoveredPerOneMillion 28623.18
setstate lmao 2021-01-17 14:14:55 Italy_tests 28994914
setstate lmao 2021-01-17 14:14:55 Italy_testsPerOneMillion 479944
setstate lmao 2021-01-17 14:14:55 Italy_todayCases 0
setstate lmao 2021-01-17 14:14:55 Italy_todayDeaths 0
setstate lmao 2021-01-17 14:14:55 Italy_todayRecovered 0
setstate lmao 2020-06-02 04:42:37 Italy_undefined 15
setstate lmao 2021-01-17 14:14:55 Italy_updated 1610888247733
setstate lmao 2021-01-17 14:14:55 Poland_active 220901
setstate lmao 2021-01-17 14:14:55 Poland_activePerOneMillion 5840.25
setstate lmao 2021-01-17 14:14:55 Poland_cases 1435582
setstate lmao 2021-01-17 14:14:55 Poland_casesPerOneMillion 37954
setstate lmao 2021-01-17 14:14:55 Poland_continent Europe
setstate lmao 2021-01-17 14:14:55 Poland_country Poland
setstate lmao 2021-01-17 14:14:55 Poland_countryInfo__id 616
setstate lmao 2020-03-30 05:01:11 Poland_countryInfo_country Poland
setstate lmao 2021-01-17 14:14:55 Poland_countryInfo_flag https://disease.sh/assets/img/flags/pl.png
setstate lmao 2021-01-17 14:14:55 Poland_countryInfo_iso2 PL
setstate lmao 2021-01-17 14:14:55 Poland_countryInfo_iso3 POL
setstate lmao 2021-01-17 14:14:55 Poland_countryInfo_lat 52
setstate lmao 2021-01-17 14:14:55 Poland_countryInfo_long 20
setstate lmao 2021-01-17 14:14:55 Poland_critical 1651
setstate lmao 2021-01-17 14:14:55 Poland_criticalPerOneMillion 43.65
setstate lmao 2021-01-17 14:14:55 Poland_deaths 33355
setstate lmao 2021-01-17 14:14:55 Poland_deathsPerOneMillion 882
setstate lmao 2021-01-17 14:14:55 Poland_oneCasePerPeople 26
setstate lmao 2021-01-17 14:14:55 Poland_oneDeathPerPeople 1134
setstate lmao 2021-01-17 14:14:55 Poland_oneTestPerPeople 5
setstate lmao 2021-01-17 14:14:55 Poland_population 37823912
setstate lmao 2021-01-17 14:14:55 Poland_recovered 1181326
setstate lmao 2021-01-17 14:14:55 Poland_recoveredPerOneMillion 31232.25
setstate lmao 2021-01-17 14:14:55 Poland_tests 8014701
setstate lmao 2021-01-17 14:14:55 Poland_testsPerOneMillion 211895
setstate lmao 2021-01-17 14:14:55 Poland_todayCases 6055
setstate lmao 2021-01-17 14:14:55 Poland_todayDeaths 142
setstate lmao 2021-01-17 14:14:55 Poland_todayRecovered 8239
setstate lmao 2020-06-02 04:42:37 Poland_undefined 41
setstate lmao 2021-01-17 14:14:55 Poland_updated 1610888247742
setstate lmao 2021-01-17 14:14:55 Spain_active 2198850
setstate lmao 2021-01-17 14:14:55 Spain_activePerOneMillion 47019.45
setstate lmao 2021-01-17 14:14:55 Spain_cases 2252164
setstate lmao 2021-01-17 14:14:55 Spain_casesPerOneMillion 48160
setstate lmao 2021-01-17 14:14:55 Spain_continent Europe
setstate lmao 2021-01-17 14:14:55 Spain_country Spain
setstate lmao 2021-01-17 14:14:55 Spain_countryInfo__id 724
setstate lmao 2020-03-30 05:01:11 Spain_countryInfo_country Spain
setstate lmao 2021-01-17 14:14:55 Spain_countryInfo_flag https://disease.sh/assets/img/flags/es.png
setstate lmao 2021-01-17 14:14:55 Spain_countryInfo_iso2 ES
setstate lmao 2021-01-17 14:14:55 Spain_countryInfo_iso3 ESP
setstate lmao 2021-01-17 14:14:55 Spain_countryInfo_lat 40
setstate lmao 2021-01-17 14:14:55 Spain_countryInfo_long -4
setstate lmao 2021-01-17 14:14:55 Spain_critical 2953
setstate lmao 2021-01-17 14:14:55 Spain_criticalPerOneMillion 63.15
setstate lmao 2021-01-17 14:14:55 Spain_deaths 53314
setstate lmao 2021-01-17 14:14:55 Spain_deathsPerOneMillion 1140
setstate lmao 2021-01-17 14:14:55 Spain_oneCasePerPeople 21
setstate lmao 2021-01-17 14:14:55 Spain_oneDeathPerPeople 877
setstate lmao 2021-01-17 14:14:55 Spain_oneTestPerPeople 2
setstate lmao 2021-01-17 14:14:55 Spain_population 46764686
setstate lmao 2021-01-17 14:14:55 Spain_recovered 0
setstate lmao 2021-01-17 14:14:55 Spain_recoveredPerOneMillion 0
setstate lmao 2021-01-17 14:14:55 Spain_tests 28775103
setstate lmao 2021-01-17 14:14:55 Spain_testsPerOneMillion 615317
setstate lmao 2021-01-17 14:14:55 Spain_todayCases 0
setstate lmao 2021-01-17 14:14:55 Spain_todayDeaths 0
setstate lmao 2021-01-17 14:14:55 Spain_todayRecovered 0
setstate lmao 2020-06-02 04:42:37 Spain_undefined 12
setstate lmao 2021-01-17 14:14:55 Spain_updated 1610888247734
setstate lmao 2021-01-17 14:14:55 USA_active 9557138
setstate lmao 2021-01-17 14:14:55 USA_activePerOneMillion 28781.28
setstate lmao 2021-01-17 14:14:55 USA_cases 24306043
setstate lmao 2021-01-17 14:14:55 USA_casesPerOneMillion 73198
setstate lmao 2021-01-17 14:14:55 USA_continent North America
setstate lmao 2021-01-17 14:14:55 USA_country USA
setstate lmao 2021-01-17 14:14:55 USA_countryInfo__id 840
setstate lmao 2020-03-30 05:01:11 USA_countryInfo_country USA
setstate lmao 2021-01-17 14:14:55 USA_countryInfo_flag https://disease.sh/assets/img/flags/us.png
setstate lmao 2021-01-17 14:14:55 USA_countryInfo_iso2 US
setstate lmao 2021-01-17 14:14:55 USA_countryInfo_iso3 USA
setstate lmao 2021-01-17 14:14:55 USA_countryInfo_lat 38
setstate lmao 2021-01-17 14:14:55 USA_countryInfo_long -97
setstate lmao 2021-01-17 14:14:55 USA_critical 28850
setstate lmao 2021-01-17 14:14:55 USA_criticalPerOneMillion 86.88
setstate lmao 2021-01-17 14:14:55 USA_deaths 405261
setstate lmao 2021-01-17 14:14:55 USA_deathsPerOneMillion 1220
setstate lmao 2021-01-17 14:14:55 USA_oneCasePerPeople 14
setstate lmao 2021-01-17 14:14:55 USA_oneDeathPerPeople 819
setstate lmao 2021-01-17 14:14:55 USA_oneTestPerPeople 1
setstate lmao 2021-01-17 14:14:55 USA_population 332060944
setstate lmao 2021-01-17 14:14:55 USA_recovered 14343644
setstate lmao 2021-01-17 14:14:55 USA_recoveredPerOneMillion 43195.82
setstate lmao 2021-01-17 14:14:55 USA_tests 283753126
setstate lmao 2021-01-17 14:14:55 USA_testsPerOneMillion 854521
setstate lmao 2021-01-17 14:14:55 USA_todayCases 0
setstate lmao 2021-01-17 14:14:55 USA_todayDeaths 0
setstate lmao 2021-01-17 14:14:55 USA_todayRecovered 0
setstate lmao 2020-06-02 04:42:37 USA_undefined 18
setstate lmao 2021-01-17 14:14:55 USA_updated 1610888247720
setstate lmao 2020-03-24 13:47:25 godd n
setstate lmao 2021-01-17 14:07:31 state Next: 15:07:31
Raspberry Pi 3 Model B Rev 1.2
Auf einem relativ aktuellen, "normalen" Intel-Notebook dauert das Verarbeiten 0.9 Sekunden, insofern sind vmtl. 7 Sekunden auf dem RPi 3 normal anzusehen.
json2nameValue dauert bei mir 0.89 Sekunden, und erzeugt ca 6200 Einzelwerte, HashKeyRename und der Rest schlaegt nur noch mit 0.01s zu.
Das JSON Parsen ist halt komplett in Perl, und Geschwindigkeits-Optimieren war keine Prio.
etwas semiOT - @TomLee, da es anscheinend Corona-Zahlen sind, wäre JSON-Mod Corona-Verbreitung (https://forum.fhem.de/index.php/topic,109413.0.html) (mit adaptierten multipath (https://forum.fhem.de/index.php/topic,109413.msg1035304.html#msg1035304)) keine Option für dich?
Danke für das danach schauen und erläutern.
@yersinia
Danke nett gemeint, aber wie man sieht befindet sich die Definition im Raum Test und wurde ursprünglich auch von mir nur zum Test/nachvollziehen erstellt.
Hätt ich damals keine kleine simple mobile-FTUI-Seite zur Darstellung der Daten auf dem Handy meiner Mutter erstellt und die sich das heute immer noch mehr oder weniger regelmäßig antun muss anzuschauen, wäre diese Definition schon längst im Nirvana verschwunden, selbst geb ich mir das mit Sicherheit nicht.