For the time being, I’m stuck at configuring the polygons for my location. I installed both “Warnwetter” and “KATWARN/NINA” apps on my mobile, which send me pushes - and I can react accordingly. This worked yesterday with the heavy hail storm in Bavaria…
of course I’d like to have this also automated (e.g. shutter automation), but for now I’m lacking the understanding of the polygons of the JSON.
Unfortunately not regarding openHAB. I just didn’t get it to work to find a geolocation in the “polygon” given in the warnings… Thing is, there’s warning regarding my (small) home town, the district I live in, or the state… And sometimes the “geocode” is formatted a bit different - but the polygon is always spanning around my location…
So I installed the App “KATWARN”, which sends push-notifications and this works for me. Perhaps if someone can figure out a service/script/… which can tell, if a geolocation is within a polygon, then you could add this into a NextGen rule with e.g. python, …
What I do have is the dwdUnwetter-binding, which at least warns me on thunderstorms and stuff (and can retract my blinds) - but not on other warnings like water quality, big fires, …
While looking for new services/APIs to integrate I found this thread. Right now I am thinking about a solution for the polygons but for now I am fine with filtering the JSON by state (DE-NI for example).
I have a string item which will process the data further after the item is updated.
This is my state expression:
JSONPATH:$.[*].[?(@.identifier contains “DE-NI”)]
Which unfortunately only works in JSONPath Validator but not in OpenHAB. Trying to figure the correct syntax now.
While switching to openHAB3 I also renewed my approach to this. As the JSON is quite large presently (Corona situations in all of Germany) I switched to preprocessing the available information and putting together an JSON for that (without the polygon information).
There’s a JSON available for your region, providing us with all Identifiers for the warnings, collects the information from the five sources and combines this to a relevant JSON.
That JSON can then be provided to openHAB and you can do your magic there.
You can find the script (a bit rough) here:
I send the JSON to node-red, process it even further and update my warning items via MQTT
Thank you, I tried executing the script on the shell directly first but I had some errors while executing:
File "mowas_mqtt.py", line 43, in get_json_as_dict
return json.loads('{"data": {"HTTP Error": 1, "URL": "'+url+'", "serial": "'+sn+'", "error": "'+str(r.status_code)+'"}}')
NameError: global name 'sn' is not defined
Here I just left out the sn part but I am not too much into python right now to understand how to fix this error:
File "mowas_mqtt.py", line 70, in <module>
keys = bucket['bucketname'].split(".")
TypeError: string indices must be integers
I think I know, what’s happening, please make sure, you have the AGS from your “Landkreis”, there’s only dedicated JSONs for Landkreise, not specific cities.
My guess is, the URL is a 404, and I did not include a check on a correct return of the first JSON yet.
e.g. I have to use “Landkreis Augsburg” (09772000000") and not “Augsburg” (09761000).
I thought that could be the problem because I used 03241001 for the city but I just tried it with 03241000000 for Hannover but it gives the same error. Tried it too with 1 at the end. and it looks like 404 yes
And can you give me a hint on what to add if I want to drop all buckets containing “COVID” ?
There’s a bit of a confusion in documentation on how to write the AGS correctly.
sometimes I see it with trailing 000000, sometimes just the first five characters.
The JSON nevertheless for “Landkreis Region Hannover” is here: https://warnung.bund.de/bbk.status/status_032410000000.json
so, using 032410000000 in the current version on github should do the trick.
one thing is, that there’s no instance ov “Covid”, but “Corona” and then it’s only in the descriptive texts, and then also there’s different spellings:
So, you could search for “Corona” and drop the information also. I’d like to have all warnings sorted out, if like e.g. the local government decides for new means for containing the spread.
But you could do something along the lines of
inserting a function to search in a python dictionary:
def search_in_dict (values, searchterm):
for k in values:
for v in values[k]:
if searchterm in v:
return True
return False
inserting the search in (current) line 91
if (announcementJSON[j]["identifier"] == meldewert):
if (search_in_dict(announcementJSON[j], "Corona" == False):
JSONreturn[i] = announcementJSON[j]
JSONreturn[i]["info"][0]["area"][0].pop("polygon")
j = j+1
so, the if-clause should find “False”, if there’s no “Corona”, meaning it will add the warning to the JSON, and True, if there’s Corona in there and then do nothing. But it’s untested!
I added the ) and now it is running but the output seems to be incorrect (other Cities and Corona in it) so I am now trying with the new version but I dont have paho installed and trying to get it installed for the right python version now. Honestly I was happy with the use of the mosquitto client which was already installed on my MQTT Broker Pi.
File "mowas_mqtt.py", line 8, in <module>
import paho.mqtt.client as mqtt # using MQTT-client
ModuleNotFoundError: No module named 'paho'
hehe!
it is a really dirty hack, because you’ll OS.write the whole MQTT thing, but if your environment is installed properly, you just have to use pip install paho-mqtt, which will do all the work for you and install and configure the corresponding library.