Yurik72 / ESPHap

ESP32/ESP8266 Arduino library for native Apple Homekit Accessory Protocol (HAP)
MIT License
264 stars 60 forks source link

Siri not recognizing multiple accessories #121

Closed matrixall closed 2 years ago

matrixall commented 2 years ago

I have set up 3 separate accessories on 3 different ESP-12F in my kitchen for the lights which I can command Siri to trigger each independently with no problems.

However, in the living room where I have set up 3 accessories (light bulb) on a single ESP-12F each named (1st, 2nd, 3rd). if Ask Siri, How many lights are there in the living room? she responds with only one light. Moreover, when I command her to switch on for example first light in living room, it says there is no such light in the living room! I tried with single tile and separate tiles as well with no success. When it comes to the app, it is find I can see all accessories and trigger them successfully..

I'm not really sure if this is a homekit , ESPHap or my coding issues: Here is how I added the extra accessories based on my understanding of the library:

// Accessory Information #define ACCESSORY_NAME ("LB") #define ACCESSORY_SN ("4444") #define ACCESSORY_MANUFACTURER ("B4IT") #define ACCESSORY_MODEL ("TRIO") #define ACCESSORY_FW ("1.0")

// GPIO Pins const int TPIN1 = 5; const int TPIN2 = 14; const int TPIN3 = 13;

homekit_service_t* hapservice1={0}; homekit_service_t* hapservice2={0}; homekit_service_t* hapservice3={0}; homekit_characteristic_t *ch;

homekit_characteristic_t * ch1; homekit_characteristic_t * ch2; homekit_characteristic_t * ch3;

hap_initbase_accessory_service(ACCESSORY_NAME,ACCESSORY_MANUFACTURER,ACCESSORY_SN,ACCESSORY_MODEL,ACCESSORY_FW);

hapservice1= hap_add_lightbulb_service("1st",led_callback,(void*)&TPIN1); hapservice2= hap_add_lightbulb_service("2nd",led_callback,(void*)&TPIN2); hapservice3= hap_add_lightbulb_service("3rd",led_callback,(void*)&TPIN3);

hap_setinitial_characteristic_bool_value(hapservice1,HOMEKIT_CHARACTERISTIC_ON,false); hap_setinitial_characteristic_bool_value(hapservice2,HOMEKIT_CHARACTERISTIC_ON,false); hap_setinitial_characteristic_bool_value(hapservice3,HOMEKIT_CHARACTERISTIC_ON,false);

ch1= homekit_service_characteristic_by_type(hapservice1, HOMEKIT_CHARACTERISTIC_ON); ch2= homekit_service_characteristic_by_type(hapservice2, HOMEKIT_CHARACTERISTIC_ON); ch3= homekit_service_characteristic_by_type(hapservice3, HOMEKIT_CHARACTERISTIC_ON);

void led_callback(homekit_characteristic_t *ch, homekit_value_t value, void *context) { if ( ch == ch1 ) { set_led(TPIN1, ch1->value.bool_value); } if ( ch == ch2 ) { set_led(TPIN2, ch2->value.bool_value); } if ( ch == ch3 ) { set_led(TPIN3, ch3->value.bool_value); } }

void set_led(int GPIOPin, bool val){ digitalWrite(GPIOPin, val?HIGH:LOW); }

Yurik72 commented 2 years ago

Hi the question is about accessories and services and their differences. For Apple and Siri each new device is accessory. Each accessory can have different services. For instance in your example you have created one device (lightbulb) with 3 services. Like one physical lamp contains 3 separate leds,..

To achieve result which you want you have to add second and third lamp as accessory. I have mentioned this is readme To simplify you need to call: hap_add_lightbulb_service_as_accessory instead of hap_add_lightbulb_service for the second and third device

hapservice2= hap_add_lightbulb_service_as_accessory ("2nd",led_callback,(void)&TPIN2); hapservice3= hap_add_lightbulb_service_as_accessory ("3rd",led_callback,(void)&TPIN3);

matrixall commented 2 years ago

hapservice2= hap_add_lightbulb_service_as_accessory ("2nd",led_callback,(void)&TPIN2); hapservice3= hap_add_lightbulb_service_as_accessory ("3rd",led_callback,(void)&TPIN3);

Correction:

hapservice2= hap_add_lightbulb_service_as_accessory (homekit_accessory_category_lightbulb,"2nd",led_callback,(void)&TPIN2); hapservice3= hap_add_lightbulb_service_as_accessory (homekit_accessory_category_lightbulb,"3rd",led_callback,(void)&TPIN3);