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

KeyError: 'idx' in HomeKit .../homekit/type_triggers.py", line 97, in async_trigger #95015

Closed
DanielHons opened this issue Jun 21, 2023 · 7 comments · Fixed by #95076
Closed
Assignees

Comments

@DanielHons
Copy link

DanielHons commented Jun 21, 2023

The problem

In my protocol of home assistant core, there are loads of such Key-Errors

The full log of the first minutes of my HA instance contains 170 of those errors. The full log is available here.

It seems that there is exactly one those Error for each telegram coming from the KNX bus/integration (See its config.

2023-06-21 21:19:50.640 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_triggers.py", line 97, in async_trigger
    idx = int(run_variables["trigger"]["idx"])
              ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'idx'

What version of Home Assistant Core has the issue?

core-2023.6.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

HomeKit

Link to integration documentation on our website

https://www.home-assistant.io/integrations/homekit/

Diagnostics information

config_entry-homekit-2048d7074690a063c2d5399508f7410b.json.txt

Example YAML snippet

# This automation does add five such errors to the protocol
alias: EG Sichtschutz bei Sonnenuntergang
description: Am Abend fahren im EG die Rolladen automatisch herunter
trigger:
  - platform: sun
    event: sunset
    offset: "-00:10:00"
condition: []
action:
  - service: scene.turn_on
    target:
      entity_id: scene.erdgeschoss_sichtschutz
    metadata: {}
mode: single

Anything in the logs that might be useful for us?

# I provided a log from the start of home assistant already, here is the log from the Automation above

2023-06-21 22:56:59.052 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.qhome_active_power_lower, old_state=<state sensor.qhome_active_power_lower=-6034; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=QHome Active Power Lower @ 2023-06-21T22:56:56.054256+02:00>, new_state=<state sensor.qhome_active_power_lower=-6039; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=QHome Active Power Lower @ 2023-06-21T22:56:59.052717+02:00>>
2023-06-21 22:56:59.071 DEBUG (MainThread) [homeassistant.components.homekit.type_triggers] Button triggered - {'trigger': {'destination': '2/0/1', 'destination_name': '', 'direction': 'Outgoing', 'payload': 1, 'source': '15.15.250', 'source_name': '', 'telegramtype': 'GroupValueWrite', 'timestamp': datetime.datetime(2023, 6, 21, 22, 56, 59, 71128, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin')), 'unit': None, 'value': None}}
2023-06-21 22:56:59.071 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_triggers.py", line 97, in async_trigger
    idx = int(run_variables["trigger"]["idx"])
              ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'idx'
2023-06-21 22:56:59.107 DEBUG (MainThread) [homeassistant.components.homekit.type_triggers] Button triggered - {'trigger': {'destination': '2/0/0', 'destination_name': '', 'direction': 'Outgoing', 'payload': 0, 'source': '15.15.250', 'source_name': '', 'telegramtype': 'GroupValueWrite', 'timestamp': datetime.datetime(2023, 6, 21, 22, 56, 59, 106913, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin')), 'unit': None, 'value': None}}
2023-06-21 22:56:59.108 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_triggers.py", line 97, in async_trigger
    idx = int(run_variables["trigger"]["idx"])
              ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'idx'
2023-06-21 22:56:59.149 DEBUG (MainThread) [homeassistant.components.homekit.type_triggers] Button triggered - {'trigger': {'destination': '2/1/4', 'destination_name': '', 'direction': 'Outgoing', 'payload': 1, 'source': '15.15.250', 'source_name': '', 'telegramtype': 'GroupValueWrite', 'timestamp': datetime.datetime(2023, 6, 21, 22, 56, 59, 149490, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin')), 'unit': None, 'value': None}}
2023-06-21 22:56:59.150 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_triggers.py", line 97, in async_trigger
    idx = int(run_variables["trigger"]["idx"])
              ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'idx'
2023-06-21 22:56:59.186 DEBUG (MainThread) [homeassistant.components.homekit.type_triggers] Button triggered - {'trigger': {'destination': '2/2/3', 'destination_name': '', 'direction': 'Outgoing', 'payload': 1, 'source': '15.15.250', 'source_name': '', 'telegramtype': 'GroupValueWrite', 'timestamp': datetime.datetime(2023, 6, 21, 22, 56, 59, 186479, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin')), 'unit': None, 'value': None}}
2023-06-21 22:56:59.187 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_triggers.py", line 97, in async_trigger
    idx = int(run_variables["trigger"]["idx"])
              ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'idx'
2023-06-21 22:56:59.224 DEBUG (MainThread) [homeassistant.components.homekit.type_triggers] Button triggered - {'trigger': {'destination': '2/4/0', 'destination_name': '', 'direction': 'Outgoing', 'payload': 1, 'source': '15.15.250', 'source_name': '', 'telegramtype': 'GroupValueWrite', 'timestamp': datetime.datetime(2023, 6, 21, 22, 56, 59, 224428, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin')), 'unit': None, 'value': None}}
2023-06-21 22:56:59.225 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_triggers.py", line 97, in async_trigger
    idx = int(run_variables["trigger"]["idx"])
              ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'idx'

Additional information

Could possible the idx default to 0 in case it is missing?

@home-assistant
Copy link

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (homekit) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homekit can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign homekit Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


homekit documentation
homekit source
(message by IssueLinks)

@bdraco
Copy link
Member

bdraco commented Jun 21, 2023

# Example configuration.yaml entry
logger:
  default: info
  logs:
    homeassistant.components.homekit: debug

Please restart with debug logging enabled for homekit and post a new full log. Thanks 👍

@DanielHons
Copy link
Author

DanielHons commented Jun 21, 2023

Sure :) Here it is. Thank you for taking a look.

home-assistant_2023-06-21T21-45-58.382Z.log

[EDIT]
Is it possible that the knx integration and the HomeKit integration are not aligned on how a trigger should look like? I had this suspicion at the beginning.

@bdraco
Copy link
Member

bdraco commented Jun 22, 2023

KNX isn't passing on the trigger data so it can't find the trigger.

This should fix knx:

diff --git a/homeassistant/components/knx/device_trigger.py b/homeassistant/components/knx/device_trigger.py
index 8a074b43b7..1abafb221d 100644
--- a/homeassistant/components/knx/device_trigger.py
+++ b/homeassistant/components/knx/device_trigger.py
@@ -84,6 +84,7 @@ async def async_attach_trigger(
     trigger_info: TriggerInfo,
 ) -> CALLBACK_TYPE:
     """Attach a trigger."""
+    trigger_data = trigger_info["trigger_data"]
     dst_addresses: list[str] = config.get(EXTRA_FIELD_DESTINATION, [])
     job = HassJob(action, f"KNX device trigger {trigger_info}")
     knx: KNXModule = hass.data[DOMAIN]
@@ -95,7 +96,7 @@ async def async_attach_trigger(
             return
         hass.async_run_hass_job(
             job,
-            {"trigger": telegram},
+            {"trigger": {**trigger_data, **telegram}},
         )
 
     return knx.telegrams.async_listen_telegram(

@home-assistant
Copy link

Hey there @Julius2342, @farmio, @marvin-w, mind taking a look at this issue as it has been labeled with an integration (knx) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of knx can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign knx Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


knx documentation
knx source
(message by IssueLinks)

@farmio
Copy link
Contributor

farmio commented Jun 22, 2023

Thank you very much @bdraco 😃
I'm still not sure how these device triggers even get fired for every telegram without ever configuring a device trigger 🤔 (at least I don't think OP has done that from our conversation on Discord)... and why the HomeKit integration picks them up...

@DanielHons
Copy link
Author

Wow, that was quick. Thanks a lot

@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants