Choose always taking the same option

Problem: Choose always takes the same route, even if the conditions are not met.
What I am trying to do: I want an automation to perform different actions based on if another automation is running
What I have tried:

  • Extracting attribute state from configuration.yaml and using a choose for that binary attribute based on whether it’s 1 or 0
  • Using another automation to turn on a helper. The helper (switch) works great but then choose still takes the exact same route, regardless of what the helper is doing.
  • Using an If/Then. Exact same problem with the helper or the state attribute.
  • checked the spelling/case of all entities many many times

I feel like I must be doing something wrong, I just don’t know what

alias: Secure House Triggers
description: ""
trigger:
  - platform: event
    event_type: state_changed
    event_data:
      entity_id: event.back_door_light_and_aux_buttons_scene_004
  - platform: device
    type: changed_states
    device_id: 7519e0d903a4edfa2cd5d0bd951528cb
    entity_id: 247d362a7241ac3fe6ace4a3336dde44
    domain: switch
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.hvac_status_3
            state: "0"
        sequence:
          - service: automation.trigger
            target:
              entity_id: automation.secure_house
            data:
              skip_condition: true
      - conditions:
          - condition: state
            entity_id: sensor.hvac_status_3
            state: "1"
        sequence:
          - service: automation.turn_off
            target:
              entity_id: automation.secure_house
            data:
              stop_actions: true
          - device_id: bc891b713523a8dedb664b325031eb9b
            domain: zwave_js
            type: set_config_parameter
            endpoint: 0
            parameter: 10
            bitmask: null
            subtype: 10 (LED Indicator Color (Button 4)) on endpoint 0
            value: 0
          - type: turn_off
            device_id: 96ad377956b4f4d42b9c448d2b9d2900
            entity_id: 5baf8a818dbac6e6ac389a342b71557b
            domain: switch
          - type: turn_off
            device_id: 7519e0d903a4edfa2cd5d0bd951528cb
            entity_id: 247d362a7241ac3fe6ace4a3336dde44
            domain: switch
          - service: automation.turn_on
            target:
              entity_id: automation.secure_house
            data: {}
mode: restart

You are checking the hvac status but pointing to the secure house automation status.

So, I am confused with the issue.

I think it is how I wrote it in my configuration.yaml file. I cannot get rid of the hvac_status portion of it. However, I have copy/pasted the unique entity ID.

This is also the reason I tried using the switch helper in the choose. Regardless of the switch being on or off, it always takes the same route.

#Attribute for secure house automation running status
  - platform: template
    sensors:
      automation_status:
        unique_id: "secure_house_automation_running"
        friendly_name: secure house automation status
        value_template: >-
          {{ state_attr('automation.secure_house', 'current')}}

Hello all, incase anyone stumbles on this, I found the root cause of the problem.

In the automation I am calling to trigger the same automation that I am checking the status of, for some reason this makes everything not work properly. As soon as I disable the step of triggering the same automation, the choose proceeds as normal. I’m sure there is a work around but I anticipate it being complicated.

If this only has the states 1 and 0 you should be using a binary sensor. Also you should be using the new template integration for new template sensors. The legacy template sensor platform is not getting new features (though it does continue to be supported).

e.g. replace that with this in your configuration.yaml file (not sensors.yaml or binary_sensors.yaml)

template:
  - binary_sensor:
      - name: Secure House Automation Status
        device_class: running
        state: "{{ is_state_attr('automation.secure_house', 'current','1') }}"

You can then use this condition in your choose action:

action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.secure_house_automation_status
            state: "off"

this will not however solve your automation triggering issue. We would need to see both automations to solve that.

Solution Below

Thank you for taking the time to help me @tom_l. I had no idea I was using legacy templating. I did implement your method but the state would never change. I found an alternate method before I was able to determine/fix the problems with implementing what you suggested (I was likely doing something wrong).

Anyways, I found the solution to my original problem. I have changed entity names from the above description however the core concept remains the same and the mistake was very simple.

The problem is you cannot use the service call Script: “script_name_here” after you check if a script is running. The same applies for automations and the example is below:

service: script.securing_house_test
data: {}

The above example is wrong and will not work

The method that worked for me to determine if the script/automation is running and then shut it off if it is or turn it on if its not running is below.

action:
  - choose:
      - conditions:
          - condition: state
            entity_id: script.securing_house_test
            attribute: current
            state: 1
        sequence:
          - service: script.turn_off
            target:
              entity_id:
                - script.securing_house_test
            data: {}

Two important takeaways in the above example. 1, when using a script, you have to use the “script turn on service call” to activate the script. 2, quotation marks will automatically be added around the “1” and the “0” The quotation marks must be removed manually for the above example to work.

Entire code is below in the event it helps someone:

alias: Home Securing Test
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.secure_house_test
    from: "off"
    to: "on"
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: script.securing_house_test
            attribute: current
            state: 1
        sequence:
          - service: script.turn_off
            target:
              entity_id:
                - script.securing_house_test
            data: {}
      - conditions:
          - condition: state
            entity_id: script.securing_house_test
            attribute: current
            state: 0
        sequence:
          - service: script.turn_on
            target:
              entity_id: script.securing_house_test
            data: {}
      - conditions: []
        sequence:
          - service: script.securing_house_test
            data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
mode: restart