[SOLVED] Esp Easy toggle/ OH2 switch question

Rpi 2B+ OH 2.4 ESP8266 running ESPEasy Mega and a pushbutton. The Basic UI “switch” is actually controlling a relay via the office ESP board running Tasmota.

I have set up one ESP for my Office Comfort readings, temp, humidity, pressure and a relay to control an office light using Tasmota. All working well.

As a test using another ESP running ESP Easy Mega and a push button, I have read through a ton of docs to get the push button to toggle ON with one push and OFF with a second push. I have also set up a binding in OH2 so that this push button will toggle the ON/OFF switch on the Basic UI.

So everything is working great. What I would like to do is be able to turn ON/OFF the Basic UI switch (the relay) with either switch. What I mean is, If I use the push button to turn ON the switch I want to be able to use the UI switch to turn it OFF and vise versa.

Currently, I can do this BUT the push button rule automatically turns it back on. So what I’m thinking is I somehow have to send something back to the ESP to tell it to toggle IT’S rule to ON/OFF or something like that.

The end result of this experiment is to replace the wall switch with a push button that will control the relay to turn the lights ON/OFF with either the push button OR openHAB and get comfort readings all from one board. I’m also learning how to make cheap controllers that can be added to the OH repertoire and program them into the system.

Any ideas or suggestions are welcome.

Once I get this working, I’ll try to move the push button over to the Tasmota or move the sensors and relay over to the ESP Easy to make it a compact unit. Then I will try and write this all up with screenshots on how I did it. It should be a fun project!!

Thanks for your ideas

John Frankforther

soory did not have time to read of all of your post , see if the below helps
i also got stuck on how to toggle an ESP switch and moved to tasmota , where its easier to understand

Gad_Ofir
I have messed around with the Tasmota buttons commands. The main problem I had is getting it to send commands to OH. Am I switching the switch or the relay or what?? From what I can tell, in MHO, it is written for the SONOFF devices which the basic version has 1 switch and a relay. I can see it work in the Tasmota Consol screen but could never get it to send commands to OH MQTT. I know there are settings to change the button configurations and whether or not to send MQTT commands. With ESPEasy, set up the switch and tell it where the MQTT broker is and bam it 's done.

John

OK New update. More reading - pushbutton set up and working on the Office ESP board so now I have

  • Pushbutton to control the relay.
  • Basic UI switch to also control the relay
  • Relay to control the lights via pushbutton or Basic UI switch
  • BME280 to read Temperature, Humidity, and Pressure.

So what I think I need to do now is make a rule to say,
if the relay is off and I get ON from pushbutton or ON from the UI switch, turn the relay ON.

If the relay is ON and I get OFF from the pushbutton or OFF from UI switch, turn the relay OFF.

I still need to work on the pushbutton ON/OFF toggle.

John Frankforther

yes on Tasmota its a little different… i am also not sure how exctly it works but i got it working try to do the following

  1. on console set ",“ButtonTopic”:"What ever you want “,”
    this will set the MQTT msg for the button ,

  2. and switchmode 1 1
    this should disconnect the butten from relay

  3. then you can use MQTT to set rules and not envolve the relay switch
    but please double check on github , i got this from one of my POWs that i am using as MQTT button

  4. listen to cmnd/what ever you put on step 1/Off-Topic
    exmaple: cmnd/XXXX/#

  5. i think a double press will turn the realy on and off , and long press will send HOLD
    a single press will send TOGGLE

i just hope i got what you want to do :slight_smile:

PS: a small advice … to work with MQTT use node red
it has great debugging tools and it works with OH like a charm

Gad_Ofir
Ok, I’m not using a sonoff board. I have a Wemos board running the Tasmota software.

I think I’m getting close. I can toggle the relay on and off using the Basic UI switch.

Pressing the button down toggles the relay but when I release the button it toggles again.

So I need to figure out how to make the button only toggle when it is pressed down and do nothing when released. More reading needed!!

**** UPDATE
If I set SwitchMode1 to SwitchMode1 4, this toggles the relay ON or OFF depending on the original state of the relay. This also shows in the BasicUI ON or OFF to match the state the relay is in. I can ALSO toggle the relay with the UI switch.

*** So everything is working just like I wanted. I can turn the office light ON/OFF with either the pushbutton OR the UI switch. YEA !!

So I have met all my requirements as I originally stated.

  • Control multiple environment items with a Wemos ESP8266 running Tasmota software.
  • Control office light with either a wall mounted pushbutton or the Basic UI switch AND
  • Read and display the Office temperature, humidity, and pressure in real time.

John

The button is a momentary button, and you want it to work similar to a toggle, maybe something like this will work? Create a contact item and use it to control the switch when it’s state is changed.


rule "Item_Test"
when
    Item Item1_Contact changed to ON
then
    Item1_Switch.sendCommand(if(Item1_Switch.state == ON) ON else OFF)
end

Thanks H102

I found the setting in the Tasmota software to make the push button into a toggle switch. No rules needed.

John

cool yes , this switchmodes are tricky , but its much better than rules on the Hub or on espeasy rules
if you use espeasy rules only “kick in” after full boot
where tasmota , its right on startup, this is the main reason why i abounded espeasy