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

cat dwd.log
/bin/sh: 1: /usr/local/bin/dwdweather.sh: not found

then i asked: “which bash” and added this first line:

SHELL=/bin/bash
*/5 * * * * /usr/local/bin/dwdwetter.sh >> /home/user/dwd.log 2>&1

AND discovered that i mixed up “wetter” and “weather”. :slight_smile:

Thank you @der_optimist - Jochen!

Now heading forward to a sitemap or … new territory … HabPanel. :sunny:

For the WDW_warnings.map
10 = Hitze

1 Like

THX and added

Hi Richard,
as you seem to use my script, I want to tell you that there is a bug - at the time I wrote the script, the xml files never hat a “newline” in it. Last week, I had the first warning where the xml file had 2 or 3 lines. awk works per line, that’s why the script won’t work as intended then. You can repair that by adding
tr ‘\n’ ’ ’ |
before each awk command.

Here’s what my skript looks like now:

# check current value of Warnung_1_Event
value_old=$(curl -s "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Event/state")
# download xml for warncellid or ids
rm /etc/openhab2/html/dwd/warnings.xml
wget -q -O /etc/openhab2/html/dwd/warnings.xml "https://maps.dwd.de/geoserver/dwd/ows?service=WFS&version=2.0.0&request=GetFeature&typeName=dwd:Warnungen_Gemeinden&CQL_FILTER=WARNCELLID%20IN%20(%27.....%27)"
if [ ! -s /etc/openhab2/html/dwd/warnings.xml ]; then
	echo "xml-Datei ist leer. Vermutlich kein Internet. Ich geh wieder schlafen..."
	exit
fi
#
# Events
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EVENT>" '{print $2}' | awk -F"</dwd:EVENT>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Event/state"
else
	if [ "$value_old" = "0" ]; then
#		echo "Keine Warnung gefunden, Wert in OH ist schon 0, ich geh wieder schlafen..."
		exit
	fi
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Event/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EVENT>" '{print $3}' | awk -F"</dwd:EVENT>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Event/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Event/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EVENT>" '{print $4}' | awk -F"</dwd:EVENT>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Event/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Event/state"
fi
#
# Severity
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:SEVERITY>" '{print $2}' | awk -F"</dwd:SEVERITY>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Severity/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Severity/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:SEVERITY>" '{print $3}' | awk -F"</dwd:SEVERITY>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Severity/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Severity/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:SEVERITY>" '{print $4}' | awk -F"</dwd:SEVERITY>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Severity/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Severity/state"
fi
#
# Start
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:ONSET>" '{print $2}' | awk -F"</dwd:ONSET>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Start/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "2000-01-01T00:00:00Z" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Start/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:ONSET>" '{print $3}' | awk -F"</dwd:ONSET>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Start/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "2000-01-01T00:00:00Z" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Start/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:ONSET>" '{print $4}' | awk -F"</dwd:ONSET>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Start/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "2000-01-01T00:00:00Z" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Start/state"
fi
#
# End
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EXPIRES>" '{print $2}' | awk -F"</dwd:EXPIRES>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_End/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "2000-01-01T00:00:00Z" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_End/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EXPIRES>" '{print $3}' | awk -F"</dwd:EXPIRES>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_End/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "2000-01-01T00:00:00Z" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_End/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EXPIRES>" '{print $4}' | awk -F"</dwd:EXPIRES>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_End/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "2000-01-01T00:00:00Z" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_End/state"
fi
#
# Group
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EC_GROUP>" '{print $2}' | awk -F"</dwd:EC_GROUP>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Group/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Group/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EC_GROUP>" '{print $3}' | awk -F"</dwd:EC_GROUP>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Group/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Group/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:EC_GROUP>" '{print $4}' | awk -F"</dwd:EC_GROUP>" '{print $1}')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Group/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Group/state"
fi
#
# Parameter
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:PARAMATERVALUE>" '{print $2}' | awk -F"</dwd:PARAMATERVALUE>" '{print $1}' | sed 's/&lt;/</g' | sed 's/&gt;/>/g')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Parameter/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_1_Parameter/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:PARAMATERVALUE>" '{print $3}' | awk -F"</dwd:PARAMATERVALUE>" '{print $1}' | sed 's/&lt;/</g' | sed 's/&gt;/>/g')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Parameter/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_2_Parameter/state"
fi
value=$(</etc/openhab2/html/dwd/warnings.xml tr '\n' ' ' | awk -F"<dwd:PARAMATERVALUE>" '{print $4}' | awk -F"</dwd:PARAMATERVALUE>" '{print $1}' | sed 's/&lt;/</g' | sed 's/&gt;/>/g')
if [ -n "$value" ]; then
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Parameter/state"
else
	curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://openhabianpi:8080/rest/items/DWD_Warnung_3_Parameter/state"
fi

1 Like

Hello Stefan,
all worked very well, but after a reboot i get a error message at openhab.log

2018-11-11 14:28:01.040 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'DWD Warnungen': Invalid method signature in method jdk.nashorn.internal.objects.Global.setLastRegExpResultØ2H^G�vüåÑ]ð2H^ßÖè^(3H^ª\KЄÅÚ]X3H^©~ðÙ$dÓZx3H^B
                              êüHa�]�3H^g�û%°@^¸3H^97ݔÔÑZØ3H^^>ê<£j^(4H^ÆéùñÕ_P4H^³>�×

I have no idea what happened. What can I do?

I also wanted the DWD Warnings in openhab, but I didn’t really like the solution with a cron script.

So I decided to build my own binding. It’s currently working on my local openhab installation. I’m thinking about filling a pull request (would be my first), but before I would like to have some comments.

The source code is here: https://github.com/limdul79/openhab2-addons/tree/dwd/addons/binding/org.openhab.binding.dwdunwetter and jars (for 2.4.0 and 2.5.0-SNAPSHORT) can be found here: https://drive.google.com/drive/folders/1vUTIWki45CDxVHP2aepX1aLaIuTf9Aut?usp=sharing

5 Likes

I will try this in the next few days :slight_smile:

Schau zu, dass Du das Ding in das nächste Release bekommst. <3

Vielen Dank @LimDul

I tried the binding and it works perfect. Thanks.

Continuing the discussion from [SOLVED] JSON Path weather warnings DWD (Deutscher Wetterdienst):

Hello,
I get the following error message when the rule expires:

[WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert ‘heute 16:00’ to a state type which item ‘DWD_Warnung_1_Start’ accepts: [DateTimeType, UnDefType].

Can you help me?

Thanks

Hi @ollis112, it looks like you assign the string “heute 16:00” to the item DWD_Warnung_1_Start which is defined as a DateTime item => not possible to receive a string.
In my rule, I assign the string to another item (String item) which is named …_lesbar:
=> DWD_Warnung_1_Start_lesbar.postUpdate("heute " +Uhrzeit)

But: the way of @LimDul looks much better than my ugly solution, I would recommend looking at his binding (but I didn’t try it myself as my system is running…)

Hi Jochen,
I understand. I’ll test it tonight. many thanks. I will report

OK works.
Thank you for your help.
Greetings Oliver

Hello Martin,
great binding. Works perfectly.
Unfortunately, I get the date and time displayed in the Habpanel in a long string.
Can I change that without using a big rule?
greeting
Oliver

Can you try the newest version from https://github.com/limdul79/openhab2-addons/tree/dwd and re-create the item? The item should be of the Type DateTime. With that, you should be able to format the Item in HABPanel with Format Strings.

@LimDul copied yesterday a new .jar file on his google drive. Thank you!

So far no error in the logs.

When i read the table in the documentation (thank you!) here: https://github.com/limdul79/openhab2-addons/tree/dwd/addons/binding/org.openhab.binding.dwdunwetter there is no “last update” item?

In the lack of “Unwetter” i can’t test the function … :slight_smile:

For testing, I look for regions with active warnings and change my thing :slight_smile:

Yes, there is no lastUpdate Item - SImple Reason I haven’t thought about ist. But I might add one (only one per thing, regardless of the number of warnings provided)

The lastUpdate Item is, in my opinion, only useful to check if the DWD Server is online and if the OpenHAB Binding ist working. (I wasn’t aware that my existing installation was not working … so missed a lot of warnings :slight_smile: )

it workes :slight_smile:

The switch is off … normal?

Should not be off. I have updated the binding and uploaded new Jars, including a last updated Channel :slight_smile:

I fixed the problem that at the first startup there were empty items and only after waiting the refresh Time it got populated.

1 Like