Australian users weather forecast from BOM that uses no things and only one item

Hi,

This is something I have been struggling with for the past week or two but have FINALLY managed to get it to work and if anyone else wants to use it look at it etc feel free.

It is a NO FRILLS weather forecast program that gets the data from the Australian BOM (Bureau of Meteorology) in json format and puts the downloaded data into an item call BOMdata (called that only so you can copy and paste code without changing things)

There is a BOM addon for openhab that has been created already and it is very good and if you need all the bells and whistles then use that but it creates nearly 100 items, If you just want basic 7 day forecast and forecast temperatures and only want to add one item then this is for you.

It is my first attempt at doing something like this and also my fiest attempt to publish something like this on github, but here goes.

What is looks like etc is here:
https://github.com/ubeaut/openhab3-BOM-program/wiki/How-to-use-instructions.

The files and examples are here:

Hopefully it will work for you. If you have any suggestions for improvements let me know.
I am sure there are better ways of doing this but I am only just starting out.

Thanks to the forum for giving me some clues on things that stumped me otherwise I would still be trying to work it out.

1 Like

image

Terrific work

Thank the BOM as well.
Glad you can understand my instructions and it worked.

If it’s a binding then it creates nearly 100 Channels. But you are not required to use them all. I use the OpenWeatherMap binding which has even more Channels than that but I only use three of them. Therefore I only have three Items. Most Things will have way more Channels than you will use. You only need as many Items as you actually use.

Also, by not having the values in Items you are unable to use them in many ways within OH such as in Rainer’s Weather Forecast Widget, saving the data for charting or using historic data in rules, etc.

I’m not saying anything against what you have done. It looks quite nice. I just want to make it clear that: you don’t have to create Items for all the Channels a Thing provides, having lots of Items isn’t really a problem and not having them limits the ways you can use the data in other parts of OH.

Is there a reason you didn’t use the sendHttpGetRequest action or the HTTP binding to fetch the data? That might be a bit simpler. To use those Actions in JavaScript you’d need to import * org.openhab.core.model.script.actions.HTTP (see HTTP (openHAB Core 3.1.0-SNAPSHOT API)).

If you used the HTTP binding all your rule would have to do is the String manipulation to replace the “-” with “_”. And you could even move that into your Widgets and completely eliminate the Rule entirely.

Thanks for posting!

Yes I did look at the http binding and originally used that but then I though do I need another binding? Can I do it another way?
I know I don’t have to use all the items but I just wanted a simple no frills way of doing this.
It was a process of figuring out how to do JavaScript. I have never used JavaScript until a few weeks ago so it is still new to me.
The rule only needs to run a few times a day and it is 6 lines of code and the widget is only 27 lines.
I knew there would be better ways of doing this but others can run with the idea and perfect it. It works for me and I literally only worked out how to do the widget thing yesterday. It was so frustrating working that out.
I put it all up on github so others can look at the whole code that works. I have found that snippets of examples of how things are supposed to work is confusing because there are other bits further up the code that also tie in with the snippet and they are left out of the example.
I do like OH3 I was on OH2.5 and used the DSL rules but now I just do JavaScript (badly) but it functions.

" Is there a reason you didn’t use the sendHttpGetRequest action or the HTTP binding to fetch the data? That might be a bit simpler."
The reason I didn’t do sendHttpGetRequest is because I have never heard of it or what it does :slight_smile: Again, if you don’t know what to ask you can’t find the information. I had the same issue years ago on Linux and the man command. man is good but only if you know the command you want use.

Thanks for the feedback. Still learning.

In general, being good at searching is not sufficient with openHAB. You need to read through the docs at least once and continue to return to them periodically to scan for updates and changes. for example, within the last week all the “Semantics” Actions were just added. If I didn’t review the docs periodically I’d never know that they exist (and they look like a cool way to interact with the Model from Rules).

However, that page is still Rules DSL focused. To use these Actions you’ll have to import the right class to your JavaScript. But searching for the action in the JavaDocs will show you right away what class to import.

Also note that a number of bindings provide Actions of their own that can be called from Rules.

I have added:
var HttpGet = Java.type(“org.openhab.core.model.script.actions.HTTP”);
and put in:
var DATA = HttpGet.sendHttpGetRequest(“https://api.weather.bom.gov.au/v1/locations/r3fgmyd/forecasts/daily”, 2000).replace(/icon_descriptor…\w+/g,input);

That works as well.
Thanks