Momentary Switch Using ESPeasy?

Hi All,
I need a momentary pulse from a GPIO pin on an ESP8266 running ESPeasy to set or reset my workshop alarm.
Using the line below in items file the GPIO toggles OK,could someone please edit my config below to show me how to implement autoupdate=“false” I tried this but either the GPIO did not change state or it went high and stayed like that.

Sitemap

Switch item=Wshop_Alarm label=“Workshop Alarm”

Items

Switch Wshop_Alarm {mqtt=">[mymosquitto:/Workshop_1/gpio/2:command:ON:1],>[mymosquitto:/Workshop_1/gpio/2:command:OFF:0]"}

Thanks

Dave

Try adding the state as input:

Switch Wshop_Alarm {mqtt=">[mymosquitto:/Workshop_1/gpio/2:command:ON:1],>[mymosquitto:/Workshop_1/gpio/2:command:OFF:0],<[mymosquitto:/Workshop_1/gpio/2:state:default]"}

Instead of trying to solve this in Openhab you could try setting up ESP easy to handle the momentary part.

I use this for my doorbell using MQTT… pressed once this makes the switch in OpenHAB turn ON and OFF again.

see screenshot for ESP easy setup:

The MQTT item setup in Openhab would look like this ( only looking at topic state!)

{mqtt="<[broker:/Home/Hall/Doorbell/Doorbell/state:state:MAP(mqtt.map)]"}

p.s. i use a map to transform the 0 and 1 coming from esp easy into on and off.

Thanks chaps for the reply …

Roel, I need to send the momentary pulse to the ESP,not the other way around.

Sihui, adding the state as an input results in the GPIO toggling but still latches,it does not return to the off state by itself.

Any other ideas please ?

Thanks

Dave

Did you play around with the “Switch Button Type”?
“Push Button Active Low” (or High depending on your setup) should do it …

A dirty trick would be to setup a rule like this:

rule "toggle workshop alarm"
when
Item Wshop_Alarm received update
then
if (Wshop_Alarm.state == ON) {
sendCommand(Wshop_Alarm, OFF
}
end

Thanks snoekieboe,your rule trick works exactly as needed.
1 last thing please,can a delay be added to the rule so that the GPIO stays high for a second when triggered before going low again ?
The pulse is a bit short with no delay.
Thanks again you chaps for the help.
Davve

Just add

Thread::sleep(300) //time is in millis

to your rule.

rule "toggle workshop alarm"
when
Item Wshop_Alarm received update
then
if (Wshop_Alarm.state == ON) {
Thread::sleep(300)
sendCommand(Wshop_Alarm, OFF)
}
end

Would be your optimized result

1 Like