So, I've an automation for an IKEA smart light. But I'm not satisfied of an experience this setup provides. There are uncomfortable delays between the key presses and the reaction of light. It's obvious that the signal passes the whole loop, from the remote control, to the raspberry pi, where is processed by homeassistant, and just then back to the light device.  All this round trip takes something around the 1 - 1.5 seconds to between actual button press and the light turned on. This is an awful experience after using directly paired remote and led driver.

In a zigbee2mqtt documentation I've found out that there is binding feature - which is doing exactly what I want - directly pairs the remote control and led driver. So, the paired devices work super fast, super smooth and still are connected to the home assistant. That means I can trigger other automation based on remote control button clicks, or turn on and off the lights on a led driver.

The big picture

There is a group concept in zigbee networking system. You can bind a several remote controls and light devices to the same group, and each device would react on each command from a remote control. This is like many-to-many relation or Cartesian Product of control.

This is a bit complicated in theory, but practically is much easier. You just need to find the default group bounded to your remote control, and bind other light devices to this group.

At first, we have to find the GROUP number of our remote. The recommended way is to see the log print of zigbee2mqtt when the device is used on log level debug.

Then we have to add our led driver to this group and viola. Adding is realized by a sending an mqtt event to a bridge. And that it's for us. Bridge can speak the device specific protocol and will send the necessary binding data via raw zigbee to the devices.

Prerequirements

You need to have all your devices paired with zigbee2mqtt.

I. Getting the group ID.

  1. Change the log level of zigbee2mqtt
/opt/zigbee2mqtt/data/configuration.yaml
...
advanced:
  log_level: debug

2. Restartzigbe2mqtt service

sudo systemctl restart zigbee2mqtt.service 

3. Start monitoring logs

sudo journalctl -u zigbee2mqtt.service -f

4. Start clicking on the remote control

5. Observer the logs

Mar 19 19:39:19 raspberrypi npm[1464]: zigbee2mqtt:info  2020-03-19 19:39:19: MQTT publish: topic 'zigbee2mqtt/ikea_pad_1', payload '{"linkquality":34,"battery":87,"action":""}'
Mar 19 19:39:23 raspberrypi npm[1464]: zigbee2mqtt:debug 2020-03-19 19:39:23: Received Zigbee message from 'ikea_pad_1', type 'commandToggle', cluster 'genOnOff', data '{}' from endpoint 1 with groupID 26315

II. Register the group at zigbee2mqtt

The group is added to the same configuration.yml as log level.

/opt/zigbee2mqtt/data/configuration.yaml

Add the section groups if not exists and add the group with founded ID.

...
advanced:
  log_level: debug
groups:
  '26315':
    friendly_name: the_group_name
    retain: false
    transition: 2
    optimistic: true

Now restart the service again

sudo systemctl restart zigbe2mqtt.service

III. Add the led driver to the group

Now we have to say zigbee2mqqt that we want to add the light device into a group of the switch. So we need to send a mqtt message to a service somehow. The most convenient way I found was to use the homeassistant web interface. Maybe there are some good mqtt console clients but I had no time to investigate them.

Go to the homeassistant sidebar -> Developer Tools -> MQTT tab. And publish a packet to a topic:

zigbee2mqtt/bridge/group/the_group_name/add

With a payload of friendly name of light device:

On a logs of zigbee2mqtt.service it should print that the device has been Adding.

Mar 19 19:49:16 raspberrypi npm[1720]: zigbee2mqtt:debug 2020-03-19 19:49:16: Received MQTT message on 'zigbee2mqtt/bridge/group/besta/add' with data 'ikea_led_driver_1'
Mar 19 19:49:16 raspberrypi npm[1720]: zigbee2mqtt:info  2020-03-19 19:49:16: Adding 'ikea_led_driver_1' to 'besta'

From now the light device directly responses to a button signals, and still reacts on a home assistant calls.

Happy Automating ;)