Changing input_select state on automation not working

Guys, I’m pulling my hair out on this!
I have created an automation for monitoring a washing machine, which can have the following three states on a input_select helper entity:
- Washing
- Finished
- Cleared

The automation works mostly but at the very end of the washing process, the input_select state of the washing machine gets stuck on “Finished” and does never change again to someting else.
So when the door of the washing machine gets opened after the washing proccess, the state never changes to “Cleared” and even starting a new washing process does not change the state to “Washing” again.

For better understanding I made this screenshot:

You can see on the timeline, from 10:05 on, the washing machine is not consuming power anymore for more than 5 minutes which indicates the washing process is finished. This works as intended so far and a telegram message is being send correctly every 30 minutes. So far, so good.

Then you can see on 11:13 approximately, the door was being opened (and on 11:14 the door was being closed again to start a new washing process) but the state was never changed to “Cleared”. It gets stuck on “Finished”. Which results in telegram messaged keep being sent forever.
When I change the state back to “Cleared” manually, everything works again until the next washing process being finished.

Here’s my automation code:

alias: WashingMachine
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
    to: "on"
    from: "off"
    id: XiaomiAqaraDoorAndWindowSensor01FromClosedToOpen
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.mystromswitch02_power_total
    for:
      hours: 0
      minutes: 0
      seconds: 30
    above: 10
    id: myStromSwitch02PowerTotalAboveTriggerLimitWashing
  - platform: numeric_state
    entity_id: sensor.mystromswitch02_power_total
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 10
    id: myStromSwitch02PowerTotalBelowTriggerLimitFinished
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: XiaomiAqaraDoorAndWindowSensor01FromClosedToOpen
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.washingmachinestate
                    state: Cleared
        sequence:
          - service: input_select.select_option
            data:
              option: Cleared
            target:
              entity_id: input_select.washingmachinestate
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: myStromSwitch02PowerTotalAboveTriggerLimitWashing
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.washingmachinestate
                    state: Washing
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "off"
        sequence:
          - service: input_select.select_option
            data:
              option: Washing
            target:
              entity_id: input_select.washingmachinestate
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: myStromSwitch02PowerTotalBelowTriggerLimitFinished
              - condition: state
                entity_id: input_select.washingmachinestate
                state: Washing
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "off"
        sequence:
          - service: input_select.select_option
            data:
              option: Finished
            target:
              entity_id: input_select.washingmachinestate
          - repeat:
              while:
                - condition: and
                  conditions:
                    - condition: state
                      entity_id: input_select.washingmachinestate
                      state: Finished
                    - condition: state
                      entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                      state: "off"
              sequence:
                - service: telegram_bot.send_message
                  data:
                    message: Waschvorgang beendet!
                    target: -xxxxxxxxx
                - delay:
                    hours: 0
                    minutes: 30
                    seconds: 0
                    milliseconds: 0
mode: single

Any ideas what the problem could be? Any help is very appreciated!

EDIT:

I just had a thought: As I am using trigger IDs and therefore this is a single automation, the automation may get stuck in the while loop for 30 minutes and therefore never changes the state, even when the door is being opened. Could that be the problem? Do I have to separate the automation containing the while loop from the other two automations?

Have you tried using Trace?

Yes! This is probably the cause of the issue you have.

You can try changing the mode from single to restart.

Change to:

mode: restart

You can aso change this delay for a wait_for_trigger and wait 30 min until the door is opened, then the delay will ato when you open the door.
Then you have to change your trigger on the door to have triggered when the door is opened for 5 sec, so you know the automation will be finished before it detects the door opening.

Ooh, I was not aware of the wait_for_trigger option, which could be very handy in this case.
Also I changed the “while” loop to an “until” loop (probably not necessary, but it looks better for understanding).
Now it looks like this:

alias: WashingMachine
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
    to: "on"
    from: "off"
    id: XiaomiAqaraDoorAndWindowSensor01FromClosedToOpen
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.mystromswitch02_power_total
    for:
      hours: 0
      minutes: 0
      seconds: 30
    above: 10
    id: myStromSwitch02PowerTotalAboveTriggerLimitWashing
  - platform: numeric_state
    entity_id: sensor.mystromswitch02_power_total
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 10
    id: myStromSwitch02PowerTotalBelowTriggerLimitFinished
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: XiaomiAqaraDoorAndWindowSensor01FromClosedToOpen
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.washingmachinestate
                    state: Cleared
        sequence:
          - service: input_select.select_option
            data:
              option: Cleared
            target:
              entity_id: input_select.washingmachinestate
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: myStromSwitch02PowerTotalAboveTriggerLimitWashing
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.washingmachinestate
                    state: Washing
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "off"
        sequence:
          - service: input_select.select_option
            data:
              option: Washing
            target:
              entity_id: input_select.washingmachinestate
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: myStromSwitch02PowerTotalBelowTriggerLimitFinished
              - condition: state
                entity_id: input_select.washingmachinestate
                state: Washing
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "off"
        sequence:
          - service: input_select.select_option
            data:
              option: Finished
            target:
              entity_id: input_select.washingmachinestate
          - repeat:
              until:
                - condition: state
                  entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                  state: "on"
              sequence:
                - service: telegram_bot.send_message
                  data:
                    message: Waschvorgang beendet!
                    target: -xxxxxxxxx
                - wait_for_trigger:
                    - platform: state
                      entity_id:
                        - binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                      from: "off"
                      to: "on"
                  timeout:
                    hours: 0
                    minutes: 30
                    seconds: 0
                    milliseconds: 0
mode: single

Let’s see if this works now, I’ll report back next time my wife starts a washing process :slight_smile:

P.S. Unfortunately I did not really understand what you are trying to tell me by this:

Then you have to change your trigger on the door to have triggered when the door is opened for 5 sec, so you know the automation will be finished before it detects the door opening.

I had similar issues keeping input select in sync. I used a different approach. I created template switches for each of input select items (input_select.select_option) in my case Off, Dark, Relaxed and Bright . Used so I can trigger Light moods in Alexa and my dashboard

  - platform: template
    switches:
      dark:
        value_template: >
          {% if is_state('input_select.mood','Dark') %}
            true
          {% else %}
            false
          {% endif %}
        turn_on:
          service: input_select.select_option
          data:
            option: "Dark"
          target:
            entity_id: input_select.mood
        turn_off:
          service: input_select.select_option
          data:
            option: "Off"
          target:
            entity_id: input_select.mood 
      relaxed:
        value_template: >
          {% if is_state('input_select.mood','Relaxed') %}
            true
          {% else %}
            false
          {% endif %}
        turn_on:
          service: input_select.select_option
          data:
            option: "Relaxed"
          target:
            entity_id: input_select.mood
        turn_off:
          service: input_select.select_option
          data:
            option: "Off"
          target:
            entity_id: input_select.mood
      bright:
        value_template: >
          {% if is_state('input_select.mood','Bright') %}
            true
          {% else %}
            false
          {% endif %}
        turn_on:
          service: input_select.select_option
          data:
            option: "Bright"
          target:
            entity_id: input_select.mood
        turn_off:
          service: input_select.select_option
          data:
            option: "Off"
          target:
            entity_id: input_select.mood

So you can trigger the input select via the switches . The switches will always match the item select and best of all they dont trigger if you change the option in the item select.

Maybe of use ?

I’ll definitely have a look on it.
However I changed my idea again, deleted the first trigger-id based action option and added an if-then option like this instead:

alias: WashingMachine
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.mystromswitch02_power_total
    for:
      hours: 0
      minutes: 0
      seconds: 30
    above: 10
    id: myStromSwitch02PowerTotalAboveTriggerLimitWashing
  - platform: numeric_state
    entity_id: sensor.mystromswitch02_power_total
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 10
    id: myStromSwitch02PowerTotalBelowTriggerLimitFinished
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: myStromSwitch02PowerTotalAboveTriggerLimitWashing
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.washingmachinestate
                    state: Washing
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "off"
        sequence:
          - service: input_select.select_option
            data:
              option: Washing
            target:
              entity_id: input_select.washingmachinestate
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: myStromSwitch02PowerTotalBelowTriggerLimitFinished
              - condition: state
                entity_id: input_select.washingmachinestate
                state: Washing
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "off"
        sequence:
          - service: input_select.select_option
            data:
              option: Finished
            target:
              entity_id: input_select.washingmachinestate
          - repeat:
              until:
                - condition: state
                  entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                  state: "on"
              sequence:
                - service: telegram_bot.send_message
                  data:
                    message: Waschvorgang beendet!
                    target: -xxxxxxxxx
                - wait_for_trigger:
                    - platform: state
                      entity_id:
                        - binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                      from: "off"
                      to: "on"
                  timeout:
                    hours: 0
                    minutes: 30
                    seconds: 0
                    milliseconds: 0
                  continue_on_timeout: true
          - if:
              - condition: state
                entity_id: binary_sensor.xiaomiaqaradoorandwindowsensor01_contact
                state: "on"
            then:
              - service: input_select.select_option
                data:
                  option: Cleared
                target:
                  entity_id: input_select.washingmachinestate
mode: single

I’ll report back if this has worked.

Well, as your automation is set on single mode, if any of the triggers happens while the automation is already running, it won’t be running again and instead you might have just an info on your log file.

When it finishes the washing, the automation will be running until you open the door, so that trigger based on the door opening will never trigger (as the automation is already running).
Now you are ending your automation also when the door opens, so it probably will take a few milliseconds until the door could be used as a trigger again, but your trigger isn’t giving that time.
So, if you change your trigger from “door opened” to “door opened for 5 seconds” this problem is solved, as the trigger will be evaluated 5s after the automation finishes (or you can try 1s).

Or you can simply change your automation mode from single to restart, then this problem has gone (and probably will be more reliable).

Now I got ya, thanks a lot man!
Do you maybe know if on the following screenshot the third action (if-action) is only being executed as soon as the second action (repeat-action) is being quit? Am I getting this right? If so, I guess the last code I’ve posted above could be the solution.

Yes, that is probably fine…

But…

You have to take in account that your automation can be interrupted by something externally… Let’s say your Home Assistant restarts for some reason… It can take hours until you take the clothes from the washing machine and everything can happen… If that is the case, your select helper will stay on “Washing” or “Finished” state forever, so you should plan for that and work on your triggers to handle those cases.

Good point.
You mean changing to something like helpers, for example like timers that “survive” HA reboots for motion light purposes?

@EdwardTFN @lonebaggie

I just wanted to report back that it works now as intended with my latest solution I posted above.
Thanks a bunch you for your time guys, very appreciated!

2 Likes