relay state after reboot

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

relay state after reboot

#1 Post by manjh » 15 Jul 2017, 18:08

I've set up a Sonoff 4CH with ESP Easy and am now fine tuning the rules.
Besides simple "on" and "off", I've also created rules for the buttons to toggle the relay.
Works fine.
But I have also set two of the relays to be switched on after reboot. It works, the two relays are activated. But after that the two corresponding buttons have no effect!
In detail: relais 1 and 4 are switched off, 2 and 3 are switched on after reboot.
Then buttons 1 and 4 work fine, buttons 2 and 3 not.
It can be solved by sending an "off" command, then buttons 2 and 3 are OK again.

I tested this using the command field: evoking my "toggle" rule has no effect, turning it "off" resets the state and from that moment on everything works.
It feels like turning the relay on after boot "freezes" that state until an explicite "off" is done.

What is wrong here? Am I doing something wrong or is this a bug?

Another thing I noticed: the relay devices are defined with both "send boot state" and "send data", but the two relays that are switched on after reboot show up in Domoticz as "off", even though they are really on.

Here's a part of the rules (I copied only the relevant rules):

Code: Select all

On TurnOn1 do
  gpio, 12, 1
endon
On TurnOff1 do
  gpio, 12, 0
endon
On TurnOn2 do
  gpio, 5, 1
endon
On TurnOff2 do
  gpio, 5, 0
endon
On TurnOn3 do
  gpio, 4, 1
endon
On TurnOff3 do
  gpio, 4, 0
endon
On TurnOn4 do
  gpio, 15, 1
endon
On TurnOff4 do
  gpio, 15, 0
endon

on System#Boot do
  Event TurnOff1
  Event TurnOn2
  Event TurnOn3
  Event TurnOff4
endon
And a screenshot of one of the four devices:
Image

Screenshot of one of the buttons:
Image
Attachments
Schermafdruk 2017-07-16 20.15.01.png
Schermafdruk 2017-07-16 20.15.01.png (96.39 KiB) Viewed 18296 times
Schermafdruk 2017-07-16 09.33.15.png
Schermafdruk 2017-07-16 09.33.15.png (97.07 KiB) Viewed 18340 times
Last edited by manjh on 16 Jul 2017, 20:18, edited 3 times in total.

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: relay state after reboot

#2 Post by LisaM » 15 Jul 2017, 21:09

manjh wrote: 15 Jul 2017, 18:08 I've set up a Sonoff 4CH with ESP Easy and am now fine tuning the rules.
Besides simple "on" and "off", I've also created rules for the buttons to toggle the relay.
Works fine.
But I have also set two of the relays to be switched on after reboot. It works, the two relays are activated. But after that the two corresponding buttons have no effect!
In detail: relais 1 and 4 are switched off, 2 and 3 are switched on after reboot.
Then buttons 1 and 4 work fine, buttons 2 and 3 not.
It can be solved by sending an "off" command, then buttons 2 and 3 are OK again.

I tested this using the command field: evoking my "toggle" rule has no effect, turning it "off" resets the state and from that moment on everything works.
It feels like turning the relay on after boot "freezes" that state until an explicite "off" is done.

What is wrong here? Am I doing something wrong or is this a bug?

Another thing I noticed: the relay devices are defined with both "send boot state" and "send data", but the two relays that are switched on after reboot show up in Domoticz as "off", even though they are really on.
Rules + devices screenshot please!!!

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#3 Post by manjh » 16 Jul 2017, 09:37

LisaM wrote: 15 Jul 2017, 21:09 Rules + devices screenshot please!!!
Done.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: relay state after reboot

#4 Post by grovkillen » 16 Jul 2017, 10:32

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#5 Post by manjh » 16 Jul 2017, 12:11

grovkillen wrote: 16 Jul 2017, 10:32 Please study this information.

https://www.letscontrolit.com/wiki/inde ... figuration
Can you be more specific as to which part of this overview contains a lead to my problem?
The Sonoff 4CH uses GPIO 12, 5, 4 and 15 for the relays. I realize 4 and 5 are normally used for SDA/SCL, but I removed them from the hardware page (SDA and SCL now blank, so unassigned).

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: relay state after reboot

#6 Post by grovkillen » 16 Jul 2017, 14:44

Since you didn't mention stuff like this it is hard to help. But you could add a delay before setting the GPIO state. Right on boot might be a tad too fast?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#7 Post by manjh » 16 Jul 2017, 15:39

grovkillen wrote: 16 Jul 2017, 14:44 Since you didn't mention stuff like this it is hard to help. But you could add a delay before setting the GPIO state. Right on boot might be a tad too fast?
I will try that.

But it is still very strange, since the actions are actually performed OK but the state of the two relays that are switched on are very cryptical. They respond to nothing except an "off" command, and after that they are normal again.

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: relay state after reboot

#8 Post by LisaM » 16 Jul 2017, 19:39

manjh wrote: 16 Jul 2017, 09:37
LisaM wrote: 15 Jul 2017, 21:09 Rules + devices screenshot please!!!
Done.
Screenshots of the button devices?

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#9 Post by manjh » 16 Jul 2017, 20:18

LisaM wrote: 16 Jul 2017, 19:39
manjh wrote: 16 Jul 2017, 09:37
LisaM wrote: 15 Jul 2017, 21:09 Rules + devices screenshot please!!!
Done.
Screenshots of the button devices?
Done.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: relay state after reboot

#10 Post by grovkillen » 16 Jul 2017, 22:42

Those images are broken for me.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#11 Post by manjh » 16 Jul 2017, 23:45

grovkillen wrote: 16 Jul 2017, 22:42 Those images are broken for me.
Weird/ They show up fine as attachements to me...
I'll have another look tomorrow morning.. :?

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: relay state after reboot

#12 Post by LisaM » 17 Jul 2017, 00:16

manjh wrote: 16 Jul 2017, 20:18 Done.
I'm missing some toggle rules like this one:

Code: Select all

On Button2#State do
    If [Relais2#State]=1
        gpio,5,0
    Else
        gpio,5,1
    EndIf
EndOn

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#13 Post by manjh » 17 Jul 2017, 00:31

LisaM wrote: 17 Jul 2017, 00:16
manjh wrote: 16 Jul 2017, 20:18 Done.
I'm missing some toggle rules like this one:

Code: Select all

On Button2#State do
    If [Relais2#State]=1
        gpio,5,0
    Else
        gpio,5,1
    EndIf
EndOn
I did not think they are relevant.At bootup I only use on and off.... that puts the two 'on" relays in a very strange state.

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: relay state after reboot

#14 Post by LisaM » 17 Jul 2017, 00:36

manjh wrote: 17 Jul 2017, 00:31
LisaM wrote: 17 Jul 2017, 00:16
manjh wrote: 16 Jul 2017, 20:18 Done.
I'm missing some toggle rules like this one:

Code: Select all

On Button2#State do
    If [Relais2#State]=1
        gpio,5,0
    Else
        gpio,5,1
    EndIf
EndOn
I did not think they are relevant.At bootup I only use on and off.... that puts the two 'on" relays in a very strange state.
:?: At bootup you put the relay to the on state, then when pushing the corresponding button you want it to change state? Since it's a push button, there's no on or off state but only toggle...

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#15 Post by manjh » 17 Jul 2017, 09:13

LisaM wrote: 17 Jul 2017, 00:36
manjh wrote: 17 Jul 2017, 00:31
LisaM wrote: 17 Jul 2017, 00:16
I'm missing some toggle rules like this one:

Code: Select all

On Button2#State do
    If [Relais2#State]=1
        gpio,5,0
    Else
        gpio,5,1
    EndIf
EndOn
I did not think they are relevant.At bootup I only use on and off.... that puts the two 'on" relays in a very strange state.
:?: At bootup you put the relay to the on state, then when pushing the corresponding button you want it to change state? Since it's a push button, there's no on or off state but only toggle...
Correct. Two more rules that I use but did not show yet:

Code: Select all

on Toggle2 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
on button2#state do
  Event Toggle2
endon

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: relay state after reboot

#16 Post by papperone » 17 Jul 2017, 12:13

Can you try like this:

Code: Select all

on System#Boot do
  Event TurnOff1
  Event TurnOff2
  Event TurnOff3
  Event TurnOff4
  Event Toggle2
  Event Toggle3
endon
I can imagine your toggle events get confused when you set channels manually On at boot so above should work properly
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#17 Post by manjh » 17 Jul 2017, 17:24

papperone wrote: 17 Jul 2017, 12:13 Can you try like this:

Code: Select all

on System#Boot do
  Event TurnOff1
  Event TurnOff2
  Event TurnOff3
  Event TurnOff4
  Event Toggle2
  Event Toggle3
endon
I can imagine your toggle events get confused when you set channels manually On at boot so above should work properly
I tried this approach, does not make any difference.

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: relay state after reboot

#18 Post by LisaM » 17 Jul 2017, 21:45

manjh wrote: 17 Jul 2017, 09:13

Code: Select all

on Toggle2 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
on button2#state do
  Event Toggle2
endon
Did you try :

Code: Select all

on Toggle2=1 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#19 Post by manjh » 17 Jul 2017, 22:12

LisaM wrote: 17 Jul 2017, 21:45
manjh wrote: 17 Jul 2017, 09:13

Code: Select all

on Toggle2 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
on button2#state do
  Event Toggle2
endon
Did you try :

Code: Select all

on Toggle2=1 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
No, I did not try that. But I don't see the point: all rules work just fine. The only problem is when I switch a relay on after boot. It then goes into a strange state, which can only be corrected by an explicit "off" command.

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: relay state after reboot

#20 Post by LisaM » 17 Jul 2017, 22:20

manjh wrote: 17 Jul 2017, 22:12
LisaM wrote: 17 Jul 2017, 21:45
manjh wrote: 17 Jul 2017, 09:13

Code: Select all

on Toggle2 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
on button2#state do
  Event Toggle2
endon
Did you try :

Code: Select all

on Toggle2=1 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
No, I did not try that. But I don't see the point: all rules work just fine. The only problem is when I switch a relay on after boot. It then goes into a strange state, which can only be corrected by an explicit "off" command.
Set a timer at boot and set state in the timer on a later time?

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#21 Post by manjh » 18 Jul 2017, 01:04

LisaM wrote: 17 Jul 2017, 22:20
manjh wrote: 17 Jul 2017, 22:12
LisaM wrote: 17 Jul 2017, 21:45
Did you try :

Code: Select all

on Toggle2=1 do
  if [relais2#state]=1
    Event TurnOff2
  else
    Event TurnOn2
  endif
endon
No, I did not try that. But I don't see the point: all rules work just fine. The only problem is when I switch a relay on after boot. It then goes into a strange state, which can only be corrected by an explicit "off" command.
Set a timer at boot and set state in the timer on a later time?
Will try that. If it works my problem is solved by this workaround, but it does not explain what is going on here... :?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: relay state after reboot

#22 Post by grovkillen » 18 Jul 2017, 06:32

Since it is the two I2C pins it might be that these are still being active as such right at boot. (Just my wild guess, I haven't studied the code.)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#23 Post by manjh » 18 Jul 2017, 09:03

grovkillen wrote: 18 Jul 2017, 06:32 Since it is the two I2C pins it might be that these are still being active as such right at boot. (Just my wild guess, I haven't studied the code.)
Ah, that could make sense. During the boot process the I2C is activated (or in this case: deactivated). If that happens after the execution of the "on boot" command block, it could explain the behaviour.
I will try. But if it does work, I would think we can qualify this as a bug... :oops:

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#24 Post by manjh » 18 Jul 2017, 09:36

I just tried this approach: in the system-boot section added a timerset for 5 seconds.
Then when the timer expires, switched on the two relays that I want switched on.
After this everything works as it should! :)

It could mean that the I2C initializing is done after the execution of the system-boot block in the rules.
Do we classify this as a bug?

For now, I am happy to leave the timerdelay in there. The unit does not boot-up often, so it is not a big deal.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: relay state after reboot

#25 Post by grovkillen » 18 Jul 2017, 10:48

Yes, that's considered a bug. Will you file it as an issue on GitHub?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

manjh
Normal user
Posts: 516
Joined: 08 Feb 2016, 11:22

Re: relay state after reboot

#26 Post by manjh » 18 Jul 2017, 12:21

grovkillen wrote: 18 Jul 2017, 10:48 Yes, that's considered a bug. Will you file it as an issue on GitHub?
Done.

vbs
New user
Posts: 2
Joined: 08 Apr 2018, 12:40

Re: relay state after reboot

#27 Post by vbs » 08 Apr 2018, 12:41

I think I also do suffer from that problem.

I cannot find the Github issue you have created. Could you provide a link please?

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests