[SOLVED] JSON Path weather warnings DWD (Deutscher Wetterdienst)


(Vincent Regaud) #21
jsonResult =JSON.stringify(newJSON.warnings.['113003000'][0]);

(Stefan) #22

same issue


(Vincent Regaud) #23
	var String jsonString = sendHttpGetRequest("https://www.dwd.de/DWD/warnungen/warnapp/json/warnings.json")
        logInfo("TEST1", jsonString)
	var String newString = transform("JS", "getDWDjson.js", jsonstring)
        logInfo("TEST2", newString)
        logInfo("TEST1", transform("JSONPATH", "$.start", newString))
	DWD_Unwetter_start.postUpdate(transform("JSONPATH","$.start", newString))
        ....

(Stefan) #24
2018-06-19 14:54:01.844 [INFO ] [eclipse.smarthome.model.script.TEST1] - warnWetter.loadWarnings({"time":1529412466000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
2018-06-19 14:54:01.850 [INFO ] [eclipse.smarthome.model.script.TEST2] - warnWetter.loadWarnings({"time":1529412466000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
2018-06-19 14:54:01.864 [INFO ] [eclipse.smarthome.model.script.TEST1] - warnWetter.loadWarnings({"time":1529412466000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});

(Richard) #25

Hello!

With this transformation:

(function(jsonString) {
    var newString = jsonString.replace('warnWetter.loadWarnings(','');
    newString = newString.replace(');','');
    var newJSON = JSON.parse(newString);
    var jsonResult = "";
    if (newJSON.warnings.hasOwnProperty('113003000')) {
         jsonResult =JSON.stringify(newJSON.warnings['113003000'][0]);

    } else jsonResult = 'NULL'
    return jsonResult;
    })(input)

and this rule (changed jsonstring to jsonString)

rule "Unwetterwarnung DWD"
when
   Time cron "0 * * ? * *"     
then
	var String jsonString = sendHttpGetRequest("https://www.dwd.de/DWD/warnungen/warnapp/json/warnings.json")
        logInfo("TEST1", jsonString)
	var String newString = transform("JS", "getDWDjson.js", jsonString)
        logInfo("TEST2", newString)
        logInfo("TEST1", transform("JSONPATH", "$.start", newString))
	DWD_Unwetter_start.postUpdate(transform("JSONPATH","$.start", newString))
	DWD_Unwetter_end.postUpdate(transform("JSONPATH","$.end",jsonString))
	DWD_Unwetter_level.postUpdate(transform("JSONPATH","$.level",jsonString))
	DWD_Unwetter_description.postUpdate(transform("JSONPATH","$.description",jsonString))
	DWD_Unwetter_headline.postUpdate(transform("JSONPATH","$.headline",jsonString))
	DWD_Unwetter_instruction.postUpdate(transform("JSONPATH","$.instruction",jsonString))
	DWD_Unwetter_event.postUpdate(transform("JSONPATH","$.event",jsonString))
	DWD_Unwetter_last_update.postUpdate(new DateTimeType())
end

the result in the item

String		DWD_Unwetter_start					"Start: [%s]"				

looks like this: "Start: {“regionName”:"Hansestadt


and

String		DWD_Unwetter_end					"Ende: [%s]"

containes: “Ende: warnWetter.loadWarnings({”


Logging from OpenHab says:

[eclipse.smarthome.model.script.TEST1] - warnWetter.loadWarnings({"time":1529413111000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
2018-06-19 15:09:00.276 [INFO ] [eclipse.smarthome.model.script.TEST2] - {"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}
2018-06-19 15:09:00.278 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.280 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.284 [INFO ] [eclipse.smarthome.model.script.TEST1] - {"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}
2018-06-19 15:09:00.287 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.289 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.293 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.295 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.299 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.301 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.306 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.307 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.312 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.313 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.319 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.320 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.
2018-06-19 15:09:00.324 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH
2018-06-19 15:09:00.326 [WARN ] [ore.transform.actions.Transformation] - No transformation service 'JSONPATH' could be found.

(Jerome) #26

You have to install the JSONPATH transformation service for your test first.


(Richard) #27

Thank you! For OpenHAB you need four eyes: one for the items, one for the sitemap, one for the rules and 
 one for the Bindings/Transformations. :slight_smile:

Installed via PaperUI -> AddOns -> Transformations: “JSONPath Transformation”

But 
 OH is not happy:

2018-06-19 15:20:00.342 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.event' in 'warnWetter.loadWarnings({"time":1529413751000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});'


(Jerome) #28

You are using jsonString in your test items, which hasn’t been cleared by the javascript transformation.
Due to this the json string is still malformed and prduces an error.
You have to use newString like here:

// Correct with newString
DWD_Unwetter_start.postUpdate(transform("JSONPATH","$.start", newString))

// Wrong with jsonstring
DWD_Unwetter_end.postUpdate(transform("JSONPATH","$.end",jsonString))

@ topic:

Really strange. If i use https://codebeautify.org/jsonpath-tester for the whole json file (without that malforming)
it works for $.warnings['113003000'][0].start but if i just grab the one warning it doesnt find the timestamp for start.


(Jerome) #29

@The-Elk could you please try:

var String jsonString = sendHttpGetRequest("https://www.dwd.de/DWD/warnungen/warnapp/json/warnings.json")
logInfo("TEST1", jsonString)
var String newString = transform("JS", "getDWDjson.js", jsonString)
logInfo("TEST2", newString)
logInfo("TEST1", transform("JSONPATH", "$.start", newString))

There was again a mistake with the capitalized variable.
jsonstring and jsonString are two different variables and openHAB can’t find the first one, since you never initialized it.


(Stefan) #30

the test was with this correction jsonstring and jsonString

I saw it and correct it before, but thanks for this hint.


(Jerome) #31

Please check again if there was a typo maybe.


Is working for me.

15:39:03.553 [INFO ] [arthome.model.script.Plain DWD String] - warnWetter.loadWarnings({"time":1529415041000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
15:39:04.127 [INFO ] [e.model.script.Transformed DWD String] - {"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}
15:39:04.137 [INFO ] [.smarthome.model.script.JSONPATH Test] - 1529388000000

So basically the Javascript function and the returned json are working.


(Stefan) #32

rule:

var String jsonString = sendHttpGetRequest("https://www.dwd.de/DWD/warnungen/warnapp/json/warnings.json")
        logInfo("Plain DWD String", jsonString)
	var String newString = transform("JS", "getDWDjson.js", jsonString)
        logInfo("Transform DWD String", newString)
        logInfo("JSONPATH Test", transform("JSONPATH", "$.start", newString))

getDWDjson.js in transfom folder

(function(jsonString) {
var newString = jsonString.replace('warnWetter.loadWarnings(','');
newString = newString.replace(');','');
var newJSON = JSON.parse(newString);
var jsonResult = "";
if (newJSON.warnings.hasOwnProperty('501000008')) {
	jsonResult =JSON.stringify(newJSON.warnings.['501000008'][0]);
} else jsonResult = 'NULL'
return jsonResult;
})(input)

log:

2018-06-19 16:02:00.189 [INFO ] [rthome.model.script.Plain DWD String] - warnWetter.loadWarnings({"time":1529416336000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
2018-06-19 16:02:00.198 [INFO ] [me.model.script.Transform DWD String] - warnWetter.loadWarnings({"time":1529416336000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
2018-06-19 16:02:00.206 [INFO ] [smarthome.model.script.JSONPATH Test] - warnWetter.loadWarnings({"time":1529416336000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});

(Jerome) #33

Here is the wrong part:

jsonResult =JSON.stringify(newJSON.warnings.['501000008'][0]);

Correction:

newJSON.warnings.['501000008'][0]

should be

newJSON.warnings['501000008'][0]

(Stefan) #34

@Confectrician Now the Test log file works

2018-06-19 16:21:00.184 [INFO ] [rthome.model.script.Plain DWD String] - warnWetter.loadWarnings({"time":1529417621000,"warnings":{"501000008":[{"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"113003000":[{"regionName":"Hansestadt Rostock","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073002":[{"regionName":"Kreis Vorpommern-RĂŒgen - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"913073003":[{"regionName":"Kreis Vorpommern-RĂŒgen - Insel RĂŒgen","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"501000006":[{"regionName":"Flensburg bis Fehmarn","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"501000007":[{"regionName":"Östlich Fehmarn bis RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}],"913072002":[{"regionName":"Kreis Rostock - KĂŒste","start":1529388000000,"end":1529431200000,"type":1,"state":"Mecklenburg-Vorpommern","level":2,"stateShort":"MV","description":"Es treten Windböen mit Geschwindigkeiten bis 60 km/h (17m/s, 33kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus nordwestlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}],"901055002":[{"regionName":"Kreis Ostholstein - KĂŒste","start":1529370000000,"end":1529424000000,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"Es treten Windböen mit Geschwindigkeiten um 55 km/h (15m/s, 30kn, Bft 7) anfangs aus sĂŒdwestlicher, spĂ€ter aus westlicher Richtung auf.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche WARNUNG vor WINDBÖEN","instruction":"","event":"WINDBÖEN"}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"});
2018-06-19 16:21:00.368 [INFO ] [me.model.script.Transform DWD String] - {"regionName":"Östlich RĂŒgen","start":1529350320000,"end":null,"type":1,"state":"Schleswig-Holstein","level":2,"stateShort":"SH","description":"SĂŒdwest bis West 5 bis 6, dabei Böen von 7 Beaufort.","altitudeStart":null,"altitudeEnd":null,"headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor STARKWIND","instruction":"","event":"STARKWIND"}
2018-06-19 16:21:00.374 [INFO ] [smarthome.model.script.JSONPATH Test] - 1529350320000

But my items file got the same completely string as before.


(Jerome) #35

Did you switch to newString everywhere or do those items still try to transform jsonString? :slight_smile:

Reference:


(Stefan) #36

While I am waiting, I double check my rule and changed it by myself. now it looks good.

now it’s time for optimizing


(Stefan) #37

Now I tried to convert UNIX time to DateTime.
But it do not work

items

DateTime	DWD_Unwetter_start					"Start: [%1$tm/%1$td %1$tH:%1$tM]"

rule

var String newStart = transform("JSONPATH", "$.start", newString)
DWD_Unwetter_start.postUpdate(transform("JS", "unixtime.js", newStart.toString))

unixtime.js

(function(json){
	var otdata = JSON.parse(json);
	var tzoffset = new Date().getTimezoneOffset() * 60000;
	return new Date(otdata.tst * 1000 - tzoffset).toISOString();
})(input)

any Ideas?


(Vincent Regaud) #38

The js transform is not working. I’ll have a look in the morning.


(Richard) #39

Since i updated the rule with “newString”, there are no more warnings:

...
DWD_Unwetter_start.postUpdate(transform("JSONPATH","$.start", newString))
	DWD_Unwetter_end.postUpdate(transform("JSONPATH","$.end",newString))
	DWD_Unwetter_level.postUpdate(transform("JSONPATH","$.level",newString))
	DWD_Unwetter_description.postUpdate(transform("JSONPATH","$.description",newString))
	DWD_Unwetter_headline.postUpdate(transform("JSONPATH","$.headline",newString))
	DWD_Unwetter_instruction.postUpdate(transform("JSONPATH","$.instruction",newString))
	DWD_Unwetter_event.postUpdate(transform("JSONPATH","$.event",newString))
	DWD_Unwetter_last_update.postUpdate(new DateTimeType())

So, for my region, there are actually no weather warnings. Nonetheless there are warnings in the logging:

2018-06-19 20:55:00.188 [INFO ] [me.model.script.Transform DWD String] - NULL
2018-06-19 20:55:00.191 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.start' in 'NULL'
2018-06-19 20:55:00.193 [INFO ] [smarthome.model.script.JSONPATH Test] - NULL
2018-06-19 20:55:00.195 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.start' in 'NULL'
2018-06-19 20:55:00.200 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.end' in 'NULL'
2018-06-19 20:55:00.205 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.level' in 'NULL'
2018-06-19 20:55:00.210 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.description' in 'NULL'
2018-06-19 20:55:00.214 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.headline' in 'NULL'
2018-06-19 20:55:00.219 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.instruction' in 'NULL'
2018-06-19 20:55:00.224 [ERROR] [ore.transform.actions.Transformation] - Error executing the transformation 'JSONPATH': Invalid path '$.event' in 'NULL'

Then i tought about it, how to “use” the results in a rule. Like “IF there is heavy rain/thunder THEN 
 send a notification or start blinking a red light or close all shutters.”

This could only be done, if we know, what possible warnings could ever come.

This link (not shure, if it relates to the method in this thread ) https://maps.dwd.de/geoserver/wfs?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetCapabilities

(from https://www.dwd.de/DE/leistungen/geowebservice/geowebservice.html;jsessionid=0DAAB6E3EAC9264E88F88A1BA084D658.live21073?nn=508722 (on the right side: “getCapabilities-Abfragen”) )

shows something like a “scope” of warnings:

<FeatureType><Name>dwd:Warngebiete_Kreise</Name><Title>Warngebiete des DWD auf Kreisbasis</Title><Abstract>Warngebiete des DWD, basierend auf den Geodaten fĂŒr deutsche Landkreise. Abweichende Unterteilung in Warngebiete z.B. im KĂŒstenbereich. Copyright GeoBasis-DE / BKG (http://www.bkg.bund.de) 2016 (Daten modifiziert)</Abstract><ows:Keywords><ows:Keyword>cap</ows:Keyword><ows:Keyword>Dauerregen</ows:Keyword><ows:Keyword>Eisberg</ows:Keyword><ows:Keyword>ergiebiger Dauerregen</ows:Keyword><ows:Keyword>extrem ergiebiger Dauerregen</ows:Keyword><ows:Keyword>extrem heftiger Starkregen</ows:Keyword><ows:Keyword>extrem schweres Gewitter</ows:Keyword><ows:Keyword>extrem starke Schneeverwehung</ows:Keyword><ows:Keyword>extrem starker Schneefall</ows:Keyword><ows:Keyword>extreme Orkanböen</ows:Keyword><ows:Keyword>extreme Unwetterwarnung</ows:Keyword><ows:Keyword>Frost</ows:Keyword><ows:Keyword>Geographisches Gebiet</ows:Keyword><ows:Keyword>Gewitter</ows:Keyword><ows:Keyword>GlĂ€tte</ows:Keyword><ows:Keyword>Glatteis</ows:Keyword><ows:Keyword>heftiger Starkregen</ows:Keyword><ows:Keyword>Leiterseilschwingung</ows:Keyword><ows:Keyword>Nebel</ows:Keyword><ows:Keyword>Orkanböen</ows:Keyword><ows:Keyword>Schneefall</ows:Keyword><ows:Keyword>Schneeverwehung</ows:Keyword><ows:Keyword>Schweres Gewitter</ows:Keyword><ows:Keyword>starke Schneeverwehung</ows:Keyword><ows:Keyword>starker Schneefall</ows:Keyword><ows:Keyword>starkes Gewitter</ows:Keyword><ows:Keyword>starkes Tauewtter</ows:Keyword><ows:Keyword>Starkregen</ows:Keyword><ows:Keyword>strenger Frost</ows:Keyword><ows:Keyword>Sturmböen</ows:Keyword><ows:Keyword>Tauwetter</ows:Keyword><ows:Keyword>Text</ows:Keyword><ows:Keyword>Tiefsttemperatur</ows:Keyword><ows:Keyword>Tornado</ows:Keyword><ows:Keyword>Tropischer Wirbelsturm</ows:Keyword><ows:Keyword>Tropischer Wirbelsturm (Hurrikan)</ows:Keyword><ows:Keyword>Tropischer Wirbelsturm (Taifun)</ows:Keyword><ows:Keyword>Tsunami</ows:Keyword><ows:Keyword>Turbulenz in wolkenfreier Luft</ows:Keyword><ows:Keyword>Unwetterwarnung</ows:Keyword><ows:Keyword>Vulkanaschewolke</ows:Keyword><ows:Keyword>Warngebiet</ows:Keyword><ows:Keyword>Wetterwarnungen</ows:Keyword><ows:Keyword>Windböen</ows:Keyword><ows:Keyword>XML</ows:Keyword><ows:Keyword>Zyklon</ows:Keyword></ows:Keywords>

I’m not sure, but if this is right, then you could process the warnings in a rule.

Interesting would be a rule " if there ist upcoming ice rain, the close all shutter on the roof". This would prevent damage to the glas windows.

Or, also: “if there ist heavy rain, and there are open windows, then send out an alert to the user”

The item to be processed would be:

String		DWD_Unwetter_event					"Event: [%s]"

(Vincent Regaud) #40
    if (newString != NULL) {
        DWD_Unwetter_start.postUpdate(transform("JSONPATH","$.start", newString))
	DWD_Unwetter_end.postUpdate(transform("JSONPATH","$.end",newString))
	DWD_Unwetter_level.postUpdate(transform("JSONPATH","$.level",newString))
	DWD_Unwetter_description.postUpdate(transform("JSONPATH","$.description",newString))
	DWD_Unwetter_headline.postUpdate(transform("JSONPATH","$.headline",newString))
	DWD_Unwetter_instruction.postUpdate(transform("JSONPATH","$.instruction",newString))
	DWD_Unwetter_event.postUpdate(transform("JSONPATH","$.event",newString))
	DWD_Unwetter_last_update.postUpdate(new DateTimeType())
}