Very old version v2.0-20180322
Now I need Sonoff S26 driven by its push button and from Domoticz with report its actual state to Domoticz.
It is time to try new versions, I think, so I load last version
ESP_Easy_mega_20201227_minimal_core_274_ESP8285_1M_OTA_Domoticz.bin
Push button on DPIO-0 and relay on GPIO-12
Easy task, so I wrote this rules:
( From Domoticz relay is driven through http://192.168.1.119/control?cmd=gpio,12,1 or 0 commands )
Code: Select all
On System#Boot do
gpio,12,0 // relay off
endon
on Tlacitko#State do // button on gpio0 pressed
event, change
endon
on change do
if [Relay#State]=0 // if relay is off
gpio,12,1 // set it to on
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=163&switchcmd=On // report relay state to Domoticz
else // if relay is on
gpio,12,0 // set it to off
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=163&switchcmd=Off // report relay state to Domoticz
endif
endon
I end boot with relay on.
If I remove
Code: Select all
on Tlacitko#State do // button on gpio0 pressed
event, change
endon
So push button event is fired once without button pressed after boot.
I can correct this behaviour by detecting first run of button event and not change relay state in this case.
But it can surprise someone and I think it's a bug in the code.
These rules are already working properly even after a reboot
Code: Select all
On System#Boot do
gpio,12,0 // relay off
TaskValueSet,3,1,1 // temporary variable Pom#State=1
endon
on Tlacitko#State do // button on gpio0 pressed
if [Pom#State]=0 // first run of this event?
event, change // no, so normally proceed
else
TaskValueSet,3,1,0 // first run of this event after reboot - set Pom#State=0 to indicate that first run was done
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=163&switchcmd=Off // and report relay off state to Domoticz
endif
endon
on change do
if [Relay#State]=0 // if relay is off
gpio,12,1 // set it to on
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=163&switchcmd=On // report relay state to Domoticz
else // if relay is on
gpio,12,0 // set it to off
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=163&switchcmd=Off // report relay state to Domoticz
endif
endon