sonoff

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
sonoff [23.01.2018 22:10] – [What I intend to do with it] Pascal Sutersonoff [24.07.2018 09:17] – [Making the installation permanent] Pascal Suter
Line 11: Line 11:
 ===== alternative firmware ===== ===== alternative firmware =====
   * [[https://github.com/arendst/Sonoff-Tasmota|Tasmota]]   * [[https://github.com/arendst/Sonoff-Tasmota|Tasmota]]
-    * works also on some other ESP based devices+    * works also on lots of ESP based devices and can be easily adopted to support even more. for example [[MagicHome|MagicHome RGB LED Controllers]]
     * provides control via serial / web / MQTT     * provides control via serial / web / MQTT
 ===== What I intend to do with it ===== ===== What I intend to do with it =====
Line 29: Line 29:
 You can either flash the Tasmona firmware as described below or hack your sonoff in any other way with any other firmware or even with the original firmware in place. All you need to achieve is, that you can send a http-get request to the sonoff to turn the light on and off. Tasmona does that, and since I am going to use it anyway for my project, I will assume you also flashed that. Also this solution requires the sonoff to have a static IP .. either do this with a reservation in your DHCP server or enter a fixed IP in the web-interface of Tasmona.  You can either flash the Tasmona firmware as described below or hack your sonoff in any other way with any other firmware or even with the original firmware in place. All you need to achieve is, that you can send a http-get request to the sonoff to turn the light on and off. Tasmona does that, and since I am going to use it anyway for my project, I will assume you also flashed that. Also this solution requires the sonoff to have a static IP .. either do this with a reservation in your DHCP server or enter a fixed IP in the web-interface of Tasmona. 
  
-In the dss web menu go to apps and open the ''Event-Responder'' app. create a new event and select the room and scene you want to use as trigger for your sonoff to turn on. as initiated activity select "Call URL" and enter ''http://<sonoff-ip>/cm?cmnd=Power%20On''. then give it some useful name and save.+In the dss web menu go to apps and open the ''Event-Responder'' app. create a new event and select the room and scene you want to use as trigger for your sonoff to turn on. as initiated activity select "Call URL" and enter ''%%http://<sonoff-ip>/cm?cmnd=Power%20On%%''. then give it some useful name and save.
  
-Create a second Responder, but this time select all other scenes in the same room as trigger (you can do that by holding CTRL on your keyboard while clicking on all the scenes you do NOT want your light to be on). then as action use again Call URL but this time enter ''http://<sonoff-ip>/cm?cmnd=Power%20Off''+Create a second Responder, but this time select all other scenes in the same room as trigger (you can do that by holding CTRL on your keyboard while clicking on all the scenes you do NOT want your light to be on). then as action use again Call URL but this time enter ''%%http://<sonoff-ip>/cm?cmnd=Power%20Off%%''
  
 that's it, you're all set. Congratulations you just saved yourself a day worth of fiddling with tools and scripts :) So why am I still going down the complicated route.. well, mainly **because I can** :) and also because i want to use more devices including some input devices in the future to do more complicated stuff which exceeds the capabilities of my DSS. Also, the Event-Responder is quite slow, it is even slower than my first solution with the DSS-API based mqtt-connector. So expect to wait 2-3 seconds for your light to go on. Unless you have a newer DSS than me. The newer models (DSS20 and 22) have faster cpu's and should be able to process these responders alot quicker.  that's it, you're all set. Congratulations you just saved yourself a day worth of fiddling with tools and scripts :) So why am I still going down the complicated route.. well, mainly **because I can** :) and also because i want to use more devices including some input devices in the future to do more complicated stuff which exceeds the capabilities of my DSS. Also, the Event-Responder is quite slow, it is even slower than my first solution with the DSS-API based mqtt-connector. So expect to wait 2-3 seconds for your light to go on. Unless you have a newer DSS than me. The newer models (DSS20 and 22) have faster cpu's and should be able to process these responders alot quicker. 
Line 42: Line 42:
  
 Here are the steps it took to flash the stock sonoff (current and more detailed instructions can be found in the [[https://github.com/arendst/Sonoff-Tasmota/wiki/Arduino-IDE|Tasmota wiki]] Here are the steps it took to flash the stock sonoff (current and more detailed instructions can be found in the [[https://github.com/arendst/Sonoff-Tasmota/wiki/Arduino-IDE|Tasmota wiki]]
-  - download the latest [[https://www.arduino.cc/en/Main/Software|Arduino IDE]] and unpack it.  +  - [[setup arduino IDE for ESP8266]]
-  - create a subdirectory called ''portable'' +
-  - start your arduino IDE and go to ''File->preferences'' and add this to //Additional Boards Manger URLs//:  ''http://arduino.esp8266.com/stable/package_esp8266com_index.json'' +
-  - select OK and go to ''Tools-Boards...-Boards Manager...'' and enter ''ESP'' into the search. now install the ''esp8266'' module and close that window. +
   - download the sourcecode tar.gz or zip package from the [[https://github.com/arendst/Sonoff-Tasmota/releases|Tasmota releases page]]   - download the sourcecode tar.gz or zip package from the [[https://github.com/arendst/Sonoff-Tasmota/releases|Tasmota releases page]]
   - extract the contents of the ''lib'' directory into your arduino ide's ''portable/sketchbook/libraries'' directory and extract the entire ''sonoff'' directory into your arduin IDE's ''portable/sketchbook/'' directory   - extract the contents of the ''lib'' directory into your arduino ide's ''portable/sketchbook/libraries'' directory and extract the entire ''sonoff'' directory into your arduin IDE's ''portable/sketchbook/'' directory
-  - verify your settings under Tools are like these: <code> 
-Board: "Generic ESP8266 Module"  <<<<!!!! 
-Flash Mode: "DOUT"  <<<<!!!! 
-Flash Size: "1M (no SPIFFS)"  <<<<!!!! 
-Debug Port: "Disabled" 
-Debug Level: "None" 
-LwIP Variant: "v2 Prebuilt (MSS=536)" 
-Reset Method: "ck" 
-Crystal Frequency: "26 MHz" 
-Flash Frequency: "40MHz" 
-Upload Using: "Serial" 
-CPU Frequency: "80 MHz" 
-Upload Speed: "115200" 
-Port: Your COM port connected to sonoff 
-</code> 
   - edit ''user_config.h'' and enter your wifi name and password. all other settings can be changed later once the device is booted, but you can of course set them here if you want. this will make it much faster if you flash alot of these devices and want the same settings on all of them.    - edit ''user_config.h'' and enter your wifi name and password. all other settings can be changed later once the device is booted, but you can of course set them here if you want. this will make it much faster if you flash alot of these devices and want the same settings on all of them. 
   - **make sure your sonoff is disconnected from the AC power lines***   - **make sure your sonoff is disconnected from the AC power lines***
Line 152: Line 134:
 Now that we got both our devices connected to the MQTT Broaker it is time to set up a Rules engine, to conenct the two together :)  Now that we got both our devices connected to the MQTT Broaker it is time to set up a Rules engine, to conenct the two together :) 
  
-[[https://nodered.org|Node-Red]] looks like a very capable and interesting Rules engine. I have also spotted another interesting open source project called [[https://thingsboard.io/]] which seems to be interesting for monitoring stuff. not in my focus right now, but worth a mention in order to investigate it later some day :) +[[node-red]] looks like a very capable and interesting Rules engine. I have also spotted another interesting open source project called [[https://thingsboard.io/]] which seems to be interesting for monitoring stuff. not in my focus right now, but worth a mention in order to investigate it later some day :) 
  
 installation is again very easy through npm:  installation is again very easy through npm: 
Line 203: Line 185:
 [Unit] [Unit]
 Description=Node.js MQTT DSS Bridge Description=Node.js MQTT DSS Bridge
-Requires=After=mosquitto.service       # Requires the mosquitto service to run first+Requires=mosquitto.service       # starts mosquitto first when this service is started manually 
 +After=mosquitto.service       # starts this after mosquitto on boot
  
 [Service] [Service]
Line 229: Line 212:
 [Unit] [Unit]
 Description=Node.js Node-RED Description=Node.js Node-RED
-Requires=After=node-red.service       # Requires the mosquitto service to run first+Requires=node-red.service       # starts node-red first when this service is started manually 
 +After=node-red.service       # starts this after node-red on boot
  
 [Service] [Service]
Line 276: Line 260:
  
 now restore your node-red settings now restore your node-red settings
 +
 +===== Next Steps =====
 +try to get ''mqtt-dss-bridge'' to use some sort of authentication. for encryption is not that important as the sonoff's probably won't have enough power to use encryption, and that's where it's needed most. (see [[https://github.com/arendst/Sonoff-Tasmota/issues/146|#146]])
 ===== Future projects ===== ===== Future projects =====
 eventually I'd like to write a script that uses the [[https://github.com/plan44/vdcd|plan44 vdcd]] external device API to integrate a sonoff device into a digitalSTROM setup as an emulated digitalstorm device. this will overcome the lag that is generated by querying the Web-API. we could then also create a dummy light bulb which will just publish its state to MQTT. by assigning it a different value for all of the scenes it is in, we can pass the room-state to MQTT with almost no lag. This will enable other devices like the sonoff to react immediately and not just during the next poll-interval.  eventually I'd like to write a script that uses the [[https://github.com/plan44/vdcd|plan44 vdcd]] external device API to integrate a sonoff device into a digitalSTROM setup as an emulated digitalstorm device. this will overcome the lag that is generated by querying the Web-API. we could then also create a dummy light bulb which will just publish its state to MQTT. by assigning it a different value for all of the scenes it is in, we can pass the room-state to MQTT with almost no lag. This will enable other devices like the sonoff to react immediately and not just during the next poll-interval. 
 +
 +see my progress on that at [[MQTT for digitalSTROM]]
  • sonoff.txt
  • Last modified: 07.09.2021 05:52
  • by Pascal Suter