Custom Widget: Weather Chart (Meteogram)

weather
weatherforecast
widgetgallery
Tags: #<Tag:0x00007fd3222969c0> #<Tag:0x00007fd322296858> #<Tag:0x00007fd322296718>

(Mike) #22

Is it possible to refresh the widget every 6 hours?


(Sven) #23

Yes, I would realy like that, since we now have to subscribe to the API key with our creditcard information… The last month that I was using it I regularly saw old data and have to refresh it manually each time…


(Jochen Eggler) #24

Hi there,
first of all, thank you @drmrbrewer for meteograms.com!
I went another way without the custom widget, but with that I get “self-updating” meteograms. I designed my meteogram here:
https://meteograms.com/dashboard/
With the “save settings” button it’s easy to adjust the meteogram later. I check the result via the “direct link” and copy that link. Then I use a little shell-script to download the png:

wget -q -O /home/openhabian/meteogramm.png your-direct-link-here
# if something went wrong, write an error on the old one...
if [ -s /home/openhabian/meteogramm.png ]
then
    mv /home/openhabian/meteogramm.png /etc/openhab2/html/meteogramm.png
else
    convert /etc/openhab2/html/meteogramm.png -pointsize 24 -fill white -undercolor '#ff000080' -gravity South  -annotate +0+50 ' Update-Error ' /home/openhabian/meteo-error.png
    mv /home/openhabian/meteo-error.png /etc/openhab2/html/meteogramm.png
fi
# preparation meteogram as String-Item
rm /etc/openhab2/html/meteogramm-????-??-??-??-??-??.png
stamp=$(date +%Y-%m-%d-%H-%M-%S)
cp /etc/openhab2/html/meteogramm.png /etc/openhab2/html/meteogramm-$stamp.png
curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "/static/meteogramm-$stamp.png" "http://openhabianpi:8080/rest/items/MeteogrammPfad/state"

As you can see, I use a string item called MeteogrammPfad whitch gets updated every time the script runs. Then I use an image widget with the “MeteogrammPfad” item - so it gets updated immediately.
The script can be triggered via a rule or, in my case, via linux crontab.
Of course, that’s not the only way to do that - maybe you could even use the direct link for the image widget (did not test it), but with the script I see some advantages: More than one client can use the same png an I only need 1 download. And second, if there would be some bug in habpanel in the future that updates every second, I don’t get poor :wink: