home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.97k stars 29.04k forks source link

Restart triggers an automation with HomeKit button (but shouldnt) #118857

Open Mariusthvdb opened 1 month ago

Mariusthvdb commented 1 month ago

The problem

upon restart an automation is triggered (though not listed in the last_triggered overview), resulting in executing a script turning off several lights

I did consider the script responsible for the lights being turned off could be called elsewhere, but the error that is logged clearly states this automation.

Oddity is that is does Not execute the final service in the automation (notify)

the buttons I use in this automation are Ikea buttons, integrated via HomeKit controller, so that is where I raise this. If not correct, please move to automation or script.

What version of Home Assistant Core has the issue?

2024.6.0b8

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 device

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

script:
  aan_de_slag_off_lighting:
    mode: restart
    sequence:
      - service: light.turn_off
        target:
          area_id:
            - keuken
            - zitkamer
#             - woonkamer # zitten in light.zitkamer
#             - eetkamer
            - audio
          entity_id:
#             - light.zitkamer
#             - light.wand_verlichting
            - light.slaapkamer_tafel
      - not:
          condition: state
          entity_id: sensor.dag_deel
          state:
            - Avond
            - Nacht
      - service: light.turn_off
        target:
          entity_id: light.eetkamer
        data:
          transition: 4

  - id: sneltoets_bureau_m_en_w_long_press
    alias: Sneltoets bureau M en W long press
    mode: single
    description: ''
    trigger:
      - platform: state
        entity_id:
          - event.sneltoets_bureau_marijn
          - event.sneltoets_bureau_wijke
    condition:
      - condition: state
        entity_id: binary_sensor.ouders
        state: 'on'
      - condition: or
        conditions:
          - condition: state
            entity_id: event.sneltoets_bureau_marijn
            attribute: event_type
            state: long_press
          - condition: state
            entity_id: event.sneltoets_bureau_wijke
            attribute: event_type
            state: long_press
    action:
#       - service: script.test_sneltoets_trigger
      - service: script.aan_de_slag #this calls the script aan_de_slag_off_lighting above
        metadata: {}
        data: {}
      - service: notify.mobile_app_marijn
        metadata: {}
        data:
          message: lang ingedrukt
          title: M en W ingedrukt

Anything in the logs that might be useful for us?

2024-06-05 09:36:49.771 ERROR (MainThread) [homeassistant.components.script.aan_de_slag] aan_de_slag: Error executing script. Unexpected error for call_service at pos 2: Connection lost before request could be sent
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1002, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1601, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/switch.py", line 94, in async_turn_off
    await self.async_put_characteristics({CharacteristicsTypes.ON: False})
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/entity.py", line 140, in async_put_characteristics
    return await self._accessory.put_characteristics(payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/connection.py", line 972, in put_characteristics
    await self.pairing.put_characteristics(characteristics)
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/pairing.py", line 313, in put_characteristics
    response = await self.connection.put_json(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 392, in put_json
    response = await self.put(
               ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 381, in put
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 495, in request
    raise AccessoryDisconnectedError(
aiohomekit.exceptions.AccessoryDisconnectedError: Connection lost before request could be sent
2024-06-05 09:36:49.783 ERROR (MainThread) [homeassistant.components.automation.sneltoets_bureau_m_en_w_long_press] Sneltoets bureau M en W long press: Error executing script. Unexpected error for call_service at pos 1: Connection lost before request could be sent
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 663, in _service_handler
    response = await self._async_start_run(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 621, in _async_start_run
    script_result = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 652, in _async_run
    return await self.script.async_run(script_vars, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1773, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1002, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1601, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/switch.py", line 94, in async_turn_off
    await self.async_put_characteristics({CharacteristicsTypes.ON: False})
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/entity.py", line 140, in async_put_characteristics
    return await self._accessory.put_characteristics(payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/connection.py", line 972, in put_characteristics
    await self.pairing.put_characteristics(characteristics)
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/pairing.py", line 313, in put_characteristics
    response = await self.connection.put_json(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 392, in put_json
    response = await self.put(
               ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 381, in put
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 495, in request
    raise AccessoryDisconnectedError(
aiohomekit.exceptions.AccessoryDisconnectedError: Connection lost before request could be sent
2024-06-05 09:36:49.794 ERROR (MainThread) [homeassistant.components.automation.sneltoets_bureau_m_en_w_long_press] While executing automation automation.sneltoets_bureau_m_en_w_long_press
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 723, in async_trigger
    return await self.action_script.async_run(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1773, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 663, in _service_handler
    response = await self._async_start_run(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 621, in _async_start_run
    script_result = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 652, in _async_run
    return await self.script.async_run(script_vars, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1773, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1002, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1601, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/switch.py", line 94, in async_turn_off
    await self.async_put_characteristics({CharacteristicsTypes.ON: False})
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/entity.py", line 140, in async_put_characteristics
    return await self._accessory.put_characteristics(payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/connection.py", line 972, in put_characteristics
    await self.pairing.put_characteristics(characteristics)
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/pairing.py", line 313, in put_characteristics
    response = await self.connection.put_json(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 392, in put_json
    response = await self.put(
               ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 381, in put
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohomekit/controller/ip/connection.py", line 495, in request
    raise AccessoryDisconnectedError(
aiohomekit.exceptions.AccessoryDisconnectedError: Connection lost before request could be sent
2024-06-05 09:36:51.700 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 345, in call_rpc
    return await self._wsrpc.call(method, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/wsrpc.py", line 414, in call
    resp = await self._rpc_call(method, params, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/wsrpc.py", line 447, in _rpc_call
    resp = await future
           ^^^^^^^^^^^^
aioshelly.exceptions.DeviceConnectionError: <aioshelly.rpc_device.wsrpc.RPCCall object at 0x7f2807f2f460>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 161, in _handle_ha_stop
    await self.shutdown()
  File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 699, in shutdown
    await async_stop_scanner(self.device)
  File "/usr/local/lib/python3.12/site-packages/aioshelly/ble/__init__.py", line 34, in async_stop_scanner
    script_name_to_id = await _async_get_scripts_by_name(device)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/ble/__init__.py", line 28, in _async_get_scripts_by_name
    scripts = await device.script_list()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 256, in script_list
    data = await self.call_rpc("Script.List")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 351, in call_rpc
    raise DeviceConnectionError from err
aioshelly.exceptions.DeviceConnectionError
2024-06-05 09:36:51.707 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 345, in call_rpc
    return await self._wsrpc.call(method, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/wsrpc.py", line 414, in call
    resp = await self._rpc_call(method, params, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/wsrpc.py", line 447, in _rpc_call
    resp = await future
           ^^^^^^^^^^^^
aioshelly.exceptions.DeviceConnectionError: <aioshelly.rpc_device.wsrpc.RPCCall object at 0x7f2807f2f400>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 161, in _handle_ha_stop
    await self.shutdown()
  File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 699, in shutdown
    await async_stop_scanner(self.device)
  File "/usr/local/lib/python3.12/site-packages/aioshelly/ble/__init__.py", line 34, in async_stop_scanner
    script_name_to_id = await _async_get_scripts_by_name(device)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/ble/__init__.py", line 28, in _async_get_scripts_by_name
    scripts = await device.script_list()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 256, in script_list
    data = await self.call_rpc("Script.List")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 351, in call_rpc
    raise DeviceConnectionError from err
aioshelly.exceptions.DeviceConnectionError
2024-06-05 09:36:51.711 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 345, in call_rpc
    return await self._wsrpc.call(method, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/wsrpc.py", line 414, in call
    resp = await self._rpc_call(method, params, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/wsrpc.py", line 447, in _rpc_call
    resp = await future
           ^^^^^^^^^^^^
aioshelly.exceptions.DeviceConnectionError: <aioshelly.rpc_device.wsrpc.RPCCall object at 0x7f2807f2f3a0>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 161, in _handle_ha_stop
    await self.shutdown()
  File "/usr/src/homeassistant/homeassistant/components/shelly/coordinator.py", line 699, in shutdown
    await async_stop_scanner(self.device)
  File "/usr/local/lib/python3.12/site-packages/aioshelly/ble/__init__.py", line 34, in async_stop_scanner
    script_name_to_id = await _async_get_scripts_by_name(device)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/ble/__init__.py", line 28, in _async_get_scripts_by_name
    scripts = await device.script_list()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 256, in script_list
    data = await self.call_rpc("Script.List")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioshelly/rpc_device/device.py", line 351, in call_rpc
    raise DeviceConnectionError from err
aioshelly.exceptions.DeviceConnectionError

Additional information

note that in the log above, the final errors are not on this particular device, but also raised because of events for button triggers. Because of that I left it in, maybe it contains a lead to the issue. If not, I can open a separate issue for that, though I have no unexpected behavior to report, other than this logging

I did consider adding a condition to the automation not to execute on the manual HA restart, but am not sure what exactly to add there

home-assistant[bot] commented 1 month ago

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

Code owner commands Code owners of `homekit_controller` 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_controller` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


homekit_controller documentation homekit_controller source (message by IssueLinks)

Mariusthvdb commented 1 month ago

Ive adapted the automation to use:

    trigger:
      - platform: state
        entity_id:
          - event.sneltoets_bureau_marijn
          - event.sneltoets_bureau_wijke
        attribute: event_type
        to: long_press
    condition:
      - condition: state
        entity_id: binary_sensor.ouders
        state: 'on'
#       - condition: or
#         conditions:
#           - condition: state
#             entity_id: event.sneltoets_bureau_marijn
#             attribute: event_type
#             state: long_press
#           - condition: state
#             entity_id: event.sneltoets_bureau_wijke
#             attribute: event_type
#             state: long_press
    action:

and that seems to prevent the action from being executed at restart. This might be a better trigger, but Id love to get feedback on why it triggers, even though the condition is in place in the original automation

edit

since the 'solution' above does not trigger on consecutive identical triggers (there is no state change in that case),

I tried to do:

  - id: sneltoets_bureau_m_en_w_long_press
    alias: Sneltoets bureau M en W long press
    mode: single
    description: ''
    trigger:
      platform: state
      entity_id:
        - event.sneltoets_bureau_marijn
        - event.sneltoets_bureau_wijke
      attribute: event_type
      to:
    condition:
      - condition: state
        entity_id: binary_sensor.ouders
        state: 'on'
      - condition: or
        conditions:
          - condition: state
            entity_id: event.sneltoets_bureau_marijn
            attribute: event_type
            state: long_press
          - condition: state
            entity_id: event.sneltoets_bureau_wijke
            attribute: event_type
            state: long_press
    action:
      - service: script.aan_de_slag

but again, that runs on restart

could it be we need to add some 'unavailable' test? do these entities lose their state immediately after clicking the restart button, and that causes the automation to trigger?

yes, that seems to be it:

  - id: sneltoets_bureau_m_en_w_long_press
    alias: Sneltoets bureau M en W long press
    mode: single
    description: ''
    trigger:
      platform: state
      entity_id:
        - event.sneltoets_bureau_marijn
        - event.sneltoets_bureau_wijke
#       attribute: event_type
#       to:
      not_to: &un
        - unavailable
        - unknown
      not_from: *un
    condition:
      - condition: state
        entity_id: binary_sensor.ouders
        state: 'on'
      - condition: or
        conditions:
          - condition: state
            entity_id: event.sneltoets_bureau_marijn
            attribute: event_type
            state: long_press
          - condition: state
            entity_id: event.sneltoets_bureau_wijke
            attribute: event_type
            state: long_press
    action:
      - service: script.aan_de_slag
      - service: notify.mobile_app_marijn
        data:
          message: lang ingedrukt
          title: M en W ingedrukt

does Not trigger on restart, and any event is caught, while the condition checks the type of event.

if this is per design, we can close. However, imho this feels like an issue, so please check

the condition check is not working correctly after all, because it does not limit the condition to the actual last event because of the or...

so we are forced to use a template condition:

{{trigger.to_state.attributes.event_type == 'long_press'}}

Nonetheless, this does Not take away the main reason for the issue: triggering on restart