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

Sunday 29 October 2017

Home Automation System - New mailbag...




Last Friday, a new mailbag arrived...full of new stuffs from China...


Among the others, we have:

- a SONOFF B1, wifi controlled RGB lamp;
- a SONOFF 4Ch, wifi controlled relays (4);
- some temperature and humidity sensors DHT11
- some RF433 wireless transmitter and receiver
- a couple of ESP8266 NodeMCU

Keep going on...

Tuesday 24 October 2017

Home Automation System - OpenHAB v.2, a better network monitoring with groups




Introducing the openhab groups in my setup, I improved my network monitoring.

I created a new group called gNetworkCheck, which will be assigned to all the network devices I would like to monitor. This group will be ON when all items will be ON, otherwise OFF.

Then I changed the monitoring rule, defining it only for the group and not for every device; in this way, I could add a new device to monitor simply assigning it to the gNetworkCheck group; no new rules to write.

So, I edited my /etc/openhab2/rules/checks.rules file, replacing all the specific device rules with a single rule for the group:

rule "network check"
when
Item gNetworkCheck changed
then
val lastItem = gNetworkCheck.members.sortBy[lastUpdate].last
logInfo("rules", "NETWORK CHECK -> " + lastItem.name + " changed to " + lastItem.state)
sendNotification([user_to_be_notified], "NETWORK CHECK -> " + lastItem.name + " changed to " + lastItem.state)
end


Following a tip found in the OpenHAB forum (https://community.openhab.org/t/determining-the-triggering-item-in-the-body-of-a-rule/2654/4?u=alex73) I'm able to identify the item changed, which I added to the notification message.

Here is the sitemap with the new group on it


Wednesday 18 October 2017

Home Automation System - Using groups in OpenHAB v.2




Another step forward with OpenHAB v.2...let's speak about "groups"; reading the official documentation (http://docs.openhab.org/configuration/items.html#groups) and studying them I discovered that they aren't simple labels to categorize items but they can be used also as particular objects to be added in the sitemaps, they can be used inside "rules" and may get a real value, derived from the linked items. They may also receive commands which will be forwarded to the items inside them.

A "group" is a special item with some differences. It is defined in a .items file in the folder /etc/openhab/items. So I create a new file called groups.items with some groups which I will use later, going forward with the openhab configuration.

Groups may be nested and so it is possible to create a real hierarchical design.

The syntax is very simple and you can find it in the official documentation.

The first groups I created are related to the floor and the room (main floor, first floor, kitchen, garden...), the item type (sensor, switch, network, etc etc...), the purpose (lights, temperature etc etc...) and so on...

Some of these groups will have a real value, depending on the value of the items / groups inside them. Examples:

- the gTemperatureFirstFloor group will be used for temperature sensors on the first floor and its value will be the average of all values of these sensors;

- the gEnergyConsumer group will be used for the energy consumer sensors and its value will be the sum of all values of the sensors;

- the gLightSwitchGarden group will be used for all the light switches in the garden and its value will be ON if at least one switch will be ON, otherwise OFF;

These groups can be put into the sitempas, so their values will be shown (if applicable...) and, click on them, you can see all the items / groups inside them, making a real hierarchical presentation.

For example, referring to the gLightSwitchGarden, we could add other groups for all the light switches in the house: gLightSwitchFirstFloor, gLightSwitchMainFloor, gLightSwitchGroundFloor (inside them we will put the light switch item...). Then, we create a new group called gLightSwitch linked to all of them.

Adding the gLightSwitch group in a sitemap we could browse all the light switches with a couple of click; sending command to gLightSwitch we will drive all the light switchs together.


Here is a video about groups and light switches:




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





Sunday 8 October 2017

Home Automation System - Checking TASMOTA firmware updates with OpenHAB v.2





A little post about managing notifications about new TASMOTA firmware versions for SONOFF devices on OpenHAB v.2

As we already know reading the official TASMOTA documentation (https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#firmware-binary-sources), @smadds user manages a public MQTT broker "sonoff.maddox.co.uk:1883", where he publishes the last version number of the TASMOTA firmware using topic sonoff-version.

So, in my setup, I just added an "item" linked to this value, through MQTT and then published it on my sitemap.

First thing to do was create a new MQTT connection (called sonoffmaddox-mqtt) to the @smadds broker, appending the following lines to the /etc/openhab2/services/mqtt.cfg file

sonoffmaddox-mqtt.url=tcp://sonoff.maddox.co.uk:1883
sonoffmaddox-mqtt.clientId=
sonoffmaddox-mqtt.user=
sonoffmaddox-mqtt.pwd=
sonoffmaddox-mqtt.qos=0
sonoffmaddox-mqtt.retain=true

Then I created a new file called general.itemsin the /etc/openhab2/items folder, in which I wrote down the following line:

String      SonoffTasmotaVersion      "SONOFF Tasmota Version [%s]"     <settings>
{mqtt="<[sonoffmaddox-mqtt:sonoff-version:state:default]"}


My item is called SonoffTasmotaVersion, its type is "String" and it is linked to the mqtt connection called sonoffmaddox-mqtt, topic sonoff-version. In this way, this item will be updated everytime someone will publish new messages on topic sonoff-version.


Last step: I added my new item to the sitemap, just to keep tracking of the last TASMOTA version.
So, I edited the /etc/openhab2/sitemaps/test.sitemap file, inserting, on the top, the item just created inside a frame called "general":

Frame label="General" {
    Text item=SonoffTasmotaVersion
}

Here is the result:



To be more useful, I created a new OpenHAB rule just to be notified every time the TASMOTA version will be updated.

So, I created the /etc/openhab2/rules/checks.rules file, and wrote down the following lines:

rule "tasmota version check"
when
Item SonoffTasmotaVersion changed
then

logInfo("rules", "New Tasmota Version " + SonoffTasmotaVersion.state)

sendNotification([user_to_be_notified], "New Tasmota Version " + SonoffTasmotaVersion.state)

end

The sendNotification function sends a notification to the specified user; this notification reaches the mobile devices where the OpenHAB App is installed and linked to the OpenHAB cloud (MyOpenHAB). Its configuration is very simple, just following the official guide: http://docs.openhab.org/addons/io/openhabcloud/readme.html

Now I have to wait for the next TASMOTA update just to check that all is working as expected.

Monday 2 October 2017

Home Automation System - External buttons and switches on the SONOFF Basic with TASMOTA




I need to control SONOFF using either physical buttons and switches and not only through OpenHAB

The easiest way is to use a button directly connected to the physical button pins in the SONOFF. I already made a test with my first SONOFF Basic, as described in a previous post(http://domoticsduino.blogspot.com/2017/08/home-automation-system-sonoff-and-mqtt_19.html).

In this way we could activate and deactivate SONOFF as we do using the physical button. But I need to control the SONOFF through switches too. Reading the TASMOTA documentation, I discovered that I could connect a button / switch to the GPIO14 pin. Then I could tell TASMOTA what kind of object I connected...if a standard button or a switch.

To do so, I have to connect the button / switch to the GPIO14 pin and to the GND pin on the board; both of them are easily reachable. The GPIO14 pin is the one which is not utilized on the serial interface, and the GND is just beside it (already used for the serial communication).





When the hardware link are OK, I have to configure TASMOTA

In the configuration menù of the web interface, I choose 09 Switch1 as the new value for GPIO14 drop down list.



Then, I have to set SwitchMode parameter accordly to my needs, through the Console: if I will work with a button, I set up the value 3, otherwise I will put 0


And finally here is a video with my test