Is it possible to refresh the widget every 6 hours?
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ā¦
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://api.meteograms.com
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 (* => see remark below). Then I use a little shell-script to download the png:
#!/bin/bash
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
(*) ācopy that linkā => you need the fully encoded link, without the " characters. If I right-click on ādirect linkā, I get that encoded link. If I open it, Chrome decodes parts of it => in the address bar I have " characters => do not copy from here, it wonāt work in the script!
Alternatively, you can copy the encoded options that are shown next to where you do the settings.
High,I tried to use your script, however using my direct link raised an error.
The error was:
08:30:15.746 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'Meteogram.script' has errors, therefore ignoring it: [1,49]: missing EOF at ':'
My first line in code looks like:
wget -q -O /home/openhabian/meteogramm.png https://nodeserver.cloud3squared.com/getMeteogram......
I used the ādirect Linkā created on api.meteograms.com, however the error reported point directly into that link. What am I missing?
Hmm⦠I think the first line looks OK, at least it looks the same in my file.
Do you get an error if you run the script from the linux shell?
Will try that before noon! Iāll be back.
Using the first line in the linux shell creates an empty file āMeteogram.pngā.
Hi Jürgen, I suggest we try to solve that via PN and return here when there is a result. OK?
My āproblemā was missing the Shell-script hint. I understood the posted code as a script running as a script in openHAB! Doing the same in a linux shell will work!
Using the script from @der_optimist works fine, however you need to copy the āEncoded Optionsā in order to make your URL. Using the ādirect Linkā made use of the " -character which is escaped in the āEncoded Optionsā (In dircet Link it looks in part like " ⦠%7B"token"%3A"ā¦" and the same part in the Encoded Options "ā¦%7B%22token%22%3A%22ā¦)
What does not work for me is the āelseā-part (if the crrated .png is empty). I get an error stating that the method āconvertā isn not found.
Thank you for this hint, Jürgen. Looks like the server behavior has changed. When I copied the link, I got the fully encoded version via ādirect linkā, but now I also get the " characters.
Good to hear that it works with the Encoded Options.
I got it running. However I notice a yellow placard over the meteogram stating āOnly 40.3 credits left!ā What is that for? I checked my account, only 24 calls have been made so far!
@opus ā what weather data provider are you specifying in the call? Some providers charge (me) for each call made, so there is a separate credit system to control usage of those providers from the Android app. I will consider how to handle this for direct meteogram requests.
@der_optimist ā Iād not noticed that before. In fact the URL for the ādirect linkā uses exactly the same string encoding as for the āencoded optionsā, and always has done (i.e. with the quote character encoded). I think the browser may āun-encodeā the quote character for readability, since a quote character is a valid character in a URL, at least in a browser if not in some script or code somewhere.
Iām using the german DWD, is that a problem?
No thatās not one of the providers that charges, so it shouldnāt need anything special. I probably just need to reset the credit count and the message should go away.
Tried to run the script triggered by a rule, failing so far!
Running it from the shell is of no problem, doing the same from a rule fails in some obscure results. The .png with the timestamp gets created, however it is the old one. Checking with Meteogramm no update has been requested. It looks to as if the first line (wget) doesnāt run, the other are running???
[Edit]
Using āvar/lib/openhab2ā as the directory for creating the .png is my solution. Can*t get the āconvertā command to run (āCommand not foundā), so Iām not using this part.
Thanks Jürgen for the hint with the " characters. I updated my original post to avoid this problem in future.
I also updated the link to https://api.meteograms.com as @drmrbrewer asked me to do. This is the link that will also work in future.
@opus, your last problem (script not working when triggered by a rule) sounds like a problem with the file permissions. When you trigger it by a rule, user āopenhabā starts the script. When you start it from the linux shell, the current user starts it (e.g. āopenhabianā). Maybe āopenhabianā (or whatever user you use) has the permission to create a file and āopenhabā doesnāt? Maybe in /var/lib/openhab2 every user has the permission to write a file and thatās why it works there.
I would also say it was file permissions. Now it is running smooth (only once in a while I get no new png, canāt say why ATM).
Hi all
Maybe someone can help me regarding the widget for habpanel?
When I enter the token, long, lat, name⦠Nothing is showing up. its the same both in the habpanel and on meteogram api siteā¦
{
"schemaVersion": "1.0",
"token": "xxxxxxxxxxxxxxxxx",
"chartWidth": "700",
"chartHeight": "350",
"density": "1.5",
"location": {
"placeName": "Viborg",
"longPlaceName": "8800 Viborg, Denmark",
"latitude": "56.452",
"longitude": "9.3963",
"countryCode": "DK"
What im I doing wrong?
The server has has a little bit of a āmomentā in the last hour or two. It should be fixed now. Is it working more as expected for you now?