When I turn off manually any switch, the automation runs again

Hi all,

I have an automation for my boiler that I want to turn off after specific time depends on the switch that I turned it on. Also I want to be able to turn it off from the switch. So far so good, does the job as I like it. The “problem” is that when I turn off manually the boiler, the automation cancel itself and run again just to pass the “choose” state and turn the boiler off

trigger:
  - platform: state
    entity_id:
      - input_boolean.bath
      - input_boolean.shower
condition: []
action:
  - type: turn_on
    device_id: 19df15442d27443fc8834099d46182b2
    entity_id: a9e8a51166181de47e05d8126293087b
    domain: switch
    enabled: true
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.bath
            state: "on"
            enabled: true
        sequence:
          - delay:
              hours: 0
              minutes: 20
              seconds: 0
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.bath
            enabled: true
      - conditions:
          - condition: state
            entity_id: input_boolean.shower
            state: "on"
            enabled: true
        sequence:
          - delay:
              hours: 0
              minutes: 10
              seconds: 0
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.shower
    enabled: true
  - type: turn_off
    device_id: 19df15442d27443fc8834099d46182b2
    entity_id: a9e8a51166181de47e05d8126293087b
    domain: switch
    enabled: true
mode: restart

When the automation starts and stop it manually

It doesn’t bother me much but it doesn’t seems right that way. Is there any way to turn it off manually and the automation don’t has to start again from the beginning? Probably I have to play with that template thing but I don’t understand this.

If i understand correctly you just want to trigger on “on” ?
So just add that as the state trigger:

trigger:
  - platform: state
    entity_id:
      - input_boolean.bath
      - input_boolean.shower
    to: "on"

Simply move the turn on action into the choose sequences, like this:

trigger:
  - platform: state
    entity_id:
      - input_boolean.bath
      - input_boolean.shower
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.bath
            state: "on"
            enabled: true
        sequence:
          - type: turn_on
            device_id: 19df15442d27443fc8834099d46182b2
            entity_id: a9e8a51166181de47e05d8126293087b
            domain: switch
            enabled: true
          - delay:
              hours: 0
              minutes: 20
              seconds: 0
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.bath
            enabled: true
      - conditions:
          - condition: state
            entity_id: input_boolean.shower
            state: "on"
            enabled: true
        sequence:
          - type: turn_on
            device_id: 19df15442d27443fc8834099d46182b2
            entity_id: a9e8a51166181de47e05d8126293087b
            domain: switch
            enabled: true
          - delay:
              hours: 0
              minutes: 10
              seconds: 0
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.shower
    enabled: true
  - type: turn_off
    device_id: 19df15442d27443fc8834099d46182b2
    entity_id: a9e8a51166181de47e05d8126293087b
    domain: switch
    enabled: true
mode: restart

Having said that, waiting in an automation for extended periods of time is never a good idea as it can be interrupted by restarts or reloads.

A better way would be to use timers as they survive restarts/reloads.

Start your timers and boiler when the input booleans turn on. Stop the boiler when the timers finish, or the input booleans are tuned off.

I did that but then it doesn’t catch the manual turn off

I tried that but its the same. It keeps cancel the automation and triggers it again just to turn off the boiler. The problem is with the service calls “off”.

As for the delays, I know that there may be an issue but it won’t make any problem for now. I will fix it sometime.

How else would it turn off?

By the time passed or by the switch. But when I turn it off by the switch, cancel the current run of the automation and run it again to bypass the choose options. Just like the photos with the timeline. They only have few seconds difference

Both of which you have to trigger the automation for to perform the off action.

I don’t see what the issue is?

OΚ maybe it’s not an issue after all. I thought it was weird that the automation has to stop when I turn off the switch and run again. Anyway, thank you for your time

It does not have to. You could do this: