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

Hello friends, i started a new Project in my home.
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.

This has everything you need :slight_smile:

Also this is helpful:
https://www.letscontrolit.com/wiki/index.php/Sonoff_Touch
especially the rules…

@hijinx thank you for your time.

ok i make this:

but doesnt work :frowning: what is wrong?

ps: my sonoff was flashet with TASMOTA firmware

@xbmcnut

Bit confused. You show pictures of ESPEasy but say Sonoff flashed with Tasmota. Can you define which you are using?

@xbmcnut
i have one esp8266 with button flashed with espeasy.ok?

and i have one sonoff flashed with tasmota firmware ok?

them is working with MQTT.

My goal is, when i press the button on ESP8266-01… i want that my sonoff turn on, and when i press button again on ESP8266-01, sonoff turn off.

Do you think can help me?

It would be much easier if both devices were running ESPEasy then you could use the rules feature as I did here to get two devices controlling one another.

2 Likes

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

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

device is nodemcu with relay.With name sonoff1

the config is:

rule:

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:

rule:

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 ?

My code I used to get two ESPEasy units to talk to one another is here Syncing two Sonoff’s for 2-way light switching

In the YouTube video comments, a user has also suggested using sendHTTP instead of MQTT as this will work even if your broker is offline.

Thanks tomorrow i will test again. I think i forgot to set " unit id"

@xbmcnut its need to check the option GLOBAL SYNC in advanced settings?

Only if you want to talk to one another using UDP EasyGlobalSync - Let's Control It. I found UDP too unreliable. Will not hurt to have this enabled anyway.

@xbmcnut ok its working now.

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.

rule device 1:

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

any idea?

Why do you not have any rules in Sonoff2? Also, your code above for Sonoff1 is turning itself on. My code for Sonoff1 turns on Sonoff2 and vice versa. I have local button control but remote MQTT control (of the other Sonoff).

@xbmcnut
I can connect my sonoff that is in my room, through the physical button that I have in the bedroom. But if I turn on my sonoff by the button, and turn it off by the HA, when it is called again by the button the sonoff will no longer turn on. Do you understand?

@ SOLVED


--------- RELAY -------

on relay#state do
if [relay#state]=1
GPIO,12,1
SendTo 2,inputswitchstate 0,1
else
GPIO,12,0
SendTo 2,inputswitchstate 0,0
endif
endon


-----EXTERNAL BUTTON ------

on button#state do
if [button#state]=0
Publish /sonoff1/cmd,GPIO,12,0
else
Publish /sonoff1/cmd,GPIO,12,1
endif
endon

1 Like

@Rodolfo_Vieira Great! Good to know.

I cant put all these comments together to one proper guide.
Will someone give me a step by step guide to this esp8266 button, that can control mqtt devices, like sonoff switch.

Greetings DK.

Instead of making rules in ESP Easy (I never tried them) you can make automation on HASS. For example I have a ESP8266 running ESP Easy with a 2 relay connected and another ESP8266 with a few touch buttons configured as Input Switch, each publishes 1 and 0 for On and Off on they’re own topic.

On Hass I made 4 automations:
To turn on the first relay:

  alias: "K1 ON"
  trigger:
    platform: mqtt
    topic: /Easy-Relay/button/button
    payload: '0'
  action:
    service: mqtt.publish
    data:
      topic: /Easy-Relay/gpio/12
      payload: '0'

To turn off the first relay:

  alias: "K1 OFF"
  trigger:
    platform: mqtt
    topic: /Easy-Relay/button/button
    payload: '1'
  action:
    service: mqtt.publish
    data:
      topic: /Easy-Relay/gpio/12
      payload: '1'

To turn off the second relay:

  alias: "K2 OFF"
  trigger:
    platform: mqtt
    topic: /Easy-Relay/touch-button/touch-button
    payload: '1'
  action:
    service: mqtt.publish
    data:
      topic: /Easy-Relay/gpio/15
      payload: '1'

and to turn it on:

  alias: "K2 ON"
  trigger:
    platform: mqtt
    topic: /Easy-Relay/touch-button/touch-button
    payload: '0'
  action:
    service: mqtt.publish
    data:
      topic: /Easy-Relay/gpio/15
      payload: '0'
1 Like