Automation with conditional trigger not triggering consistently

So I am running 2 hubitats integrated into home assistant as my radios with the integration.

I have a aeotec wall mount quad remote. It is connected via hubitat integration.

I have a somfy zwave blind controller via hubitat as well.

I wrote the following code which seemed to work well last night but not so much this morning.

type or paalias: Greatroom.wallmote.control
description: ""
trigger:
  - platform: state
    entity_id:
      - event.grwallmountquadcontrol
    attribute: event_type
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: event.grwallmotequad_button_1
            attribute: event_type
            state: held
        sequence:
          - service: cover.close_cover
            target:
              entity_id: cover.grzblinds_windowshade
            data: {}
      - conditions:
          - condition: state
            entity_id: event.grwallmotequad_button_1
            attribute: event_type
            state: pushed
        sequence:
          - service: cover.open_cover
            target:
              entity_id:
                - cover.grzblinds_windowshade
            data: {}
      - conditions:
          - condition: state
            entity_id: event.grwallmotequad_button_2
            attribute: event_type
            state: held
        sequence:
          - service: cover.close_cover
            data: {}
            target:
              entity_id: cover.nookzblinds_windowshade
      - conditions:
          - condition: state
            entity_id: event.grwallmotequad_button_2
            attribute: event_type
            state: pushed
        sequence:
          - service: cover.open_cover
            target:
              entity_id:
                - cover.nookzblinds_windowshade
            data: {}
      - conditions:
          - condition: state
            entity_id: event.grwallmotequad_button_3
            attribute: event_type
            state: pushed
        sequence:
          - service: cover.open_cover
            data: {}
            target:
              entity_id: cover.mrzblinds_windowshade
      - conditions:
          - condition: state
            entity_id: event.grwallmotequad_button_3
            attribute: event_type
            state: held
        sequence:
          - service: cover.close_cover
            target:
              entity_id:
                - cover.mrzblinds_windowshade
            data: {}
mode: single
ste code here

This morning, it only fired once on button 2. I then hit button one and the automation failed to run:

Automation runs 1 out of a bunch of tries.

Ideas?

Advice?

Clearly it is not the trigger not being recognized nor the integration.

Thanks for any help with this.

Look at the trace to see what is going on.

Can you explain how your automation is designed to work?

It uses a single State Trigger configured to monitor one event entity’s event_type attribute. The event entity is:

  • event.grwallmountquadcontrol

In its action section it uses a choose to check the value of the event_type attribute of three completely different event entities:

  • event.grwallmotequad_button_1
  • event.grwallmotequad_button_2
  • event.grwallmotequad_button_3

Perhaps I don’t understand how this device works but shouldn’t the automation’s State Trigger monitor the three event entities (containing the word button) instead of event.grwallmountquadcontrol?

It seems to me that those three events are responsible for determining which cover to open or close so they should be the ones monitored by the State Trigger.

It’s an event group composed of four button entities which is triggered by a change


in entity (any activation of any sort)

I did.

The problem is that it only shows the appropriate trace when the appropriate button push is recognized.

The issue is that log shows all the button pushes shown above but there is a failure to recognize the trigger and fire the automation in a ratio of 1 successful to multiple unsuccessful options.

So the trigger is shown as being recognized but the automation doesn’t recognize it consistently as a triggered as it should to activate the automation.

It’s hit or miss.

But each and every button push shows a trigger in the history of the entity and the group.

If you have a moment, try this version (it lacks button_4 because I don’t know which blind it controls but you can easily add it).

alias: example
trigger:
  - platform: state
    entity_id:
      - event.grwallmotequad_button_1
      - event.grwallmotequad_button_2
      - event.grwallmotequad_button_3
    to:
condition:
  - condition: template
    value_template: "{{ trigger.to_state.attributes.event_type in ['held', 'pushed'] }}"
action:
  - variables:
      blinds:
        grwallmotequad_button_1: grz
        grwallmotequad_button_2: nookz
        grwallmotequad_button_3: mrz
      blind: "{{ blinds.get(trigger.to_state.object_id, 'unknown') }}"
      mode: "{{ iif(trigger.to_state.attributes.event_type == 'held', 'close', 'open') }}"
  - condition: "{{ blind != 'unknown' }}"
  - service: 'cover.{{ mode }}_cover'
    target:
      entity_id: 'cover.{{ blind }}blinds_windowshade'
mode: single
1 Like

will do. not home now. but will try and report back.

i understand it completely and find it fascinating! i’ll give it a shot and let you know. this is my first time with .yaml and HA but the code is elegant and simple.

thank you!

so the issue is that it is triggered but the mode is an issue.

if the button is pushed, mode:open; if held, then closed.

i tried this but it didn’t work.

trace shows the conditions working, but the action doesn’t fire. i know my syntax is off but i can’t figure it out

alias: blindcontrol1
description: ""
trigger:
  - platform: state
    entity_id:
      - event.grwallmotequad_button_1
      - event.grwallmotequad_button_2
      - event.grwallmotequad_button_3
    to: null
condition:
  - condition: template
    value_template: "{{ trigger.to_state.attributes.event_type in ['held', 'pushed'] }}"
action:
  - variables:
      blinds:
        grwallmotequad_button_1: grz
        grwallmotequad_button_2: nookz
        grwallmotequad_button_3: mrz
      blind: "{{ blinds.get(trigger.to_state.object_id, 'unknown') }}"
      mode:
        trigger.to_state.attributes.event_type  == 'pushed': open
        trigger.to_state.attributes.event_type  == 'held': close
  - condition: "{{ blind != 'unknown' }}"
  - service: cover.{{ mode }}_cover
    target:
      entity_id: cover.{{ blind }}blinds_windowshade
mode: single

That’s exactly what the example’s template does for the mode variable. If the value of event_type is held then mode is set to close, otherwise it’s set to open.

      mode: "{{ iif(trigger.to_state.attributes.event_type == 'held', 'close', 'open') }}"

Post the automation’s trace file (the Download Trace command is found in the upper right menu when you’re viewing a trace). It will help me understand what’s happening.

1 Like

ok that was strange.

i recopied your example and it worked perfectly.

I am not convinced this yaml editor is working as well as it should.

thank you again. this is a great starting point.

is there a definitve guide on advanced yaml structure for those of us new to yaml but not coding?

YAML is used for many purposes because it’s a means of structuring data. Home Assistant uses it for several things including to create a scripting language. That’s documented here:

Scripts - Home Assistant (home-assistant.io)
Script Syntax - Home Assistant (home-assistant.io)

If you look at my example above, the text you see displayed in red is Jinja which is a templating language. That’s completely separate from YAML and is documented here:

Templating - Home Assistant (home-assistant.io)

1 Like