Page 1 of 1
relay state after reboot
Posted: 15 Jul 2017, 18:08
by manjh
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:
Screenshot of one of the buttons:

Re: relay state after reboot
Posted: 15 Jul 2017, 21:09
by LisaM
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!!!
Re: relay state after reboot
Posted: 16 Jul 2017, 09:37
by manjh
LisaM wrote: ↑15 Jul 2017, 21:09
Rules + devices screenshot please!!!
Done.
Re: relay state after reboot
Posted: 16 Jul 2017, 10:32
by grovkillen
Re: relay state after reboot
Posted: 16 Jul 2017, 12:11
by manjh
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).
Re: relay state after reboot
Posted: 16 Jul 2017, 14:44
by grovkillen
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?
Re: relay state after reboot
Posted: 16 Jul 2017, 15:39
by manjh
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.
Re: relay state after reboot
Posted: 16 Jul 2017, 19:39
by LisaM
manjh wrote: ↑16 Jul 2017, 09:37
LisaM wrote: ↑15 Jul 2017, 21:09
Rules + devices screenshot please!!!
Done.
Screenshots of the button devices?
Re: relay state after reboot
Posted: 16 Jul 2017, 20:18
by manjh
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.
Re: relay state after reboot
Posted: 16 Jul 2017, 22:42
by grovkillen
Those images are broken for me.
Re: relay state after reboot
Posted: 16 Jul 2017, 23:45
by manjh
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..

Re: relay state after reboot
Posted: 17 Jul 2017, 00:16
by LisaM
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
Re: relay state after reboot
Posted: 17 Jul 2017, 00:31
by manjh
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.
Re: relay state after reboot
Posted: 17 Jul 2017, 00:36
by LisaM
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...
Re: relay state after reboot
Posted: 17 Jul 2017, 09:13
by manjh
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
Re: relay state after reboot
Posted: 17 Jul 2017, 12:13
by papperone
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
Re: relay state after reboot
Posted: 17 Jul 2017, 17:24
by manjh
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.
Re: relay state after reboot
Posted: 17 Jul 2017, 21:45
by LisaM
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
Re: relay state after reboot
Posted: 17 Jul 2017, 22:12
by manjh
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.
Re: relay state after reboot
Posted: 17 Jul 2017, 22:20
by LisaM
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?
Re: relay state after reboot
Posted: 18 Jul 2017, 01:04
by manjh
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...

Re: relay state after reboot
Posted: 18 Jul 2017, 06:32
by grovkillen
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.)
Re: relay state after reboot
Posted: 18 Jul 2017, 09:03
by manjh
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...

Re: relay state after reboot
Posted: 18 Jul 2017, 09:36
by manjh
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.
Re: relay state after reboot
Posted: 18 Jul 2017, 10:48
by grovkillen
Yes, that's considered a bug. Will you file it as an issue on GitHub?
Re: relay state after reboot
Posted: 18 Jul 2017, 12:21
by manjh
grovkillen wrote: ↑18 Jul 2017, 10:48
Yes, that's considered a bug. Will you file it as an issue on GitHub?
Done.
Re: relay state after reboot
Posted: 08 Apr 2018, 12:41
by vbs
I think I also do suffer from that problem.
I cannot find the Github issue you have created. Could you provide a link please?