[Solved] SMHI Weather

Thank you both for sharing this. I am working on a solution for controlling sunshades based on weather forecast, and this is a great starting point for that. I used the code from @tnemrap and it worked nicely.

I will also try to use some of the code from @pacive, since it has some nice features. One question though, the function getTrimmedList will probably not work for the current day since the forecast does not always start from time 0:00, depending on when the forecast is requested. Is there any simple way of comparing requested times with the timestamps in the json? I am new to the OH scripting language and I do not know how to implement that.

The getTrimmedList can be made to work for todays date by adding

var startIndex = startHour - (24 - numberList.length)

and use startIndex intstead of startHour in the for-loop. This doesn’t play well with days more than 2 days in the future however
 Still got some bugs to figure out :wink:

That was a nice and simple solution, which works for what I am going to use it for. :slight_smile:

Just realized that the same has to be done for the endHour value for it to work properly

var startIndex = startHour - (24 - numberList.length)
var endIndex = endHour - (24 - numberList.length)

Hi Mike,
Thanks for sharing your Weather Script .
Do you mind sharing your Custom Template, as well can you help me with the python script ? In witch folder do i need to save it in openhab folder ? And where the python.exe . I’m still in an early learning stage and need a bit of assistance. I can see a location of the script in the rules but there is no c:/ or something similar.
Thanks in advance.

Hi @tnemrap

Since some time, I get an error with smhi_minmax.py. Not sure if something has changed from SMHI, or this came because of some upgrade on my computer (python?);

16:10:00.815 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'SMHI': For input string: "File "/home/micke/oh/conf/scripts/smhi_minmax.py", line 45
    print '{"tmax": "' + str(tmax) + '","tmin": "' + str(tmin) + '","tmax1": "' + str(tmax1) + '","tmin1": "' + str(tmin1) + '","tmax2": "' + str(tmax2) + '","tmin2": "' + str(tmin2)+ '","tmax3": "' + str(tmax3) + '","tmin3": "' + str(tmin3)+ '"}'
                     ^
SyntaxError: invalid syntax"

Hi

I do not have that error.

/Mike

I have now released a test version of SMHI Binding

/Mike

1 Like