{"id":315,"date":"2016-11-30T23:35:41","date_gmt":"2016-11-30T22:35:41","guid":{"rendered":"https:\/\/ms07.de\/blog\/?p=315"},"modified":"2017-10-26T10:00:56","modified_gmt":"2017-10-26T08:00:56","slug":"sonoff-s20-and-espeasy","status":"publish","type":"post","link":"https:\/\/ms07.de\/blog\/?p=315","title":{"rendered":"Sonoff S20 and espeasy"},"content":{"rendered":"<h1>Flash espeasy<\/h1>\n<p>Image can be found <a href=\"http:\/\/www.letscontrolit.com\/wiki\/index.php\/ESPEasy#Stable\">here.<\/a><br \/>\nTo boot the sonoff into flash mode, press and hold the button while connecting it to power.<\/p>\n<pre>.\/esptool.py --port \/dev\/ttyUSB0 write_flash 0x000 ESPEasy_R120_1024.bin -fs 8m<\/pre>\n<h1>Connect to wifi and configure<\/h1>\n<p>Connect to <strong>ESP_0<\/strong> with password <strong>configesp <\/strong>and set up the wifi connection.<\/p>\n<p>After connecting to wifi open the webinterface http:\/\/ip.of.sonoff\/config and configure the name and unit number. The name of my sonoff is <strong>sonoff-s20<\/strong>.<\/p>\n<p>Configure <strong>Hardware<\/strong> and <strong>Devices<\/strong>.<\/p>\n<p><a href=\"https:\/\/ms07.de\/blog\/wp-content\/uploads\/2016\/11\/espeasy-hardware-1.png\" rel=\"lightbox[315]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-330 size-thumbnail\" src=\"https:\/\/ms07.de\/blog\/wp-content\/uploads\/2016\/11\/espeasy-hardware-1-150x150.png\" alt=\"espeasy-hardware\" width=\"150\" height=\"150\" \/><\/a><a href=\"https:\/\/ms07.de\/blog\/wp-content\/uploads\/2016\/11\/espeasy-button-1.png\" rel=\"lightbox[315]\"> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-329\" src=\"https:\/\/ms07.de\/blog\/wp-content\/uploads\/2016\/11\/espeasy-button-1-150x150.png\" alt=\"espeasy-button\" width=\"150\" height=\"150\" \/><\/a> <a href=\"https:\/\/ms07.de\/blog\/wp-content\/uploads\/2016\/11\/espeasy-relay-1.png\" rel=\"lightbox[315]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-331 size-thumbnail\" src=\"https:\/\/ms07.de\/blog\/wp-content\/uploads\/2016\/11\/espeasy-relay-1-150x150.png\" alt=\"espeasy-relay\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>Enable rules: <strong>Tools &#8211; Advanced &#8211;\u00a0Rules: Checked<\/strong><\/p>\n<p>Now there is a new menu entry named <strong>Rules<\/strong><\/p>\n<pre>On Button#State=1 do\r\n\u00a0 if [Relay#State]=0\r\n\u00a0\u00a0\u00a0 gpio,12,1\r\n\u00a0 else\r\n\u00a0\u00a0\u00a0 gpio,12,0\r\n\u00a0 endif\r\nendon<\/pre>\n<p>Now you can toggle the relay with the button.<\/p>\n<h1>MQTT usage<\/h1>\n<p>I use the protocol <strong>OpenHAB MQTT<\/strong>. So I can subscribe these events:<\/p>\n<pre># mosquitto_sub -h my.mqtt.server -t \"#\" -v\r\n\/sonoff-s20\/Relay\/State 1\r\n\/sonoff-s20\/Relay\/State 0<\/pre>\n<p>To switch on and off you can publish these messages:<\/p>\n<pre># mosquitto_pub -h 192.168.1.99 -t \"\/sonoff-s20\/gpio\/12\" -m \"1\"\r\n# mosquitto_pub -h 192.168.1.99 -t \"\/sonoff-s20\/gpio\/12\" -m \"0\"<\/pre>\n<p>It is also possible to change &#8222;Relay&#8220; to &#8222;gpio&#8220; and &#8222;State&#8220; to &#8222;12&#8220;. In this case, the subscribed and published strings are the same, but the rules also have to be modified.<\/p>\n<p>192.168.1.99 is the IP-Address of the MQTT-Server (for example, mosquitto).<\/p>\n<h1>openHAB configuration<\/h1>\n<p>After configuration of the mqtt-binding in openhab.cfg I created a new item-file<br \/>\nitems\/sonoff.items:<\/p>\n<pre>Switch sonoff01 \"Sonoff Socket\" {mqtt=\"&gt;[mosquitto:\/sonoff-s20\/gpio\/12:command:ON:1],&gt;[mosquitto:\/sonoff-s20\/gpio\/12:command:OFF:0],&lt;[mosquitto:\/sonoff-s20\/Relay\/State:state:MAP(mqtt.map)]\", autoupdate=\"false\"}<\/pre>\n<p>I also created the file transforms\/mqtt.map<\/p>\n<pre>0=OFF\r\n1=ON<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Flash espeasy Image can be found here. To boot the sonoff into flash mode, press and hold the button while connecting it to power. .\/esptool.py &#8211;port \/dev\/ttyUSB0 write_flash 0x000 ESPEasy_R120_1024.bin -fs 8m Connect to wifi and configure Connect to ESP_0 with password configesp and set up the wifi connection. After connecting to wifi open the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-it","category-linux"],"_links":{"self":[{"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":25,"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions\/385"}],"wp:attachment":[{"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ms07.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}