#How to listen correctly on an event

1 messages · Page 1 of 1 (latest)

lost wolf
#

I want to trigger an automatiin by a specific state_changed event:

event_type: state_changed
data:
  entity_id: event.dashbutton_wohnzimmer_action
  old_state:
    entity_id: event.dashbutton_wohnzimmer_action
    attributes:
      event_types:
        - single
        - double
        - hold
        - "on"
        - "off"
      event_type: double
      icon: mdi:gesture-double-tap
      friendly_name: DashButton - Wohnzimmer Action
    context:
      id: 01JHMHHM3ANS6S474TWR75HCDR
      parent_id: null
      user_id: null
  new_state:
    entity_id: event.dashbutton_wohnzimmer_action
    state: "2025-01-15T08:33:41.721+00:00"
    attributes:
      event_types:
        - single
        - double
        - hold
        - brightness_move_to_level
        - color_temperature_move
        - brightness_step
        - "on"
        - "off"
      event_type: "on"
      icon: mdi:gesture-double-tap
      friendly_name: DashButton - Wohnzimmer Action
    context:
      id: 01JHMHHMAS88SQB7YXYXM16N9T
      parent_id: null
      user_id: null
origin: LOCAL
time_fired: "2025-01-15T08:33:41.721913+00:00"
context:
  id: 01JHMHHMAS88SQB7YXYXM16N9T
  parent_id: null
  user_id: null

For that I build this trigger:

trigger: event
event_type: state_changed
event_data:
  entity_id: event.dashbutton_wohnzimmer_action
  new_state:
    event_type: "double"

If I remove the "new_state" stuff it is triggered if my device do any action. But I only want to trigger on the "double" action.
But after adding the "new_state" part the automation is not triggered anymore.

T

umbral comet
#

Just to simplify that, you've got an event entity why not just use a state trigger?

#

You also forgot to share the whole automation

lost wolf
#

Only the trigger is currently my problem.

#

This does not work:

#

Maybe it is caused, because immediatly after the state is "double" it is reset to "on".

umbral comet
#

The YAML helps us more than the pictures do

lost wolf
#
alias: Aktiviere Input_button wenn Double Tab on DashButton (WZ)
description: >-
  Wenn im Wohnzimmer ein Double-Tab ausgeführt wird, wird der Input button
  (starte pc) gedrückt. Dieser wird als Start für die entsprechenden
  Automatisierungen verwendet.
triggers:
  - trigger: state
    entity_id:
      - event.dashbutton_wohnzimmer_action
    to: double
conditions: []
actions:
  - action: input_button.press
    metadata: {}
    data: {}
    target:
      entity_id: input_button.starte_pc
mode: single

umbral comet
#

But no, having it change to on doesn't matter

#

And that's why YAML wins

#

You're checking the state

lost wolf
#

Maybe the "double" state is not long enough present

umbral comet
#
    state: "2025-01-15T08:33:41.721+00:00"
#

You need to check the event_type attribute

#
  - trigger: state
    entity_id:
      - event.dashbutton_wohnzimmer_action
    attribute: event_type
    to: double
lost wolf
#

Nice, thank you

#

Is there a similar behavior for node-red "event: state" nodes?:

umbral comet
#

I don't use Node Red so can't say

#

I'd assume so, since it can handle attributes