[ Zigbee ST Edge ] device.emit_event_for_endpoint only pushing to endpoint 1

Hey, @nayelyz @andresg

I hope you’re doing great = ]

I wanted to report an issue with the device.emit_event_for_endpoint resource, because it seems that it is only pointing capability updates to the main component (in my case, endpoint 1) regardless of the endpoint number passed.

This is the piece of code calling that API:

local function _send_device_event(endpoint, device, event, state_change)
  event.state_change = state_change

  return pcall(
    device.emit_event_for_endpoint,
    device,
    endpoint,
    event)
end


local function send_button_capability_setup(device, buttons_number, button_events)
    assert(_send_device_event(
      1,  -- "main" profile component
      device,
      button.numberOfButtons(buttons_number)))

    -- configure supported values for
    -- each profile component
    for ep=1, buttons_number do
      print(ep)   <<< This is printed in following snippet
      assert(_send_device_event(
        ep,
        device,
        button.supportedButtonValues(button_events)))
    end
end

And the logs look like this:

2022-02-12T00:23:03.132787408+00:00 INFO button-battery-v1.3.0
<ZigbeeDevice: ... [0x581E] (Scene Switch)> emitting event:
{ "attribute_id": "numberOfButtons",
  "component_id": "main",
  "capability_id": "button",
  "state":{"value":3}}


2022-02-12T00:23:03.150639741+00:00 PRINT button-battery-v1.3.0  1  << endpoint ref
2022-02-12T00:23:03.160293074+00:00 INFO button-battery-v1.3.0
<ZigbeeDevice: ... [0x581E] (Scene Switch)> emitting event:
{ "attribute_id": "supportedButtonValues",
  "component_id": "main",
  "capability_id": "button",
  "state":{"value":["pushed","double","held"]}}


2022-02-12T00:23:03.177856074+00:00 PRINT button-battery-v1.3.0  2  << endpoint ref
2022-02-12T00:23:03.184973741+00:00 INFO button-battery-v1.3.0
<ZigbeeDevice: ... [0x581E] (Scene Switch)> emitting event:
{ "attribute_id": "supportedButtonValues",
  "component_id": "main",
  "capability_id": "button",
  "state":{"value":["pushed","double","held"]}}

2022-02-12T00:23:03.203620741+00:00 PRINT button-battery-v1.3.0  3  << endpoint ref
2022-02-12T00:23:03.211192408+00:00 INFO button-battery-v1.3.0
<ZigbeeDevice: ... [0x581E] (Scene Switch)> emitting event:
{ "attribute_id": "supportedButtonValues",
  "component_id": "main",
  "capability_id": "button",
  "state":{"value":["pushed","double","held"]}}

Also, I think it is important to notice that the endpoint reference is being defined by device:component_count().

For more details, you can review the code: erickv-edge-drivers/zigbee/button-battery at develop · erickvneri/erickv-edge-drivers · GitHub

Hi, @erickv. It’s great hearing from you.

I see the function device.emit_event_for_endpoint depends on the configuration of set_endpoint_to_component_fn, this part was successful in your device?

1 Like

Hey, @nayelyz

I think this got solved during the weekend (maybe?) because now components are being referred as expected, check this logs:

PRINT button-battery-v1.3.0  endpoint:      0
PRINT button-battery-v1.3.0  matches with:  battery
PRINT button-battery-v1.3.0  endpoint:      1
PRINT button-battery-v1.3.0  matches with:  main
PRINT button-battery-v1.3.0  endpoint:      2
PRINT button-battery-v1.3.0  matches with:  button2
PRINT button-battery-v1.3.0  endpoint:      3
PRINT button-battery-v1.3.0  matches with:  button3
PRINT button-battery-v1.3.0  endpoint:      4
PRINT button-battery-v1.3.0  matches with:  button4
INFO button-battery-v1.3.0  <ZigbeeDevice:
[0x581E] (Scene Switch 《cocina》)> emitting event:
{"attribute_id":"numberOfButtons","state":{"value":3},"capability_id":"button","component_id":"main"}
INFO button-battery-v1.3.0  <ZigbeeDevice:
[0x581E] (Scene Switch 《cocina》)> emitting event:
{"attribute_id":"supportedButtonValues","state":{"value":["pushed","double","held"]},"capability_id":"button","component_id":"main"}
INFO button-battery-v1.3.0  <ZigbeeDevice:
[0x581E] (Scene Switch 《cocina》)> emitting event:
{"attribute_id":"supportedButtonValues","state":{"value":["pushed","double","held"]},"capability_id":"button","component_id":"button2"}
INFO button-battery-v1.3.0  <ZigbeeDevice:
[0x581E] (Scene Switch 《cocina》)> emitting event:
{"attribute_id":"supportedButtonValues","state":{"value":["pushed","double","held"]},"capability_id":"button","component_id":"button3"}

And this is the code I added to validate it:

local function init(_, device)
  device:set_component_to_endpoint_fn(_component_to_endpoint)
  device:set_endpoint_to_component_fn(_endpoint_to_component)

  for ep=0, device:component_count() do
    -- [[
    --  calling get_component_id_for_endpoint
    --  to verify relationship ep / component
    --]]
    print('endpoint: ', ep)
    print('matches with:', device:get_component_id_for_endpoint(ep))
  end

  send_button_capability_setup(
    device,
    device:component_count() - 1,  -- exclude "battery" component
    { "pushed", "double", "held" })
end
1 Like

That was weird, anyway, thank you for letting me know.
In case you see it again, I’m only “a tag away” :wink:

2 Likes