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
72.8k stars 30.51k forks source link

Matter Event Entity Not Recognized in a Conditional Template #124527

Closed jvmahon closed 2 months ago

jvmahon commented 2 months ago

The problem

Problem: I believe there is an issue with the Matter button press Event entity not being recognized in a conditional template.

Note: This problem has been tested using the Inovelli VTM31-SN dimmer.

Background:

  1. I am constructing an automation where I want to use the same "Then Do" section for several event entities. An example use is I have several switches that lead to the outdoors, and I want a double-tap on any one of them to do the same thing.
  2. For this purpose, I trigger on a state change of any of several event entities. This much seems pretty routine
  3. In the "Then Do" section, I want to use a "Choose" to determine the number of presses.
  4. However, since there are several entities that may trigger the automation, I don't want to "hard code" the event entity ID.
  5. Instead, I want to use the "trigger" value to identify which one of the entities triggered, and then read its event_type attribute.
  6. I am doing this using a conditional value template
  7. I have tried various forms of condition value templates, none of them seem to recognize the double-tap event.
  8. However, I also added a not has_value test to the automation, and the not has_value condition template does evaluate to true. This is very strange since the trace indicates that there is a recognized entity_id, so "not" has_value should be false.

I have pasted sample YAML for a simplified version of what I am trying to do. In the "Choose" block, Options 1 - 4 are various attempts to use condition templates to recognize a double tap.

Options 5 and 6 test if the entity is known (using has_value and not has_value). Only Option 6 gets executed on a double tap.

I have also pasted below the trace data for a sample triggering using double-tap. As I read the trace data, trigger.to_state_entity_id does have a value (and correctly identifies the triggering entity), but "{{ not has_value ('trigger.to_state.entity__id') }}" still evaluates to true.

So, am I doing something wrong? Or is this a bug in the Event entity code?

What version of Home Assistant Core has the issue?

2024.8.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

Matter

Link to integration documentation on our website

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

Diagnostics information

trace automation.backyard_lights_on_and_off 2024-08-24T12_57_40.604780+00_00.json

Example YAML snippet

alias: Test Trigger Conditions Pressed 2X
description: ""
trigger:
  - platform: state
    entity_id:
      - event.backyard_deck_door_up_button
condition: []
action:
  - choose:
      - conditions:
          - alias: Pressed 2X using equality operator
            condition: template
            value_template: "{{ trigger.to_state.event_type == 'multi_press_2' }}"
        sequence: []
      - conditions:
          - alias: Pressed 2X using is_state_attr
            condition: template
            value_template: >-
              {{ is_state_attr('trigger.to_state.entity_id', 'event_type',
              'multi_press_2') }}
        sequence: []
      - conditions:
          - alias: Pressed 2X using state_attr
            condition: template
            value_template: >-
              {{ state_attr('trigger.to_state.entity_id', 'event_type') ==
              'multi_press_2' }}
        sequence: []
      - conditions:
          - alias: Pressed 2X using state_attr
            condition: template
            value_template: >-
              {{ state_attr('trigger.to_state.entity_id', 'event_type') ==
              multi_press_2 }}
        sequence: []
      - conditions:
          - alias: Entity Is Known
            condition: template
            value_template: "{{ has_value('trigger.to_state.entity_id') }}"
        sequence: []
      - conditions:
          - alias: Entity Is Not Known
            condition: template
            value_template: "{{ not has_value('trigger.to_state.entity_id') }}"
        sequence: []
mode: queued
max_exceeded: silent

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 2 months ago

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

Code owner commands Code owners of `matter` 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 matter` 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)


matter documentation matter source (message by IssueLinks)

jvmahon commented 2 months ago

I also wonder if there could be a connection to this other issue I entered in the "frontend" repository regarding use of Labels as references: https://github.com/home-assistant/frontend/issues/21744

In both this "conditional template" issue, and frontend "labels as references" issue 21744, there seems to be problem accessing information relating to an entity created by the Matter integration.

jvmahon commented 2 months ago

Possibly solved - may be a quoting error. Closing for now while I check further.