Smart home touchscreen – HABpanel – Part 2

This post will be about installing Bindings and creating Things and Items to get live data to the smart home touchscreen – HABpanel, that I created in the last post.

Let’s get going!

To start, open Visual Studio Code and all the openHAB configuration files. I talk about why to use VS Code and how to set it up, in this post and in this video.

To install bindings, open the Services folder and click on addons.cfg. Remove the hashtag in front of bindings and type an equal sign. Now you can type in all the bindings you want, separated by a comma.

Once you specify Bindings here, anything installed through PaperUI will be lost.

If you have any Bindings installed via PaperUI they will be uninstalled as soon as you startusing configuration files and only the ones you’ve specified here, will be installed.

I want to install the Astro binding for sun and moon data, and the weather binding. Take note that for weather binding you need to type weather1. Once you do that, hit Ctl+S to save and openHAB will download and install them.

First the Astro Binding for sun and moon data

To get more information about the binding, Google “astro binding” and then go to the openhab.org page for the documentation. The link to the page is here.

Here you can find all the information you will need to work with the binding. The channels available, how to set it up etc. I will scroll down to the examples area.

For now I will just copy the basic Thing configuration.

In Visual Studio Code

Going back to VS Code, we need somewhere to paste it. We will need a Things file and an Items file. To do that, right click on the folder, where you want to create the new file in, and make a new file. You can call the file anything you want. I’ll call them both test. But an Items file has to have a format of name.items and Things file, name.things. Same goes with the rest of the files. Therefore the items file is called test.items and the things file test.things.

It is important that you do this, because this way openHAB knows how to differentiate the files. And of course they need to be in their designated folders.

Now that the files are created, go to the test.things file and paste in the lines of code we copied.

Astro Binding Things

If you look at the code, each line represents a different Thing.

What does a Thing look like?

Basic Thing syntax

The basic syntax of a thing is as follows – binding id – type id – thing id, all separated by colons.

Then comes Label @ Location, but this is optional and as you can see, we don’t have any here. And lastly in square brackets are the parameters of the Thing. Note that all but the Label and Location are required. So you have to declare the binding id-type id -thing id and the parameters.

Parameters for the astro binding, according to the documentation, are latitude and longitude. Which makes perfect sense .And optionally interval – which indicates the refresh rate in seconds, if you want to calculate positional data like elevation that is changing constantly.

And that is our Astro Things set up. Now, we need Items, so we can access this incoming data.

Now, time for an Item!

Going back to the Astro binding documentation and scrolling further down, you’ll see the Items examples. Because at the moment I’m only interested in sunrise and sunset I’ll copy the top two lines. Take a bit of time to go through the documentation and see what it has to offer, because there is a lot and you will find really cool stuff you might want to use.

Now back in VS Code, head over to the test.items file you created earlier and paste in the items.

Basic Item syntax

The basic syntax for Items is a follows. Item type – item name – label with the state format in square brackets-<icon name> – (groups the item belongs to) – [tags] – {binding configuration}.

Take note that the order is important and so are the different bracket styles. Square, curly etc. Out of all of these, item type and item name are mandatory, others are optional.

And as with Things, each line represents a separate Item.

Explaining our Item

So in our case, from left to right, we have item type – dateTime, because sunrise and sunset are time values,. Item name is Sunrise_time. Inside the double quotes is item label – Sunrise and inside the square brackets is the formatting style. We don’t have an icon, any groups or tags specified and as I said, they are optional. Lastly, inside the curly brackets we have the binding configuration.

Link between out Item and a Channel

We need to link the Item to a channel, where we want the data to come from. I talk about Items, Links and Channels in my openHAB basics post and video. If you have any questions, go and have a look there (post , video) or let me know below in the comments. Back to our Item.

So our configuration goes as follows. Astro : sun : home specify the binding id, type id and thing id respectively. Going back to the binding documentation, you’ll see that the thing is sun. Inside sun there is a Group called rise, that’s what we have as well. And a channel called start. Everything is in descending order.The type of Item suitable for this channel is DateTime item. And that is what we have.

Connect a HABpanel widget to an Item

Now that we have our Things and Items configured, lets connect them to our widget on our HABpanel.

Head over to the HABpanel dashboard designer. I talk about that in my previous post and video.

Open the sunrise widget edit window. And now, as you can see, we have openHAB items available. If you remember last time, the drop-down was empty. Choose Sunrise_Time. That is our Item name. Do the same with sunset . Now run the dashboard.

Data we don’t need

Way too much information!

As you might have noticed, a lot of information is displayed. If there is one thing certain in this world is that the sun always rises and sets, therefore I don’t think having the day, month and year there is really necessary.

To get rid of the unnecessary info, go back to the edit window and type HH:MM in format. This will only display the hours and minutes.

Now we have live sunrise and sunset times on our HABpanel. As you saw, there is loads more channels in the Astro binding you could use to get tons more information. And they will update with the correct information without us having to worry about it.

Next step is to get live weather data.

Weather Binding

First lets Google Weather binding and go to the corresponding page on openhab.org. The link for it is here.

Again, there is extensive documentation about the binding and I urge you to have a read .

The first thing you’ll notice that under Binding Configuration it says, the binding can be configured in the file services/weather.cfg.

And that is why it is important to read through the documentation. Configuring each binding is different. Unlike the Astro binding, weather doesn’t have any things to configure, instead, it is done in the weather.cfg file. So we will need to create a weather.cfg file in the services folder.

Stop before you go!

Before you go to VS Code and create a new file, you have to stop openhab. To do that, open an ssh client. To find out which one I use, have a look at the Installing openHAB on a Pine64 post or video.

Once logged in, run this command. Sudo systemctl stop openhab2.

Now openhab service is stopped and we can safely create a new configuration file.

Weather configuration

Copy and paste the example to the new weather file.

Starting from the bottom.

Weather Binding configuration

Longitude and latitude are pretty self explanatory. The location you want the weather data to be about.

Update interval is period in minutes, a fresh data call is made. Weather doesn’t change that quickly and 10 minutes is more than enough. As you’ll see later, providers also have limits to the maximum number of call you can make.

Next is language. I’ll change this to en for english.

Provider is the web service that provides us with the data. You’ll find the different providers available in the binding documentation. I’m using OpenWeatherMap, so I’ll need to change the provider name.

Lastly we will need an apikey.

API key for weather

To get this, head over to the providers web page. In my case OpenWeatherMap. You’ll see that for the free subscription, the maximum number of call per minutes is limited to 60. Even though its a lot more that the 10 minutes we specified, there is no point having it any higher.

OpenWeatherMap

Once you’ve signed up, an api key will be sent to your email. Copy and paste that in the configuration file.

Now that the binding is configured, we need to create Items.

Weather Items

Go back to the binding documentation page and scroll down to the example items section.

We have 4 widget on our HABpanel we want to get data to. Temperature, humidity, rain and wind.

Find the examples, copy and paste them into the test.items file. When you are building your own system, it is a good idea to have different items in different files just to make it easier to read. But for now, I’ll keep it all in the same file as the Astro Items.

Out Items so far.

The basic layout is the same as with the astro items, just the binding configuration looks a little different. Weather binding is more of an exception for that matter and usually items look more like the astro items above.

Now save all the files.

Restart openHAB

Before we can make changes in HABpanel, we need to restart openhab.

In the ssh client type sudo systemctl start openhab2.

It will take a little while for openhab to get back up and running so go and make a coffee.

Once back in HABpanel dashboard designer, we can connect the widget to our new items. When doing than, also click on the “Use server-provided format if available”.

There is no need for this sort of accuracy with weather!

When you run the dashboard now, you’ll see live weather data. However, you will notice that the temperature has two digits after comma. That is unnecessary accuracy. To change that, go back to the test.items file.

Inside the square brackets as you might remember is the formatting info. Lets change that 2 to a 0 on all of them and hit Ctl+S to save.

Go back to HABpanel and if it hasn’t refreshed yet, do it manually. And behold, we have information that is actually in a useful scale.

HABpanel with live weather data and sunrise/sunset times.

It’s finally finished

And that is it for this post. Now we have live data coming in to our HABpanel.

I think it’s pretty cool and the best part is, we can now also work with this data and use it to create Rules for greater automation control and comfort.

Hope this post has been helpful. I know I had a lot of fun making it and also making the video.

You can find these videos on my YouTube channel – smartESThouse. I will be adding videos weekly, same as these blog posts. If you want to be notified when I add a new video, consider subscribing here.

Starting from the next post and video, I will be working with a new project. A complete automated lighting system that uses HABpanel, openHAB rules, external switches, micro controllers and much more. I will show you the steps of how I’m designing and building the system I plan to use in my home.

Leave a Reply

Your email address will not be published. Required fields are marked *