$6 MQTT Push Button to Control Sonoff Devices

Hey everyone! I’m excited to share something that I’ve been working on for a while, an MQTT Push Button! Please feel free to ask questions and leave all comments. I’m open to any suggestions and criticisms. Looking forward to seeing what you guys think! Thanks all!

Nice.

Can I point out that the volume seems to decrease part way through?

Also is there an advantage to this over Tasmota?

Thanks, I’ll work out the audio in the future.

As far as I know, you can’t do a long press and well as a short press with tasmota. Also, I don’t know if tasmota can just publish a payload to a specific topic with a button press, I could be wrong.

You can have Tasmota publish a payload to a topic, though not necessarily an arbitrary topic that you can select. (Though maybe using a script, this might be possible?) You need to set a couple of “SetOption” values to get the correct behavior.

Just looking at my notes, I do these commands

led power 0
setoption31 1
ledstate 0
SerialLog 0
SwitchTopic NightLight1-Motion
buttontopic button
setoption1 off
setoption11 on

only some of which are directly related… This causes messages like

cmnd/NightLight1-Modtion/POWER2 ON

to be transmitted when one of the GPIO inputs (configured as a “button”) changes state. You don’t get to directly specify the “POWER2” bit of the topic; it’s derived from how the GPIO pin was configured.

It’s not as straightforward as I’d like; I’m thinking of replacing Tasmota with an ESPHome based implementation to have it be a bit more direct.

You can do (see GitHub - arendst/Tasmota: Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at)

  • Supports single-click, double-click and long press actions

Interpretation of the topic is up to HA I guess.

Anyway, not to criticise. I like especially the hardware implementation you have achieved, very tidy. I think I personally prefer this type of thing https://www.aliexpress.com/item/Angel-Eye-Metal-LED-illuminated-Momentary-16mm-Push-Button-Switch-Car-Dash-12V-red-blue-green/32697109472.html?spm=2114.search0104.3.45.593f7021rcBJqw&ws_ab_test=searchweb0_0,searchweb201602_8_10065_10068_10547_319_10059_10884_317_10548_10887_10696_321_322_10084_453_10083_454_10103_10618_10307_537_536_10902,searchweb201603_57,ppcSwitch_0&algo_expid=e6c1f203-97f3-4901-943b-15879c8f1e60-8&algo_pvid=e6c1f203-97f3-4901-943b-15879c8f1e60

But it is very much a matter of taste!

1 Like

I’m not sure when tasmota became as popular as it is now, but I initially created 2 of these devices in mid-2017, it’s only now that I decided to publish it. I wasn’t aware if tasmota back then. I am converting my sonoff devices to tasmota now however :slight_smile:. Thanks!

It would be nice to get a button that lights up when it’s off, so that you can see it at night. It would then turn on when the light is off.