Local Warnings API (mainly Germany) for fire and other it

Tags: #<Tag:0x00007efec679cc48>

Living in Germany I’m wondering if there’s some API for warnings like local fires or other noteworthy incidents. Last week there was a water contamination nearby. As we don’t listen to local radio I’m thinking of using APIs for those warnings - but I didn’t find one yet. There’s a bunch of apps like NINA or KATWARN but they don’t seem to offer an API?

Anyone knows a source for this?

1 Like

I found some pretty reliable german sources in the meantime (thanks @cweitkamp)
Some birds whispered the following information about NINA to me:

https://warnung.bund.de/bbk.config/config_rel.json
https://warnung.bund.de/bbk.mowas/gefahrendurchsagen.json

Source: https://warnung.bund.de

The JSON combines warnings from DWD, MoWas and Hochwasserzentrale.

If my time allows, I’ll post my configuration in a few weeks! :smile:

1 Like

Hey Thomas,
did yout time allowed you to find a configuration?

1 Like

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.

I would be also very interested in this information. because I guess I am living close to you and we were faced with the same storm.

Do you have any updates?

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

1 Like

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

The “sn”-variable was used in my other python-script. I removed “sn”, please update at least the “def get_json_as_dict” (line 35 - 57).

What bugs me, is the line 70 error, please try again after updating…

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).

1 Like

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

  1. 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
  1. 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! :wink:

1 Like

just an fyi: updated my github to v0.5.0:

  • now there’s an ini-file for the settings
  • Added loglevel=DEBUG for more detailed information
  • added Pavo-MQTT for integrated MQTT-client
  • fixed a few minor bugs

still a bit rough, but should work fine…

1 Like

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. :smiley:


  File "mowas_mqtt.py", line 8, in <module>
    import paho.mqtt.client as mqtt                         # using MQTT-client
ModuleNotFoundError: No module named 'paho'
1 Like

hehe! :wink:
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.

Hi and thank you so much for this little script!

I cloned the lates git and it would not send mqtt messages for me - i bleive you forgot the payload.
I fixed it and created a PR on github :slight_smile:

All the best,

Bob

1 Like

Thanks bud!
Didn’t notice it! :wink:

Thanks for the catch.

1 Like

I just updated the git to v0.6.0 you can now switch and use either Paho-Client or the OS.system. Just change the “Paho” setting in the ini to “False”.

1 Like