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/</</g' | sed 's/>/>/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/</</g' | sed 's/>/>/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/</</g' | sed 's/>/>/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
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.
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].
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…)
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.
For testing, I look for regions with active warnings and change my thing
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 )