#I am Having trouble setting up a button as a trigger for a automation.

1 messages · Page 1 of 1 (latest)

winter arch
#

So far I have tried several things and nothing has worked.

1: I tried the simplest solution of selecting device trigger in the editor and choosing my button and "button pressed" as the trigger. However this did not work,

After some research I found out the device triggers are pretty inconsistent and events were the way to go.

2: I made an event listener for "zha_event" and got this output when I clicked the button:

data:
  device_ieee: a4:c1:38:91:80:57:91:2f
  unique_id: a4:c1:38:91:80:57:91:2f:1:0x0006
  device_id: 8bc04cbd4614c3d458369700193371b3
  endpoint_id: 1
  cluster_id: 6
  command: remote_button_short_press
  args: []
  params: {}
origin: LOCAL
time_fired: "2024-11-18T04:42:55.976099+00:00"
context:
  id: 01JCYS9D38NS78GCP4GDTZQ2M8
  parent_id: null
  user_id: null```

I then selected "manual trigger" in the automation editor and pasted:
```data:
  device_ieee: a4:c1:38:91:80:57:91:2f
  unique_id: a4:c1:38:91:80:57:91:2f:1:0x0006
  device_id: 8bc04cbd4614c3d458369700193371b3
  endpoint_id: 1
  cluster_id: 6
  command: remote_button_short_press```

and set event type to "zha_event"
this still did not work

This is the complete YAML for the automation:
```alias: Living room lights toggle
description: ""
triggers:
  - trigger: event
    event_type: zha_event
    event_data:
      data:
        device_ieee: a4:c1:38:91:80:57:91:2f
        unique_id: a4:c1:38:91:80:57:91:2f:1:0x0006
        device_id: 8bc04cbd4614c3d458369700193371b3
        endpoint_id: 1
        cluster_id: 6
        command: remote_button_short_press
conditions: []
actions:
  - type: toggle
    device_id: 46b25bd7fe0916b3b0271e8232915dc2
    entity_id: 287678a655762326134180b9bdc8ba83
    domain: light
  - type: toggle
    device_id: 95cb4dcb47498ac6e02efc093fe7ce53
    entity_id: 3f55b857052e7c51044f9ffcad6d0871
    domain: light
mode: single```

I am still new to HA and don't have a great handle on editing YAML, so any help would be appreciated!
empty matrix
#

You should remove the data: tag and shift everything left

#

event_data: is data:

winter arch
#

well that was easy

#

thanks!

empty matrix
#

You probably don't need to provide all those tags either. Probably just need device_id and command

winter arch
#

sounds good.

#

is there an easy way to toggle scenes with the button? e.g. when button pressed if scene 1 is activate switch to scene 2 and vice versa?

empty matrix
#

The most straightforward was is to create an input_boolean/toggle helper and toggle it when you activate a scene. Then use an if/then to determine which scene to activate

#

A more clever way is to sort the states of the scenes, which is when the scene was last activated and activate the oldest one. That's more fun, but more complicated

#

And requires templates

winter arch
#

hmmm ok, idk if I could quite figure it out, but I'll give it a try.
imo that should be a supported "if" statement like "if scene 1=true"

empty matrix
#

There's nothing to tell you if a scene is active because it doesn't make sense

#

Activating a scene sets properties of entities. After that, anything can happen to them

winter arch
#

I guess that makes sense, I was picturing it more like a toggle.

#

What about an "if" statement for brightness of the light? Could I have one scene dim the lights to 15% and one that checks if the brightness is 15% and if it is sets it to 100%?

empty matrix
#

If you want to, sure

winter arch
#

What would be the proper YAML for that?

empty matrix
#

You need something to know which scene is active

#

I suggest trying it in the UI

#

I'm not going to write it

winter arch
#

Ok, I'll take a look, thanks again!

#

Unfortunately the UI only supports "if" statements for on/off. I will try to find the proper YAML online.

empty matrix
#

You don't need to write YAML

#

If statements support any condition

winter arch
#

perfect!