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

It is a proxy Item for several visibility frames like “Warnungen” “Pollenflug” etc.

Hello Jochen,

thank you for this PDF. Don’t know my mistake - perhaps only IDs starting with “8” (Gemeinden) are allowed to be fetched. With your given ID, my command was working.

To make your Script runable:
create directory: “mkdir /etc/openhab2/html/dwd/”
and file: “touch /etc/openhab2/html/dwd/warnings.xml”
make it read and writeable to everyone (e.g. for user openhab and cron) “chmod 666 /etc/openhab2/html/dwd/warnings.xml”
Then, saved your script to /usr/local/bin/dwdweather.sh, and added “#!/bin/bash” at the first line. After chmod +x /usr/local/bin/dwdweather.sh i can run the script as the user “user”.

With and for this user, i created a cron entry: “crontab -e”, and there: “*/5 * * * * /usr/local/bin/dwdweather.sh”
“crontab -l” list the entry.
I run the script manually “/usr/local/bin/dwdwetter.sh” and watch the timestamp of warnings.xml. It is updated. But cron is not running the script … the timestamp remains. What could be wrong?

Where to you use this script? With HabPanel?

Have … good weather! :slight_smile:

1 Like

So you can choose. which info you want to be displayed? Would you please post this part of your sitemap? Thank you!

Frame label="" {
				Selection item=DWDSelectedSite label="Wetter" icon="dwd" mappings=[1="Aktuell", 2="Regenradar", 3="Heute", 4="Morgen", 5="Übermorgen", 6="Unwetter", 7="Pollenflug", 8="Warnungen"]
			}
Frame label=" "	visibility=[DWDSelectedSite==8] {
				Text item=DWD_Warnung_headline		label=""													valuecolor=[DWD_Warnung_level==1="#ffff00", DWD_Warnung_level==2="#ffa500", DWD_Warnung_level==3="#ff0000", DWD_Warnung_level==4="#800000"]
				Text item=DWD_Warnung_level							visibility=[DWD_Warnung_level!=0]			valuecolor=[1="#ffff00", 2="#ffa500", 3="#ff0000", 4="#800000"]
				Text item=DWD_Warnung_start							visibility=[DWD_Warnung_start!="NULL"]
				Text item=DWD_Warnung_end			icon="null"		visibility=[DWD_Warnung_end!="NULL"]
			}
			Frame label=" " 	visibility=[DWDSelectedSite==8] {
				Text item=DWD_Warnung_description					visibility=[DWD_Warnung_description!="-"]
				Text item=DWD_Warnung_instruction	icon="null"		visibility=[DWD_Warnung_instruction!="-"]
			}
			Frame label=" " 	visibility=[DWDSelectedSite==8] {
				Text item=DWD_Warnung_event							visibility=[DWD_Warnung_event!="-"]			valuecolor=[DWD_Warnung_level==1="#ffff00", DWD_Warnung_level==2="#ffa500", DWD_Warnung_level==3="#ff0000", DWD_Warnung_level==4="#800000"]
			}

Ahh! Thank you! It is working!

Are you able to download “Regenradar” GIF and display on your site? :wink:

PS: Once i could reference a username by drag an drop. Now i can’t find this option anymore. What is the trick?
PSS: I could/should open a new thread for my question. That is off-topic here. :slight_smile:

Hi Richard,
thank you for adding “Linux side” steps, i forgot to note them.
At the moment I do not see anything wrong in your cron command. Are other jobs working?
And is there an entry in the log-file?

grep CRON /var/log/syslog

If cron is not working for some reason, you could use an openhab rule to trigger it (but then the user will be openhab).

Did you get it working with your own “8” (I think in Berlin it could be “7”) ID?

Yes, I’m using HabPanel. The uploaded json is my Habpanel Widget. You can see it here:

The script is running every five minutes, as output of “grep CRON /var/log/syslog” shows:

Jul 13 10:40:01 openhab2 CRON[5229]: (user) CMD (/usr/local/bin/dwdweather.sh >/dev/null 2>&1)

(added >/dev/null 2>&1, since i do not have have mail system)

but warnings.xml is untouched:

ls -la /etc/openhab2/html/dwd/warnings.xml
-rw-rw-rw- 1 user user 712 Jul 13 08:39 /etc/openhab2/html/dwd/warnings.xml

Hmm?

That’s strange. You could redirect the output to some file:

*/5 * * * * /usr/local/bin/dwdweather.sh  >> /home/user/dwd.log 2>&1

and se what it says…

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