#Using event attribute as a trigger for automation

1 messages · Page 1 of 1 (latest)

sacred bone
#

I am trying to trigger an automation using an event. Here is an example of the event:

https://dpaste.org/Hfj1f

I want to trigger on event_type state_changed AND the 'alarm' attribute being 'idle' in the 'new_state'. This is what I am trying but it does not match:

event_type: state_changed
event_data:
  new_state:
    attributes:
      alarm: idle
trigger: event
id: turnoffalarm
enabled: true

Can someone tell me what I am doing wrong?

valid scarab
#

Using an Event trigger for that is only going to cause you pain... State triggers are already designed to listen for state_changed events and are much easier to use.

trigger: state
entity_id: sensor.viewassist_masterbedroom
attribute: alarm
to: idle
stray hull
#

I don't think it works like the way you want it to. Event trigger seems very poorly documented, but from what I can gather if you pass a key to event_data, the value of that key will be compared exactly to the key in the event.

You can't filter within nested dicts.

So if the value of new_state is not exactly

    attributes:
      alarm: idle

It won't match. That means the event being compared can't have other attributes, it can't have a state key, it can't have anything else but exactly what you put there, no more and no less. Which will obviously never work.

sacred bone
# valid scarab Using an Event trigger for that is only going to cause you pain... State trigger...

I wish it were that easy. This is for my View Assist (VA) project which allows for voice satellites to interact with HA. One of the things I've been working on is alarms and timers. I have these working well with some pyscript scripting. The issue I'm trying to overcome now is when the user presses either the snooze or dismiss button. I need a way to determine when these are pressed and the device that the button press comes from. The buttons are using the custom button card.

All of this information is in the state change event. Unfortunately this same event happens for other View Assist functions so I would need a way to filter it. From all of my poking at this stuff over the past few months, and I may be wrong, but I can't use a template trigger for this as it would be checking state change across all VA satellites. I am able to trigger on events fine but I can't trigger an event via the custom button card as it can only use action calls. I do not want to create or require the VA users to create a helper or helpers for this as it gets messy. Really all of this is a problem because I am trying to support multiple devices that could have alarms/timers going off at the same time and I'd like to have one automation that handles them all.

I am trying to give the users a good experience while minimizing the effort it takes to install another voice expansion blueprint. This one is already complicated and requires installing the blueprint, a view, the psycript and two scripts for alarm sound playback and looping. I am far from an expert in any of this as is evident in the code I've written. This one automation is about 500 lines of YAML.

I'm open to ideas but it does sound like I may be stuck creating a script that can create events and calling that via the button press.

sacred bone
stray hull
#

can't you get the same effect with a wider trigger and a condition?