Domoticz and Sonoff

%REVENUEHITS_SLIDER_OFF%

Drive your Sonoff switch with Domoticz apps.

We can see how to flash Sonoff device (with ESP 8266) from a computer in order to get connected with Domoticz application.

Sonoff and Domoticz
We can see how to flash Sonoff device (with ESP 8266) from a computer in order to get connected with Domoticz application.
1/ Connect USB serial converter to the Sonoff Device :

The sonoff device used in this example is Sonoff Basic Wifi Wireless Switch. The pin connexion could change according to the Sonoff device (like for instance Sonoff TH10, Sonoff TH16, …) but the flashing operating mode is always the same. You could find the pin description of the selected device by surfing on the net.

2/ Download the software : ESPFlashDownloadTool_v3.6.1.0.exe and the associated libraries.
Here is the link of the download :
http://www.easy-herve.com/rv-domoticz-sonoff/Tool%20to%20flash%20Sonoff%20V1H.zip
Unzip all the files into a folder located in your computer.

3/ Connection USB serial converter to computer
You have to follow the following step in order to set flash mode on the device :

  • before to plug USB serial converter on the computer, press down the button located on the Sonoff device (without to release it).
  • plug USB serial converter on the computer USB port.
  • you can release the button.

4/ Launch "ESPFlashDownloadTool_v3.6.1.0.exe

Click on the button ESP8266 DownloadTool
A new window comes :

Into the field "download path config", select the file located into subfolder "File to Flash Sonoff" named "ESPEasy_v2.0.0-dev11_normal_1024.bin"
Be sure all the options has been set like it is described on the screen below except port COM number that depends of your computer (control panel, device manager and you can read COM number which is associated with your USB serial converter).
Be sure that field at the right of the selected file was filled by 0x00000 :

Once you have checked all the setting, click on START button to start flashing the device.
During the flashing process, the application status should show the status "Download" :

Then when the flashing operation is over, the status should go to "Finish" :

5/ Unplug the USB converter from the computer and plug it again (to reset the device).
Wait few seconds to let the device boot correctly and check from a Wifi device (tablet, phone, computer, …) that you can get connected with a Wifi point named : ESP_Easy_0.

Connect to this wifi acces point with the password : configesp

Launch a Internet browser and write the address : 192.168.4.1
A new screen comes and select your home Wifi network with the right password. Then click on the button Connect.

Wait for a few seconds to let the device booting again. Then the device has to be connected to your home network.
Use the interface of your router to get the IP address of the device.

6/ Once you have the IP address of the device, launch Internet browser and write the IP address on the browser.

7/ Minimum setting to get connected with Domoticz application

  • Controlers menu


Click on the Edit button on line N°1 and add your Domoticz setting IP address and port.
This will be used by the device to send status of to your domoticz server (for example in case of user force the switch to on or off with the button located on the Sonoff device)

  • Device menu


Edit the first line to add device like below (don't forget to click on the button "Submit" to save configuration) :

Edit the second line to add device like below (don't forget to click on the button "Submit" to save configuration) :
Before to set these data on that screen, you have to add a new virtual device in Domoticz and get the IDX that you have to set below. It will be used to send the status of the switch at the right address into your domoticz installation.



Once you create new virtual device on Domoticz, you can come back to ESP adjustment, set the options as below and set the IDX with the one from Domoticz. Then, click on submit button to save changes into the device memory.

In order to use the case led to show the switch status and the case switch to force the switch to on or off, you have to add few lines of code into the "rules" menu.
Per default, the "rules" menu is hidden then to show this menu, go to tool menu :

Click on Advanced button and enable "Rules" option :

Once the rules menu is displayed, you have to copy and paste the code below. Then, don't forget to click on submit button to save changes into the device memory.

on bouton#bouton do
if [bouton#bouton]=1
gpio,12,1
else
gpio,12,0
endif
endon

on relai#relai do
if [relai#relai]=1
gpio,13,0
else
gpio,13,1
endif
endon

Then, Domoticz requires a fixed IP for the device in order to sent the right command to the right device. The first possibility is to let DHCP mode on the device and the router manage a reserved IP according to MAC id of the device.
The other possibility is to set a fixed IP in the device it self (on the line ESP IP) :

Then click on submit, switch off and on the device and come back to your browser, and type the new IP address to go back to the device setting (if it is needed).
Now, we have to adjust the command from Domoticz to the Sonoff device.
Click on the edit button of the switch on Domoticz :

Write the command on the lines :
On Action : http://SonoffDeviceIP/control?cmd=gpio,12,1
Example :
Off Action : http://SonoffDeviceIP/control?cmd=gpio,12,0
Where SonoffDeviceIP is the IP that you have set previously.
Example : Action OFF -> http://192.168.0.83/control?cmd=gpio,12,0

Then, procedure is over and normally your device has to be controlled by Domoticz.