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?
Are you able to download “Regenradar” GIF and display on your site?
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.
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:
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…)