Press a button and the mqtt subscribe a command to the HASS

Hi everyone, i need some help.

I have a nodemcu v0.9
1 x button to the nodemcu.
1 x Sonoff switch in my hass, that have the information:

state_topic: “/troom1/relay/state”
command_topic: “/troom1/gpio/12”
payload_on: “1”
payload_off: “0”

I want a code, so when i press the button that is attach to my nodemcu on: D1 and GND

I need to send payload 1 for turning my sonoff on, and send payload 0 for turning my sonoff off.

These configuration is close:

Can someone help me?

Greetings DK.

see my topic

i solve my problem with espeasy

The problem, i dont want to use the sonoff.
I have sonoff in my house.
But i want a esp8266 nodemcu module and a button to trigger mqtt commands to my sonoff.
Not vise versa.
I want the code for the trigger mqtt commands when i press the button.

my code make exactly what do you want.
i have a button, and i can controle anything what i want.
see the post.

I dont see a proper tutorial for this, could you create one please?
What code / commands i should put on my esp8266

Greeetings DK.

Hi Dk,

You can do it without HA or MQTT protocol… the Esp firmware have the posibility to send or activate another Esp pins… its very easy or simple.

Antoni.

I created the mqtt button as i want that thing inplemented.

Thansk.

1 Like