Action chose wont execute trigger when holding state logic is added

This is so super cool. I am immediately rewriting my 6 automations for my ac now into one. This is really nice and solves so many issues I could only solve by writing a different automation for each . Thanks for even going further to help expand my mind more.

Lastly out of curiosity, I have several automations where I use my notification lights. Is it possible to have the lights trigger maybe 2 minutes(3 min) before the 5 minute “for :00:05:00” and if I addressed the situation toggled the switch/light, closed the door, the trigger would no longer go off? In the automation that goes off it would be nice if my kid is asleep I could prevent the voice announcement if saw the light notify me .

I am asking as I am going to redo a lot of automations now and I figured I could integrate this.

I wanted to clarify when I specify multiple conditions and do not explicitly say its an, “and” condition does it just assume that’s the “and” condition? It seems to interpret it this way.

- conditions:
  - condition: trigger
    id: switch_on_1_min
  - condition: state
      entity_id: input_boolean.kidsleepmode
      state: 'on' 	

Yes. The documentation states:

Unlike a trigger, which is always or, conditions are and by default - all conditions have to be true.

Yes, just create a separate trigger with a shorter for duration (`for: ‘00:03:00’).

No, the State Trigger employing for: '00:05:00' can still trigger but all you need to do is add a condition (in the sequence that handles the trigger within choose) that prevents executing the balance of its `sequence if the door is already closed and the light is already in the desired state.

I wanted to say thanks a million. With what you shared I condensed my automations significantly and my though process has changed as well. I really appreciate you taking the type to help me .

Hi, Thanks for you opening me up to trigger ids.
I was trying to use a trigger ID but I am not having having luck.
The automation below shows up in the automation list when I comment out the id portion but it does not show when I uncomment the trigger id. I tried moving the Id to the top, at the end, using single quotes instead of double quotes and I feel I am missing something. Could you help me see where I went wrong . Thanks for helping better make use of the HA features.

- id: '16276162667617183740'
- alias: TurnOffDimLightsNoMotion
  trigger:
    - platform: state
   # id: "motion_on"  # I see the automation when I uncomment.
      entity_id: binary_sensor.motion_sensor_158d0001a8d4e9
      to: 'on'
 

  condition:
  - condition: state
    entity_id: media_player.55_tcl_roku_tv
    state: unavailable
  - condition: state
    entity_id: light.entertainment_area_3
    state: 'off'  
  action:
  - choose:
    - conditions:
       ########## MOTION ON ################
      - "{{ trigger.id == 'motion_on' }}" 
   #   - condition: trigger  
    #    id: "motion_on"     # I tried not using the short hand version to see if wat the #problem  
      sequence:
      - condition: state
        entity_id: light.ceilinglight
        state: 'off'
      
      - service: light.turn_on
        entity_id:  light.ceilinglight 

I Tried this as well still no luck. Which is what I see in documentation:

######################DIM Lights  Before Turning OFF ##################################
- id: '16276162667617183740'
- alias: TurnOffDimLightsNoMotion
  trigger:
    - platform: state
      id: "motionon"    
      entity_id: binary_sensor.motion_sensor_158d0001a8d4e9
      to: 'on'
  condition:
  - condition: state
    entity_id: media_player.55_tcl_roku_tv
    state: unavailable
  - condition: state
    entity_id: light.entertainment_area_3
    state: 'off'  
  action:
  - choose:
    - conditions:
       ########## MOTION ON ################
      #- "{{ trigger.id == 'motion_on' }}" 
      - condition: trigger
        id: "motionon"      
   #   - condition: trigger
    #    id: "motion_on"       
      sequence:
      - condition: state
        entity_id: light.ceilinglight
        state: 'off'
      
      - service: light.turn_on
        entity_id:  light.ceilinglight 

Not sure why you have it like this but I am surprised this even passes Check Configuration.

- id: '16276162667617183740'
- alias: TurnOffDimLightsNoMotion

That’s like two separate automations, the first with an id but nothing else, the second with no id but contains alias and other valid code for an automation.

Replace the hyphen on the second line with a space.

I did make the change but I am still not getting the automation to show up .

I am losing lot of hair. I wanted to see if this portion works before building out the automation further.

Thanks




######################DIM Lights  Before Turning OFF ##################################
- id: '1627616266761754183740'
  alias: TurnOffDimLightsNoMotionTwo
  trigger:
    - platform: state
      id: "motionon"    
      entity_id: binary_sensor.motion_sensor_158d0001a8d4e9
      to: 'on'
  condition:
  - condition: state
    entity_id: media_player.55_tcl_roku_tv
    state: unavailable
  - condition: state 
    entity_id: light.entertainment_area_3
    state: 'off'  
  action:
  - choose:
    - conditions:
       ########## MOTION ON ################
      #- "{{ trigger.id == 'motion_on' }}" 
      - condition: trigger
        id: "motionon"      
   #   - condition: trigger
    #    id: "motion_on"       
      sequence:
      - condition: state
        entity_id: light.ceilinglight
        state: 'off'
      
      - service: light.turn_on
        entity_id:  light.ceilinglight   

If after saving the automation you are executing Configuration > Server Controls > Check Configuration, it will report any errors it finds.

Even if you don’t do that and, after saving the automation, go directly to Configuration > Server Controls > Reload Automations, if it encounters errors it will refuse to reload automations and report the error (refer to Logs).

I cleared everything in my automations.yaml and left just this:

######################DIM Lights  Before Turning OFF ##################################
- id: 1627616266761754183740
  alias: TurnOffDimLightsNoMotionTwo
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d0001a8d4e9
      id: "motionon" 
      to: 'on'
  condition:
  - condition: state
    entity_id: media_player.55_tcl_roku_tv
    state: unavailable
  - condition: state 
    entity_id: light.entertainment_area_3
    state: 'off'  
  action:
  - choose:
    - conditions:
       ########## MOTION ON ################
      #- "{{ trigger.id == 'motionon' }}"  
    
      - condition: trigger
        id: "motionon"       
      sequence:
      - condition: state
        entity_id: light.ceilinglight
        state: 'off'
      
      - service: light.turn_on 
        entity_id:  light.ceilinglight    

This is what I see in the log:

Invalid config for [automation]: required key not provided @ data['action']. Got None required key not provided @ data['trigger']. Got None. (See /config/configuration.yaml, line 574).
Invalid config for [automation]: [id] is an invalid option for [automation]. Check: automation->id. (See /config/configuration.yaml, line 574).
Invalid config for [automation]: not a valid value for dictionary value @ data['action'][0]['choose'][0]['sequence'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 574).
Invalid config for [automation]: expected str for dictionary value @ data['id']. Got None. (See /config/configuration.yaml, line 574).
Invalid config for [automation]: Unexpected value for condition: 'trigger'. Expected numeric_state, state, sun, template, time, zone, and, or, not, device @ data['action'][0]['choose'][0]['conditions'][0]. Got None expected str for dictionary value @ data['id']. Got None. (See /config/configuration.yaml, line 574).

It seems like it does not like something here:
- condition: trigger
id: “motionon”

but I don’t see what I am missing

What is the version of Home Assistant you are using?

Try this version:

- id: 1627616266761754183740
  alias: TurnOffDimLightsNoMotionTwo
  trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor_158d0001a8d4e9
    to: 'on'
    id: 'motionon'
  condition:
  - condition: state
    entity_id: media_player.55_tcl_roku_tv
    state: 'unavailable'
  - condition: state 
    entity_id: light.entertainment_area_3
    state: 'off'  
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: 'motionon'
      - condition: state
        entity_id: light.ceilinglight
        state: 'off'
      sequence:
      - service: light.turn_on 
        entity_id:  light.ceilinglight    

BTW, I assume you know this is a contrived example because it has only one trigger so there’s little value in using a trigger id.

Yes, I am aware that I could simply trigger using the "on state " if I only had one trigger but I plan on expanding and adding a motion sensor for each room.
Since I am new to HA and using a new feature I prefer to test one trigger at a time. Makes it easier for me to find and fix my errors.

I tried your suggested code and no luck. I can accomplish what I need to using delays and setting the automation mode to restart so I don’t want to take up a lot of your time . I was excited to use the new feature you shared.

Can you elaborate on what you mean by “no luck”? Did it fail to pass Check Configuration or did it fail to trigger or did it fail to execute its actions as expected? If it triggered, you can inspect its trace.

Sorry for the delay. It is not showing up as an automation but I see this in the log. Do you have any idea why its pointing to the config file if the issue is for automation?

Invalid config for [automation]: required key not provided @ data['action']. Got None required key not provided @ data['trigger']. Got None. (See /config/configuration.yaml, line 584).
Invalid config for [automation]: not a valid value for dictionary value @ data['action'][0]['choose'][0]['sequence'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 584).

The example I posted above passes Check Configuration on my system with no errors. Clearly you are doing something wrong.

Where did you paste this example into your system? In the automations.yaml file with your other automations? If you did, post a fragment of that file showing the example and its nearest neighbors.

Sorry, I thought I had hit reply apparently I did not. I thank you for your help . I needed to fix something else in my automation file and the issue is resolved now. Thanks again.

You should be aware that it’s customary to assign the Solution tag to the post that is the first to identify the issue and offer a solution. In this case, you took the information provided to you and marked your own post as the Solution.

If everybody did that then no matter how much assistance they received, the solution would always appear to come from the same person who asked the question. It would appear that everyone ultimately solves their own problem … and if that were true then they wouldn’t need help in the first place. That’s why the Solution tag is assigned to whoever’s post actually provided the solution.

For more information, refer to guideline 21 in the FAQ.

So sorry about that is not my intent. I think I corrected it now. I really really really appreciated your help . Thanks again.

1 Like

That’s interesting because it still shows the same thing.

It should be good now. :smiley:

1 Like