Push button event every reboot or power on. Bug?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
kimot
Normal user
Posts: 177
Joined: 12 Oct 2017, 20:46

Push button event every reboot or power on. Bug?

#1 Post by kimot » 20 Jan 2021, 21:12

I am using about 10 Sonoff Basics couple of years like floor heating thermostats without any problems.
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&param=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&param=switchlight&idx=163&switchcmd=Off    // report relay state to Domoticz
  endif
endon
All works good except power on or reboot sequence.
I end boot with relay on.

If I remove

Code: Select all

on Tlacitko#State do       // button on gpio0 pressed
     event, change			
endon
I start correctly with relay off and can drive relay only from Domoticz of course.

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&param=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&param=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&param=switchlight&idx=163&switchcmd=Off    // report relay state to Domoticz
  endif
endon
Setting internal pullUp has no effect


2021-01-20-202834_1920x1080_scrot.png
2021-01-20-202834_1920x1080_scrot.png (103.01 KiB) Viewed 839 times
2021-01-20-203010_1920x1080_scrot.png
2021-01-20-203010_1920x1080_scrot.png (130.5 KiB) Viewed 839 times

TD-er
Core team member
Posts: 4270
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Push button event every reboot or power on. Bug?

#2 Post by TD-er » 20 Jan 2021, 22:21

Have you also looked here: https://espeasy.readthedocs.io/en/lates ... /P029.html
??
It does mainly help on Domoticz MQTT, but it does make things a lot simpler for interacting with GPIOs and Domoticz

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests