Openhab - MQTT - Hardware Button // ITEM problem

It’s much simpler to think about if you have the concept in the ESP device that a single topic published on by the ESP represents the state of the relay. If you have a wall switch wired to GPIO12, that should not have anything to do with openHAB – it’s just another way to change the state of the relay. But when the relay changes state somehow, something should publish the new state to the topic openHAB is listening to. Your existing > clauses in the MQTT binding string can stay as is since they’re working, but you will add new < clauses that subscribe to the single topic that represents the state of the relay.

Sorry for all this newbie questions.
Yes i think i have very well understands you so far about the state of relay and ON/OFF of the relay. But now If i want to wired my manual toggle switch to ESP and want to control the same relay how can i achieved? I can subscribed to topic which ESP will publish on state changed of toggle switch but how can i link them together in OpenHAB?
Thank you again and sorry for all this questions

That seems like a question about ESP programming that doesn’t involve openHAB, or am I missing something? Do you want to use an MQTT broker as an intermediary between a switch and a relay attached to the same physical device? And even if you did, what is the value of openHAB knowing the state of the physical switch position, when you are interested in the state of the relay? I’m afraid I just don’t understand what your overall objective is.

Do you want to use an MQTT broker as an intermediary between a switch and a relay attached to the same physical device?

Yes I am using MQTT broker to publish and subscribe

And even if you did, what is the value of openHAB knowing the state of the physical switch position, when you are interested in the state of the relay?

So If i am not home and if the light has been left ON i can turn off from OpenHAB App

I’m afraid I just don’t understand what your overall objective is.

My objective is simply to replace wall switch with ESP8266 module programmed with ESPEasy which I can control from App as well as manually old fashioned way.

So far I have achieved

  • Can control GPIO from OpenHAB app on ESP
  • Can publish message from ESP about the state of the toggle switch (wall switch) with 1 being ON and 0 being OFF with following message
    bedroom/Bed_SW1/Switch1/1 or bedroom/Bed_SW1/Switch1/0
    Sorry for the confusion and really appreciate your help.

The key question is: what MQTT topic can openHAB subscribe to in order to get the current, accurate state of the relay? openHAB doesn’t care about your physical wall switch or what it can do; it only cares about the on/off state of the relay.

Once you can answer the question above, replace wall/gpio/12 below with the real topic, and the contents of relayState.map with what the messages are.

your.items:

Switch Bed_SW1 "Candle Warmer" <candle> (BR_Master) {mqtt="<[mqttserver:wall/gpio/12:state:MAP(relayState.map)],>[mqttserver:bedroom/gpio/14:command:ON:1],>[mqttserver:bedroom/gpio/14:command:OFF:0]"}

relayState.map:

1.00=ON
0.00=OFF
1 Like

That is a big help. I will try and will post the results.
Once again thanks a lot for your help

1 Like

Thanks again,
I tried what you said in last post and here is my setting

Switch Bed_SW1 “Chandelier” (BR_Master) {mqtt=“<[mqttserver:bed_sw1/chandelier/Switch:state:MAP(switch.map)],>[mqttserver:bed_sw1/gpio/15:command:ON:1],>[mqttserver:bed_sw1/gpio/15:command:OFF:0]”}

Progress so far:
Now the manual switch and OpenHAB is synchronized however i can not turn the light ON/OFF means no effect on the led i can see on MQTT.FX the message being sent as follow
Manual Switch
bed_sw1/chandelier/Switch with 0 and 1 corresponding to the switch position
Switch from APP
bed_sw1/gpio/15 with 0 and 1 corresponding to toggle
tried three different led but no effect. Measured voltage between GPIO15 and GND in both position voltage measure was .48v.

switch.map

1=ON
0=OFF

Any suggestion!!!
Thank you

@watou

Got it working. I love you guys…
Here is my items line if somebody need it for future reference

Switch Bed_SW1 “Chandelier” (BR_Master) {mqtt=“>[mqttserver:bed_sw1/gpio/14:command:ON:1],>[mqttserver:bed_sw1/gpio/14:command:OFF:0],<[mqttserver:bed_sw1/chandelier/Switch:command:MAP(switch.map)])”}

now i can control LED from either from toggle switch which is connected pulldown at GPIO12 and from OpenHAB app also and LED is connected to GPIO14.
State is also synchronized in Openhab except one small problem which i don’t really care. The problem is

If i have LED on from toggle switch and turn off LED from APP, suppose i used the toggle switch next to turn since toggle was already in ON position i have to flip switch off and ON to get the led on. As i said i don’t care as I will be physically present in the room to turn the LED anyways.

Once again thank you so much let you guys know if i run into any further problem.
Andy

1 Like

And THAT was the reason I had to setup my above posted proxy/rule combination …
But maybe there is also a “native” mqtt solution for that.

Thanks sihui

This example helped me too.

BR

SQ

Hi, I was just wondering if someone could draw a quick wiring diagram, I’m trying to do a very simlar thing I think.

I was going to use an Arduino with a relay switch and wire it up like a 2 way switch. Then use a current sensor to identify when the light is on or off.

But I think this seems like a better way.

From what part do you mean? A switch connected to an esp8266?
For testing I use a short wire on a breadboard and connect it between the chosen pin and ground …

Hi, Thanks for the reply.

Basically I don’t want the wall switch to be wired into the esp8266. So I want to run a parallel wire and change the wall switch to a 3-way, then the esp8266 would be the 2nd switch in the curcuit like this. (I do understand this might be a little harder, but my wife wont be happy if the esp stops working and she cant use the lights, this is my fail safe to ensure the wall switch always works)

But If I did this I would need to know when the physical wall switch was pressed, I thought maybe i could use a current sensor that would change the status of the esp8266 controlled relay.

Hope this makes sense. Regards Campbell

Absolutely, if the controller fails the physical switch must be in operating condition so that we can turn the equipment on and off, but I guess the current sensor gives very less voltage for low current consuming equipment like a led bulb, so I think a voltage sensor is a better option.
We can take the feedback of voltage sensor in esp and accordingly send the state to openhab and change it’s state in GUI.
Can anyone help to do so with http binding?