Mixiaoxiao / Arduino-HomeKit-ESP8266

Native Apple HomeKit accessory implementation for the ESP8266 Arduino core.
MIT License
1.52k stars 277 forks source link

How can I add a physical button to switch example? #82

Open greg21greg opened 3 years ago

Mixiaoxiao commented 3 years ago

Ask Google.

greg21greg commented 3 years ago

I tried that already :( I was hoping someone could help me out here.

JGConcepcion commented 3 years ago

Were you able to make it work? I'm trying to make it work

pratik019 commented 3 years ago

I tried it, within switch example there is 3 lines of commented code to submit led pin status to ios app. from line 77 to 79.

but when i did that system started going into reset mode continiously exception(0), i would love help with it.

JGConcepcion commented 3 years ago

I was able to make it work already but it involved the use of another library which is the ESPbutton. I added this piece of code (See attached image) into the my_homekit_setup() and I got no error or whatsoever. working

yepkevin612 commented 3 years ago

@JGConcepcion con you share your code?

Varogkorn commented 3 years ago

I used Acebutton Libray to work with Push button Switch with INPUT_PULLUP

Edit program in Example02_Switch.ino

yepkevin612 commented 3 years ago

@Varogkorn thank you so much,i still cannot turn off ,when i hold the button there is off,when i released my hand the switch continous turn on.

alexxxpol commented 3 years ago

Hi! void handleEvent(AceButton / button /, uint8_t eventType, uint8_t / buttonState */) { //Serial.println('lock_state'); switch (eventType) { case AceButton::kEventPressed: if(lock_state==1){ cha_switch_on.value.bool_value = true; bool on = cha_switch_on.value.bool_value; //Serial.println("LED:ON(Force)"); digitalWrite(PIN_SWITCH, HIGH); homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value); lock_state = 0; } else { cha_switch_on.value.bool_value = false; bool on = !cha_switch_on.value.bool_value; //Serial.println("LED:OFF(Force)"); digitalWrite(PIN_SWITCH, LOW); homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value); lock_state = 1; }
break; case AceButton::kEventReleased: break; } }

yepkevin612 commented 3 years ago

@alexxxpol Thank you , it work nice.

alexandrerochasalles commented 3 years ago

How to change the HIGH to LOW position on home app?? I mean, even the exemple works inverse for me, it is on when off in home app, and off when it's on in my home app.

I'm using a Wemos d1 mini v3

david19610 commented 3 years ago

Hello,

Pleas in function swich_on_set(), change the digitalWrite(2, switch_1_power) to digitalWrite(2, !(switch_1_power)).

void switch_1_on_set(homekit_value_t value) { if (value.format != homekit_format_bool) { printf("Invalid on-value format: %d\n", value.format); return;} switch_1_power = value.bool_value; digitalWrite(2, switch_1_power); //led_update(); }

Pozdrawiam/Mit freundlichen Grüssen Dawid Rosak TEL. +48 609105069

Sent from my iPhone

On 9 Apr 2021, at 12:21, Alexandre Rocha @.***> wrote:

 How to change the HIGH to LOW position on home app?? I mean, even the exemple works inverse for me, it is on when off in home app, and off when it's on in my home app.

I'm using a Wemos d1 mini v3

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

alexandrerochasalles commented 3 years ago

Hello, Pleas in function swich_on_set(), change the digitalWrite(2, switch_1_power) to digitalWrite(2, !(switch_1_power)). void switch_1_on_set(homekit_value_t value) { if (value.format != homekit_format_bool) { printf("Invalid on-value format: %d\n", value.format); return;} switch_1_power = value.bool_value; digitalWrite(2, switch_1_power); //led_update(); } Pozdrawiam/Mit freundlichen Grüssen Dawid Rosak TEL. +48 609105069

I can't find the function that you are talking about. Can you please give me the full code? Because for the switch function I'm using as the switch example:

void cha_switch_on_setter(const homekit_value_t value) {
    bool on = value.bool_value;
    cha_switch_on.value.bool_value = on;    //sync the value
    LOG_D("Switch: %s", on ? "ON" : "OFF");
    digitalWrite(PIN_SWITCH, on ? LOW : HIGH);
}

void my_homekit_setup() {
    pinMode(PIN_SWITCH, OUTPUT);
    digitalWrite(PIN_SWITCH, HIGH);

    cha_switch_on.setter = cha_switch_on_setter;
    arduino_homekit_setup(&config);

}
david19610 commented 3 years ago

Hello,

you probably need to refresh status of the button, see the highlighted text in yellow

Pozdrawiam Dawid Rosak

pt., 9 kwi 2021 o 19:24 Alexandre Rocha @.***> napisał(a):

Hello, Pleas in function swich_on_set(), change the digitalWrite(2, switch_1_power) to digitalWrite(2, !(switch_1_power)). void switch_1_on_set(homekit_value_t value) { if (value.format != homekit_format_bool) { printf("Invalid on-value format: %d\n", value.format); return;} switch_1_power = value.bool_value; digitalWrite(2, switch_1_power); //led_update(); } Pozdrawiam/Mit freundlichen Grüssen Dawid Rosak TEL. +48 609105069 … <#m2188757451150947713>

I can't find the function that you are talking about. Can you please give me the full code? Because for the switch function I'm using as the switch example:

// access your HomeKit characteristics defined in my_accessory.c extern "C" homekit_server_config_t config; extern "C" homekit_characteristic_t cha_switch_on;

void cha_switch_on_setter(const homekit_value_t value) {

    bool on = value.bool_value;

cha_switch_on.value.bool_value = on; //sync the value

      //update current status of Button on Apple Home app

homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value);

LOG_D("Switch: %s", on ? "ON" : "OFF");

digitalWrite(PIN_SWITCH, on ? LOW : HIGH);

}

void my_homekit_setup() {

pinMode(PIN_SWITCH, OUTPUT);

digitalWrite(PIN_SWITCH, HIGH);

cha_switch_on.setter = cha_switch_on_setter;

arduino_homekit_setup(&config);

}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266/issues/82#issuecomment-816835729, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASNFVVJF5AP4ORLWQ54UYHDTH4Z5ZANCNFSM4TUIVHKQ .

alexandrerochasalles commented 3 years ago

@david19610 Thank you so much for the help!!

madmacks59 commented 2 years ago

Search for a project named "4 Relay & Switch" by Sachin Soni (aka techiesms). He has several projects that use physical switches and relays and I've got it working fine with HomeKit on a couple of different devices.

DenisMaldonadoC commented 1 year ago

The problem with the Techiesms project is that when you interact with the HomeKit App, you have to doble click the physical switch. I made the project a few months ago and I’m still dealing with that problem.