Read MQQT command and execute code only once

I have set up a MQQT broker connected to Openhab to control my car.
Openhab sends commands to a ESP8266 and turn relays on/off. The relays I have figured out. Since MQQT send a "ON" / "OFF" i can in the loop check what state it is and turn relays on and off.

My problem now is that I have a heater that I have connected via optocouplers to mimic the buttons. A singe press turns the heater on and a long press turns the heater off. I cant get my head around on how to solve this since the loop runs over and over. I only want to "press" the button (write high) for about 1 sec and then not doing it again.

So something like:

If MQQT messege is ON

"digitalWrite(Heater_ON_OFF, HIGH);
delay(4000);
digitalWrite(Heater_ON_OFF, LOW);"

Any ideas on where to start?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.