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
Showing posts with label sonoff. Show all posts
Showing posts with label sonoff. Show all posts

Friday, 26 October 2018

Home Automation System - Automating a floor lamp







Let's continue with my Home Automation System design, based on the wonderful OpenHAB

This time the main attraction is a simple floor lamp that will be trasformed in a SMART Device, using a Sonoff Basic.

These are my soldiers:




For those who don't know it, SONOFF  is a simple "wifi button", which allows you to control electrical loads remotely. The Basic version is the simplest one with a single relay.

It seems a simple job...

I will replace the standard button with the SONOFF...so, I will cut the wires to move away the button from the lamp...and plug these wires in INPUT e OUTPUT pins of the SONOFF.

Let the things be a little more complicated: on TASMOTA (https://github.com/arendst/Sonoff-Tasmota/wiki/DHT11-Wiring---Sonoff-Basic), I learnt that it's possible to manage an humidity/temperature sensor, linked to a free pin inside the SONOFF (GPIO14). A compatible sensor is the DHT11 and, luckily, I own some of them.


This sensor has 3 pin, Vin, GND and OUT. So I link Vin and GND to the right SONOFF pins and OUT pin to the GPIO14 (always inside the sonoff)...To discover the right position of these pins, I used again the TASMOTA Wiki (https://github.com/arendst/Sonoff-Tasmota/wiki/GPIO-Locations)

Here are the wires soldered and protected by a heat-shrinking sheath




Now, I have to solder the other side of the wires to the DHT11...



Also here I used a heat-shrinking sheath ...these pins are very close



And here is the complete device...



Now I make an hole in the plastic case to let the wires get out



And here is the lamp with the SONOFF and the DHT11...



Now it's software time. Using the well known TASMOTA web interface, I selected the right sensor connected to the GPIO14.

and then I inserted the usual MQTT informations.

Back to the home page, I noticed that the data acquired by the DHT11 is displayed on top of the page


Let's configure OpenHAB defining new items and the MQTT topic used by the SONOFF...

My MQTT topic will be smarthome/light_env/%topic%/%prefix%/

Looking to the TASMOTA console, I noticed a new prefix in the topic related to the temperature and humidity information:


This will be the topic which I'll use in the items definition.

Here is the result

Basic UI


Grafana Dashboard



And this is the switch for the lamp


-----------------------------------------------------
Similar items used in this project
-----------------------------------------------------

Saturday, 1 September 2018

Home Automation System - SONOFF 4 Channel integration with OpenHAB





In the previous post, I spoke about my SONOFF 4 channel, describing the physical installation.

Now, this device will help me to drive 4 lights: 1 internal and 3 exterior; of course, OpenHAB will be my control system and MQTT will be the message protocol.

Let's go to setup the SONOFF, using its web interface



The first step will be to setup the module type, using the menĂ¹ Configuration -> Configure Module



Then, in Configuration -> Configure MQTT, we will put the MQTT topic, splitted in TOPIC and FULLTOPIC as TASMOTA ask



In my case the device will use the following topic smarthome/sonoff4ch14/###. TASMOTA will replace ### with the type of message it will be sending (for example cmnd for commands, state for status information etc etc)

No more details on the other configuration options...they are the same as the other SONOFF

Now it's time for OpenHAB...we will add 4 items, one for each light.

Create a new file, called sonoff4ch.items, in the usual folder /etc/openhab2/items; in the file we will write the items configuration:


As you can see, MQTT topic is the same for all items. Only one thing changes...the property name, indexed by a number to indicate the relay number.

Finally, the last step: put the 4 items into a sitemap. So, write down 4 switch into the sitemap file

(these are the 3 items for exterior lights...)

And here is my complete sitemap:


Now let's push some buttons and see what happens.




Friday, 17 August 2018

Home Automation System - SONOFF 4 Channel




Finally I found a little time to continue my Home Automation System.

I already own a SONOFF 4 channel...I think the biggest one...


This device is able to drive 4 power outputs through a single Wifi connection. I will use it to power up my lights.

As well as input and output power connector,s it also has 4 pushbuttons which drive the 4 relays. Basically it's like 4 SONOFF Basic in a single device and with a single Wifi connection.

As usual I will use the TASMOTA firmware instead of the original one, which permits to use the device only through EWelink software. With TASMOTA firmware I'm able to easily integrate the device in OpenHAB using MQTT protocol.

Here is my SONOFF in flashing mode


As usual, it's easy to flash the firmware...just follow the official Wiki

Please, remember that this is an irreversible operation. You cannot recover the original firmware

In order to be able to control the SONOFF also through a traditional button, I decided to use the 4 pushbuttons integrated in the device... by connecting them appropriately to the buttons / wall switches ...

I never throw anything away and in this case a male / female old serial cable will be very useful to connect comfortably and plug and play the buttons / wall switches with the SONOFF buttons.

Thanks to Piero, we soldered the serial pins to the 4 pushbuttons on the SONOFF


getting the connector out of the SONOFF box


On the other side, we have an ethernet cable linked to the wall buttons


and we soldered to it the male serial connector


Ok, now it's time to configure the device to be integrated in OpenHAB through MQTT

Stay tuned...

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...

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



Saturday, 30 September 2017

Home Automation System - MQTT, SONOFF and OpenHAB v. 2




It's time to integrate MQTT and OpenHAB v.2.

As already said in a previous post (http://domoticsduino.blogspot.com/2017/08/home-automation-system-sonoff-and-mqtt_19.html), actually I have a SONOFF Basic already installed which drives a garden lamp. As we already know, it's already setup with MQTT and so let's start the OpenHAB integration.

I followed step by step the Tasmota wiki, in the integration section (https://github.com/arendst/Sonoff-Tasmota/wiki/openHAB) and so, as first step, I installed some ADDONS in OpenHAB:









Now I have to setup the MQTT connection to the MQTT broker which runs on the same Raspberry PI 3 as OpenHAB 2; so I have to edit the configuration file /etc/openhab2/config/mqtt.cfg directly through the linux shell (nano or vi) or using Eclipse SmartHome Designer, an advanced text editor optimized for OpenHAB v.2 configuration files. I used it. Its setup is very simple and then it needs to know the OpenHAB configuration files path. In my case I setup a network drive (called Z) for a samba share automatically defined by the installation of openHABianPI.

In particular, the configuration parameters I edited are the following ones:

openhabianpi-mqtt.url=tcp://localhost:1883
serve and port of the MQTT broker

openhabianpi-mqtt.clientId=openhabianpi
openHAB client Id for the MQTT connection

openhabianpi-mqtt.user=openhabian
Username for the MQTT connection

openhabianpi-mqtt.pwd=XXXXXXX
Password for the MQTT connection

openhabianpi-mqtt.retain=true
Defines if the broker should retain the messages sent to it

openhabianpi-mqtt is the logical name of the MQTT connection; in OpenHAB we could have many MQTT connections and in the items configuration we use this name as reference.

If you don't make mistakes, during the OpenHAB boot you may find log messages as following:


Ok, now I will configure items and the sitemap .

So, I created a file called sonoffbasic01.items in the folder /etc/openhab2/items in which I setup my new items.

I defined a "Switch" object ("light" category) which was linked to the full topic mqtt of the SONOFF Basic 01 tasmota/garden/light/%topic%/%prefix%/. Here is the syntax:

Switch Garden_Light_1Lamp "Garden 1-Lamp"      <light>
            (gLightSwitchGarden)
            {mqtt="
                     <[openhabianpi-mqtt:tasmota/garden/light/sonoffbasic01/stat/POWER:state:default],
                     <[openhabianpi- mqtt:tasmota/garden/light/sonoffbasic01/tele/STATE:state:JSONPATH($.POWER)],
                     >[openhabianpi-mqtt:tasmota/garden/light/sonoffbasic01/cmnd/power:command:*:default]"
             }

For info about syntax of .items files please see official documentation http://docs.openhab.org/configuration/items.html

In this way I created an item called Garden_Light_1Lamp linked to MQTT messages of topic defined in the {...} block

Then, I added this new item in my sitemap . So, I edited sitemap definition file, appending the following rows:

Frame label="Lights" {

Switch     item=Garden_Light_1Lamp        label="Garden Light 1 Lamp"       icon="switch"


}

After saved this file, OpenHAB updated the sitemap and the "lights" section appears




Here is a short video about my test: