Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add multiple lights? #29

Open
zolakt opened this issue Dec 5, 2024 · 3 comments
Open

How to add multiple lights? #29

zolakt opened this issue Dec 5, 2024 · 3 comments

Comments

@zolakt
Copy link

zolakt commented Dec 5, 2024

Sorry if this is a stupid question, but I can't figure it out. I see different examples.
I have 3 lights controlled by the Zhi Jia app. What is the proper way to configure that?

I tried adding 3 of everything (controller, light, button), and I can pair all the devices.
But whatever I change on any of them, it changes on all of them.

Here is my current config:

ble_adv_controller:
  - id: living_room_light_controller
    encoding: zhijia
  - id: kitchen_light_controller
    encoding: zhijia
  - id: bar_light_controller
    encoding: zhijia

light:
  - platform: ble_adv_controller
    ble_adv_controller_id: living_room_light_controller
    name: Living Room Light Controller
  - platform: ble_adv_controller
    ble_adv_controller_id: kitchen_light_controller
    name: Kitchen Light Controller
  - platform: ble_adv_controller
    ble_adv_controller_id: bar_light_controller
    name: Bar Light Controller

button:
  - platform: ble_adv_controller
    ble_adv_controller_id: living_room_light_controller
    name: Living Room Light Controller Pair
    cmd: pair
  - platform: ble_adv_controller
    ble_adv_controller_id: kitchen_light_controller
    name: Kitchen Light Controller Pair
    cmd: pair
  - platform: ble_adv_controller
    ble_adv_controller_id: bar_light_controller
    name: Bar Light Controller Pair
    cmd: pair

It seems like it's all the same controller. I tried unpairing everything through the service command. It all behaves like the same controller. I can unpair any light with any controllers unpair action.

I've also tried adding index to each controller, but it didn't help.

Do I need to set a different force_id to each controller? How do I find these?

I tried sniffing the force_ids, but I'm finding that confusing as well. I see multiple messages when I turn on/off individual lights from the ZhiJia app.

When I just toggle the 1st (living room light), I get this:

ble_adv_controller:
  - id: my_controller_id
    encoding: zhijia
    variant: v2
    forced_id: 0xE8E075
    index: 1

Then I turn that light off (completely cut off power via a relay), and just toggle the 2nd light (bar light). I get this:

ble_adv_controller:
  - id: my_controller_id
    encoding: zhijia
    variant: v0
    forced_id: 0xE8E0
    index: 2
...
ble_adv_controller:
  - id: my_controller_id
    encoding: zhijia
    variant: v1
    forced_id: 0xE8E075
    index: 2

Then same with the last light (kitchen light). Cut off power to the previous 2, and just toggle the 3rd one. I get this:

ble_adv_controller:
  - id: my_controller_id
    encoding: zhijia
    variant: v0
    forced_id: 0xE8E0
    index: 3
...
ble_adv_controller:
  - id: my_controller_id
    encoding: zhijia
    variant: v1
    forced_id: 0xE8E075
    index: 3

I don't know, but for me this makes no sense. Overlapping ids for different indexes...

@aronsky
Copy link
Owner

aronsky commented Dec 6, 2024

When capturing data from the ZhiJia app, it shouldn't matter whether the actual light is powered or not, the app simply broadcasts the messages. So try to keep all the lights on, and toggle each of them via the app to verify that they toggle correctly - while sniffing the data coming through the app.

If that works, I think that setting the forced_id value that you see broadcast for each light, combined with the index, for each controller should fix the issue. So your controllers should look something like:

ble_adv_controller:
  - id: living_room_light_controller
    encoding: zhijia
    variant: v2
    forced_id: 0xE8E075
    index: 1
  - id: kitchen_light_controller
    encoding: zhijia
    variant: v2
    forced_id: 0xE8E075
    index: 2
  - id: bar_light_controller
    encoding: zhijia
    variant: v2
    forced_id: 0xE8E075
    index: 3

If that doesn't work, try changing the v2 to v1/v0 for each light that doesn't function (for v0, change the forced_id to 0xE8E0). And if it works but the lights toggled don't match your expectations, just play around with the indices.

@zolakt
Copy link
Author

zolakt commented Dec 6, 2024

I'll try to sniff again, but that is pretty much what I have now. But still each controller affects all 3 lights.

ble_adv_controller:
  - id: living_room_light_controller
    encoding: zhijia
    forced_id: 0xE8E075
    index: 1
    show_config: true
  - id: bar_light_controller
    encoding: zhijia
    forced_id: 0xE8E075
    index: 2
    show_config: true
    reversed: true
  - id: kitchen_light_controller
    encoding: zhijia
    forced_id: 0xE8E075
    index: 3
    show_config: true

The issue is not if they work. All of them pair and work. But they aren't controlled separately. Every controller does the same thing, and affects all 3 light. I've even tried pairing/unpairing. It all seems to be the same thing. e.g. I pair the living room light with it's pair button, but then I unpair it by calling the kitchen controller unpair method.

@aronsky
Copy link
Owner

aronsky commented Dec 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants