I am new to Openhab. I connected NodeMCU with Openhab using MQTT and its working. What I want now is to update switch when the status changes. I wrote an example code like this
if(payload[0] == '1'){
digitalWrite(relay1, LOW);
client.publish("room1/light1confirm", "ON");
delay(5000);
client.publish("room1/light1confirm", "OFF");
}
Item coded as
Switch room1_light1 "Light 1[%s]" <light> {mqtt=">[mymqtt:room1/light1:command:*:MAP(onoff.map)],<[mymqtt:room1/light1confirm:state:*:MAP(onoff.map)]"}
So when the switch room1_light1 is toggled to on it should ON and after a delay of 5sec when the OFF status is published on room1/light1confirm the switch should toggle back to off position.
I am getting the message on my MQTT console, but the switch is not toggling back to OFF