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.
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.
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
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?
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.
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: