Custom Widget: Weather Chart (Meteogram)

Is it possible to refresh the widget every 6 hours?

1 Like

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 :wink:

(*) ā€œ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?

:+1:

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?