Custom Widget: Weather Chart (Meteogram)

@ysc just an update for you and others on this thread…

Since I introduced the token system, it has been a largely manual process to generate tokens and add them to the live server. This takes time for me and is also frustrating for the requester because they don’t get an instant response, especially these days where instant responses are expected.

So I’ve now implemented an automated system for requesting tokens, which enables a token to be issued and become active immediately. At the same time, it is now subscription based, which is mainly to act as a natural limit on usage.

As I understand it, usage via the hab panel widget tends to be quite low, and there is at present a free quota of 500 API calls per month, which I think should be plenty enough to ensure that users on this thread still won’t actually be paying anything to access the meteogram for their widgets.

An API token can be obtained from here. The existing tokens already issued will be phased out. The above page allows you to set the options interactively and see in real time how the changes will affect the meteogram.

@ysc also, my post from 8 April has now been hidden (flagged as spam)… please can you check why and unhide it if you think it appropriate… same reason as why I can’t include a link in my post of a few moments ago, but I don’t consider it to be “spam” since it is relevant to the post content.

@drmrbrewer fair enough, good to know and nice of you to give notice! :slight_smile:

I’m not a moderator here so I can’t help you on posts not getting through - pinging @moderators.

1 Like

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.