Arduino-HomeKit-ESP8266 icon indicating copy to clipboard operation
Arduino-HomeKit-ESP8266 copied to clipboard

How to achieve a button that switches back to OFF automatically

Open jenspr opened this issue 3 years ago • 1 comments

Hi there, I do not know where to ask.

I successfully build this with a NodeMCU. (Switch)

What I want to achieve is a button I trigger from Homekit.. And I want it to return automatically after lets say 3sec to OFF.

I thought to do some automation on the HomeKit side. But I would prefer to have it in 'hardware' (=in the Arduino code). Where do I infuse what to accomplish this? Any help appreciated. I am new to this.

jenspr avatar Jul 01 '21 08:07 jenspr

Seems like a timer in the main loop would do. Some pseudo code;

uint32_t timer = 0;
if millis() > timer {
  timer = millis() + (3 * 1000);  //3 seconds from now
  digitalWrite(pin, setting) //set it to whatever value
  switch.value.bool = setting //make the state consistent
  homekit_notify_accessory_change (setting) //notify for any changes.
}

dsbaha avatar Jul 20 '21 16:07 dsbaha