I use that scheme;

and my configuration sonoff is:

but i have a problem inside of portal esp8266, anyone knows how configure that?

my goal is when I press the esp8266 button, the sonoff switches on, and when I click again the sonoff switches off.
Moderators: grovkillen, Stuntteam, TD-er
Code: Select all
on relay#state do
if [relay#state]=1
GPIO,12,0
else
GPIO,12,1
endif
endon
Code: Select all
on button#state do
if [button#state]=0
Publish /sonoff1/cmd,GPIO,12,0
else
Publish /sonoff1/cmd,GPIO,12,1
endif
endon
grovkillen wrote: ↑29 Sep 2017, 08:58 On device one you should switch the 0 with 1 (but you don't need a device for setting the relay, if you don't want to, since relays are operated using the GPIO command):
On device two you should publish a "cmd" command. See wiki!Code: Select all
on relay#state do if [relay#state]=1 GPIO,12,0 else GPIO,12,1 endif endon
Now it Works.Code: Select all
on button#state do if [button#state]=0 Publish /sonoff1/cmd,GPIO,12,0 else Publish /sonoff1/cmd,GPIO,12,1 endif endon
thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu![]()
![]()
![]()
![]()
![]()
![]()
you dont read what i wrote.
Glad to have helped
Code: Select all
on button#state do
if [button#state]=0
Publish /sonoff1/cmd,GPIO,12,1
else
Publish /sonoff1/cmd,GPIO,12,0
endif
endon
grovkillen wrote: ↑30 Sep 2017, 14:23 This happens because the "button" didn't know that Home Assistant has switched the relay. To fix this you might use many different techniques MQTT Import being my favorite.
On the relay device you can I publish a topic with a 1 or 0 when the relay is switched. Let MQTT Import sniff that topic and set task value of the button accordingly.
Code: Select all
on button#state do
if [button#state]=0
Publish /sonoff3/cmd,GPIO,12,0
else
Publish /sonoff3/cmd,GPIO,12,1
endif
endon
Code: Select all
on mqtt_import#GPIO0 do
if [mqtt_import#GPIO0] = 1
gpio,12,1
else
gpio,12,0
endif
endon
Code: Select all
on relay#state do
if [relay#state]=1
GPIO,12,0
Publish /sonoff1/RelayStatus,0
else
GPIO,12,1
Publish /sonoff1/RelayStatus,1
endif
endon
Code: Select all
on button#state do
if [button#state]=0
Publish /sonoff1/cmd,GPIO,12,0
else
Publish /sonoff1/cmd,GPIO,12,1
endif
endon
on mqtt_import#GPIO0 do
if [mqtt_import#GPIO0] = 1
TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2...
else
TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2...
endif
endon
hello friend with that configuration. my relay always on off on off on off... and not stop.grovkillen wrote: ↑02 Oct 2017, 09:45 Sorry for not getting back to you until now.
What you need is this rule on the relay device:
And on the button device (and set up the MQTT Import to listen to "/sonoff1/RelayStatus"):Code: Select all
on relay#state do if [relay#state]=1 GPIO,12,0 Publish /sonoff1/RelayStatus,0 else GPIO,12,1 Publish /sonoff1/RelayStatus,1 endif endon
Please observe that I have not tested this in practice. You may test and see if it works. Please feel free to come backCode: Select all
on button#state do if [button#state]=0 Publish /sonoff1/cmd,GPIO,12,0 else Publish /sonoff1/cmd,GPIO,12,1 endif endon on mqtt_import#GPIO0 do if [mqtt_import#GPIO0] = 1 TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2... else TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2... endif endon
![]()
Code: Select all
on relay#state do
if [relay#state]=1
GPIO,12,0
Publish /sonoff1/RelayStatus,0
else
GPIO,12,1
Publish /sonoff1/RelayStatus,1
endif
endon
Code: Select all
on relay#state do
if [relay#state]=1
GPIO,12,1
Publish /sonoff1/RelayStatus,1
else
GPIO,12,0
Publish /sonoff1/RelayStatus,0
endif
endon
Code: Select all
on System#Boot do
Delay,5000 //Just to be sure...
TaskValueSet 3,1,0 //Just to be sure...
endon
on button#state do
if [button#state]=0
TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3...
Event EventTriggerButton1
else
TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3...
Event EventTriggerButton0
endif
endon
on mqtt_import#GPIO0 do
if [mqtt_import#GPIO0]=1
TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2...
else
TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2...
endif
endon
on EventTriggerButton1 do
if [Dummy#Value]=1
Publish /sonoff1/cmd,GPIO,12,1
TaskValueSet 3,1,0 //Set the check value to 0...
endif
endon
on EventTriggerButton0 do
if [Dummy#Value]=1
Publish /sonoff1/cmd,GPIO,12,0
TaskValueSet 3,1,0 //Set the check value to 0...
endif
endon
grovkillen wrote: ↑03 Oct 2017, 08:49 Oooh, sorry about that!
We need to use a counter (check value) since the TaskValueSet will trigger the button#state over and over again.
Code: Select all
on System#Boot do Delay,5000 //Just to be sure... TaskValueSet 3,1,0 //Just to be sure... endon on button#state do if [button#state]=0 TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3... Event EventTriggerButton1 else TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3... Event EventTriggerButton0 endif endon on mqtt_import#GPIO0 do if [mqtt_import#GPIO0]=1 TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2... else TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2... endif endon on EventTriggerButton1 do if [Dummy#Value]=1 Publish /sonoff1/cmd,GPIO,12,1 TaskValueSet 3,1,0 //Set the check value to 0... endif endon on EventTriggerButton0 do if [Dummy#Value]=1 Publish /sonoff1/cmd,GPIO,12,0 TaskValueSet 3,1,0 //Set the check value to 0... endif endon
Please upload your device page so I can see what names and task numbers you use. It's not complicated just different to what you have done before. Learning is power, once you got this working you will understand how to do more stuff.r16 wrote: ↑04 Oct 2017, 03:54grovkillen wrote: ↑03 Oct 2017, 08:49 Oooh, sorry about that!
We need to use a counter (check value) since the TaskValueSet will trigger the button#state over and over again.
Code: Select all
on System#Boot do Delay,5000 //Just to be sure... TaskValueSet 3,1,0 //Just to be sure... endon on button#state do if [button#state]=0 TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3... Event EventTriggerButton1 else TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3... Event EventTriggerButton0 endif endon on mqtt_import#GPIO0 do if [mqtt_import#GPIO0]=1 TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2... else TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2... endif endon on EventTriggerButton1 do if [Dummy#Value]=1 Publish /sonoff1/cmd,GPIO,12,1 TaskValueSet 3,1,0 //Set the check value to 0... endif endon on EventTriggerButton0 do if [Dummy#Value]=1 Publish /sonoff1/cmd,GPIO,12,0 TaskValueSet 3,1,0 //Set the check value to 0... endif endon
I appreciate your persistence, but it does not work. I think I'm going to give up.
I never thought this was so complicated to do.
on my sonoff1 i have this rule:grovkillen wrote: ↑04 Oct 2017, 05:55Please upload your device page so I can see what names and task numbers you use. It's not complicated just different to what you have done before. Learning is power, once you got this working you will understand how to do more stuff.r16 wrote: ↑04 Oct 2017, 03:54grovkillen wrote: ↑03 Oct 2017, 08:49 Oooh, sorry about that!
We need to use a counter (check value) since the TaskValueSet will trigger the button#state over and over again.
Code: Select all
on System#Boot do Delay,5000 //Just to be sure... TaskValueSet 3,1,0 //Just to be sure... endon on button#state do if [button#state]=0 TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3... Event EventTriggerButton1 else TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3... Event EventTriggerButton0 endif endon on mqtt_import#GPIO0 do if [mqtt_import#GPIO0]=1 TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2... else TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2... endif endon on EventTriggerButton1 do if [Dummy#Value]=1 Publish /sonoff1/cmd,GPIO,12,1 TaskValueSet 3,1,0 //Set the check value to 0... endif endon on EventTriggerButton0 do if [Dummy#Value]=1 Publish /sonoff1/cmd,GPIO,12,0 TaskValueSet 3,1,0 //Set the check value to 0... endif endon
I appreciate your persistence, but it does not work. I think I'm going to give up.
I never thought this was so complicated to do.![]()
Code: Select all
on relay#state do
if [relay#state]=1
GPIO,12,1
Publish /sonoff1/RelayStatus,1
else
GPIO,12,0
Publish /sonoff1/RelayStatus,0
endif
endon
Code: Select all
on System#Boot do
Delay,5000 //Just to be sure...
TaskValueSet 3,1,0 //Just to be sure...
endon
on button#state do
if [button#state]=0
TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3...
Event EventTriggerButton1
else
TaskValueSet 3,1,1 //Given that a Dummy device is on TaskNr 3...
Event EventTriggerButton0
endif
endon
on mqtt_import#GPIO0 do
if [mqtt_import#GPIO0]=1
TaskValueSet 2,1,1 //Given that the switch device is on TaskNr 2...
else
TaskValueSet 2,1,0 //Given that the switch device is on TaskNr 2...
endif
endon
on EventTriggerButton1 do
if [Dummy#Value]=1
Publish /sonoff1/cmd,GPIO,12,1
TaskValueSet 3,1,0 //Set the check value to 0...
endif
endon
on EventTriggerButton0 do
if [Dummy#Value]=1
Publish /sonoff1/cmd,GPIO,12,0
TaskValueSet 3,1,0 //Set the check value to 0...
endif
endon
I already tried.
Now. WORKS LIKE A CHARMvader wrote: ↑04 Oct 2017, 18:28 Ah,ok. I know that problem (had the same with Domoticz). I had to press the button twice to be in sync again with the relay on other device.
Change the rule on sonoff1 in:
on relay#state do
if [relay#state]=1
GPIO,12,1
Publish /sonoff1/RelayStatus,1
SendTo 2,inputswitchstate 0,1
else
GPIO,12,0
Publish /sonoff1/RelayStatus,0
SendTo 2,inputswitchstate 0,0
endif
endon
Users browsing this forum: No registered users and 18 guests