Button mqtt (espeasy) for turn ON sonoff on other place (SOLVED)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Button mqtt (espeasy) for turn ON sonoff on other place (SOLVED)

#1 Post by r16 » 27 Sep 2017, 22:39

Hello friends, i started a new Project in my home.
I use that scheme;
Image

and my configuration sonoff is:
Image

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


my goal is when I press the esp8266 button, the sonoff switches on, and when I click again the sonoff switches off.
Last edited by r16 on 04 Oct 2017, 21:34, edited 1 time in total.

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#2 Post by r16 » 28 Sep 2017, 02:28

i tried to make this but no sucess, i cant turn on my sonoff throught my esp

Image

Image

Image

Image

but doesnt work :( what is wrong?

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#3 Post by grovkillen » 28 Sep 2017, 06:15

Only float is possible to use in the rules arithmetic tests. Please study the rule tutorial section in the wiki. Your syntax are generally wrong.
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:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#4 Post by vader » 28 Sep 2017, 11:08

1. The scheme shows button connected to RST, not GPIO0 (I assume you know that...)
2. Switch button type must be "Push Button Active Low"
3. The Sonoffs have the relay on GPIO12 (LED on GPIO13, reversed logic!)
4. Change the value name of the switch from "power" to "state", like in the rule used
5. "endif" is missing in the rules (I don't know if this is important?)
6. Only 0 and 1 as value are allowed in the rules for a switch device

Use the "SendTo" command to switch ON/OFF a device connected to another Sonoff unit (Global Sync enabled), or use the "Publish" command for MQTT...

Now it should work.... ;)

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#5 Post by r16 » 29 Sep 2017, 01:07

@vader

hello again, ok..... i installed ESPEASY on my two devices.

----------------------------DEVICE 1----------------------------------------


**device is nodemcu with relay.With name sonoff1**

_the config is:_

Image

_rule:_
Image

**i defined UDP 65432**
this device i want control via HA and button of my esp.

Result with that rule:
HA control - OK
button ESP01- NOT OK

........................................DEVICE 2........................

**device is ESP01 with press button.With name sonoff2**

_the config is:_

Image

_rule:_
Image

**i defined UDP 65432**

this device i want when i press button the device 1 TURN ON when presse again device 1 TURN OFF

Result with that rule:

the state of button changes - OK
Device 1 not happens nothing.

where is the problem ?

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#6 Post by grovkillen » 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):

Code: Select all

on relay#state do
 if [relay#state]=1
  GPIO,12,0
 else
  GPIO,12,1
 endif
endon
On device two you should publish a "cmd" command. See wiki!

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
Given that the device one is subscribing to the "/sonoff1/#" on the FIRST controller. (Though the correct setting would state "/%sysname%/#", see wiki!)
You should not care about the GPIO-0 and try to set it to HIGH or LOW. This is not something you do since the microcontroller only alternates between 1/0 upon a toggle of the button.
Last edited by grovkillen on 29 Sep 2017, 09:06, edited 1 time in total.
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:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#7 Post by vader » 29 Sep 2017, 09:05

Set both Sonoffs --> "1st GPIO = GPIO0"
Switch Button Type --> "Switch Button Active Low"

In Sonoff2 remove GPIO0 setting in the rules

Check the MQTT communication in the logs

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#8 Post by r16 » 29 Sep 2017, 19:47

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):

Code: Select all

on relay#state do
 if [relay#state]=1
  GPIO,12,0
 else
  GPIO,12,1
 endif
endon
On device two you should publish a "cmd" command. See wiki!

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
Now it Works.
thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen:
Last edited by r16 on 29 Sep 2017, 19:54, edited 1 time in total.

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#9 Post by vader » 29 Sep 2017, 19:58

Because the button of the Sonoffs is connected to GPIO-0. The relay does not need an entry in the device/task list. Only a switch with GPIO-0 for turning on/off the relay over a rule and GPIO-12. LED on GPIO-13...

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#10 Post by r16 » 29 Sep 2017, 20:35

vader wrote: 29 Sep 2017, 19:58 Because the button of the Sonoffs is connected to GPIO-0. The relay does not need an entry in the device/task list. Only a switch with GPIO-0 for turning on/off the relay over a rule and GPIO-12. LED on GPIO-13...
you dont read what i wrote.
i dont have sonoff´s
my device are:
1. esp8266-01
2. nodemcu v3

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#11 Post by grovkillen » 29 Sep 2017, 21:13

r16 wrote: 29 Sep 2017, 19:47 Now it Works.
thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen:
Glad to have helped :D
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:

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#12 Post by r16 » 29 Sep 2017, 22:17

@grovkillen

now i have other problem.
The button Works fine, when i press it, the relay of device 2 changes from on to off and vice versa.
but when i click on button throught HOME ASSISTANT, the status of relay changes, but if i press the button of the device 1... it doesn´t Work.

did you have a home assistant?

rule device 1:

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

rule device 2:
no rules

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#13 Post by grovkillen » 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.
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:

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#14 Post by r16 » 01 Oct 2017, 05:06

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.

What are you saying is:
on my device (sonoff2) where i have a button

put the rule:

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
and other device (sonoff3) create something like this?

Image


and create that rule:

Code: Select all

on mqtt_import#GPIO0 do
  if [mqtt_import#GPIO0] = 1
    gpio,12,1
  else
    gpio,12,0
  endif
endon
is this? i am trying but i am very confused.

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#15 Post by grovkillen » 02 Oct 2017, 09:45

Sorry for not getting back to you until now.

What you need is this rule on the relay device:

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
And on the button device (and set up the MQTT Import to listen to "/sonoff1/RelayStatus"):

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
Please observe that I have not tested this in practice. You may test and see if it works. Please feel free to come back :)
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:

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#16 Post by r16 » 02 Oct 2017, 13:14

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:

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
And on the button device (and set up the MQTT Import to listen to "/sonoff1/RelayStatus"):

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
Please observe that I have not tested this in practice. You may test and see if it works. Please feel free to come back :)
hello friend with that configuration. my relay always on off on off on off... and not stop.


i tried to change this:

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
for this:

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
but does not work too

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#17 Post by grovkillen » 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


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:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#18 Post by vader » 03 Oct 2017, 11:05

And why don't you use the button with Global Sync enabled? So the state should be on all devices the same and you don't have the stress with complicate sync rules!?

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#19 Post by r16 » 04 Oct 2017, 03:54

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




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.

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#20 Post by r16 » 04 Oct 2017, 03:55

vader wrote: 03 Oct 2017, 11:05 And why don't you use the button with Global Sync enabled? So the state should be on all devices the same and you don't have the stress with complicate sync rules!?
Please, Put here the steps I have to take.

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#21 Post by grovkillen » 04 Oct 2017, 05:55

r16 wrote: 04 Oct 2017, 03:54
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




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.
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. ;)
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:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#22 Post by vader » 04 Oct 2017, 12:18

Ooops, doesn't work. Work not for switches. Only sensor values.... 8-)

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#23 Post by r16 » 04 Oct 2017, 15:23

grovkillen wrote: 04 Oct 2017, 05:55
r16 wrote: 04 Oct 2017, 03:54
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




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.
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. ;)
on my sonoff1 i have this rule:

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
Image




on my sonoff2 (buttoN) i have this rule:

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


that is my config on sonoff2:


Image
Image

with this configuration..my button not Works..
and the relay status not change.

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#24 Post by vader » 04 Oct 2017, 18:09

Try this:

Make sonoff1 = Unit Number 1 (see Config page)
Make sonoff2 = Unit Number 2
On sonoff2 rule:

on button#state do
if [button#state]=0
SendTo 1,gpio,12,0
else
SendTo 1,gpio,12,1
endif
endon

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#25 Post by r16 » 04 Oct 2017, 18:16

vader wrote: 04 Oct 2017, 18:09 Try this:

Make sonoff1 = Unit Number 1 (see Config page)
Make sonoff2 = Unit Number 2
On sonoff2 rule:

on button#state do
if [button#state]=0
SendTo 1,gpio,12,0
else
SendTo 1,gpio,12,1
endif
endon
I already tried.
But the problem is;
If i press button relay of sonoff1 turn on.
But if i turn off relay through Home assistant, and press again button...the relay not turn on again.

Because button dont knows the state of sonoff1.do you undestand?

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#26 Post by vader » 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

So it inform sonoff2 to change the button state. And I found this:

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

Shouldn't it be 0? And task #3 does not exist!
It's all just a kind of logic puzzle... ;)

r16
Normal user
Posts: 24
Joined: 12 Dec 2016, 02:48

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#27 Post by r16 » 04 Oct 2017, 21:18

vader 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

Now. WORKS LIKE A CHARM
sooooo easy, thank you @Vader and grovkillen for all persistence.
Perfect.
Now i can make this:
https://www.youtube.com/watch?v=ImVK5cGVrpQ&t=1s
:mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#28 Post by vader » 04 Oct 2017, 21:28

No problem. You are welcome. :D I know this, because I have all the crap already behind me.... :mrgreen:

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

Re: Button mqtt (espeasy) for turn ON sonoff on other place

#29 Post by grovkillen » 04 Oct 2017, 21:30

Sorry for not giving you the correct rules (didn't know your setup etc.). But glad you got it to work!! :D
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:

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 19 guests