Disclaimer

Please, proceed carefully following the tips published in this blog, specially when Main Power is involved. I'm not responsible for any damages caused by what is written in this blog.
Thank you

Wednesday 11 October 2017

Home Automation System - OpenHAB v.2 and local network monitoring




Just to go deeper in the learning of the OpenHAB v.2 world, I tried to design a little and simple local network monitor tool.

For this purpose OpenHAB v.2 give us a 2.0 Binding, which can be setup directly through Paper UI: the Network Binding, which can be easily enabled in the Add-Ons section

As usual, the official documentation is very detailed: http://docs.openhab.org/addons/bindings/network/readme.html

This binding gives us a tool to perform network scans, using system ping or port scanning technique, to detect any device joining my network; so I could be informed when a known device is ONLINE or OFFLINE

The new Things objects will be devices identified by address ip; for each of them there will be two channels:

- Online: could be linked to Switch Items to show the network status of the device;

- Time: could be linked to Number Items to store the reply time of the device

With this binding just installed, the things will be automatically discovered and OpenHAB will notify us with the menù item INBOX, on the top left side of the UI (in case, you can force the discovering process using the "search" icon on top right)


Identified the network devices, with a couple of clicks I could create the Things and, through the Channels , also the Items

Here is my Thing -> Channels -> Item chain about my home router


And here is the configuration form for the "Home Router" Thing:


Beyond the configuration parameters described in the official docs (http://docs.openhab.org/addons/bindings/network/readme.html), I also used the one called "Location", just to identify the real location of the device.
I decided to use the floors and the garden as location choices. So my home router is at "first floor" location.

After all devices was added, the first test is to have a look at the "Control" menù, by selecting the "First Floor" location.
Here is the result:



Last step is adding this informations on my sitemap. So, using SmartHome Designer I edited the /etc/openhab2/sitemaps/test.sitemap. file

I added, just under the "General" section, a new frame called Network which contains the Items just created in Paper UI. Here are the lines:

Frame label="Network" {
Switch item=HomeRouter_Online  label="Home Router"      icon="switch"
Text   item=HomeRouter_Time   label="Home Router Time [%s ms]"       icon="network"
Switch item=LamanNAS_Online label="LamanNAS"        icon="switch"
Text   item=LamanNAS_Time label="LamanNAS Time [%s ms]"      icon="network"
}

(HomeRouter_Online/Time and  LamanNAS_Online/Time are the names of the items as we can see on Paper UI).

Here is the result:


Just to make all these things more useful, I could create a new rule for every device I would like to monitor...

So I added the following lines in the /etc/openhab2/rules/checks.rules file, where we can find the already known rule related to the TASMOTA firmware update:

rule "home router check"
when
Item HomeRouter_Online changed
then
logInfo("rules", "HomeRouter_Online online status changed")
sendNotification([user_to_be_notified], " HomeRouter_Online online status changed ")
end





No comments:

Post a Comment