Fan automation with input boolean: how to let an automation don't trigger the input boolean (only by manual changes)?

So I have a Fan that I automate via Wifi (Wemos D1 Mini with ESPHome). It’s all working perfectly expect for the deprecated fan_speed setting, but that’ another story.

So I want to trigger the Fan at midnight (00:00) and in the morning (08:00). At midnight, speed should go back to 1 (0% - ‘off’) and in the morning speed should go to 2 (33%). These times also turn the Automatic Fan Mode input boolean to on. I also have an input boolean that triggers once I make adjustments to the state_attribute: percentage i.e. I make manual adjustments. The input boolean Automatic Fan Mode will then turn off.

So now comes the tricky part, but maybe easy for you guys: because at midnight and in the morning the automations for the fan percentage are triggered, the input boolean will turn off. I now workaround that in my automation to wait 1 second and then turn the input boolean back on. But I don’t like this, and since I like dabbling in YAML, there should be a cleaner way right?

Is there a way to incorporate the automation to ONLY trigger by adjusting myself and not to trigger when an automation changes the fan percentage?

This is my YAML for my input boolean automation:

---
# Automation to automatically start fan at certain times.
# Resets itself at midnight if input_boolean is overriden.
# Sets midnight and morning speed.
# 
alias: "Fan Automatic Mode off"
id: "fan_automatic_mode_off"
mode: single
trigger:
  platform: state
  entity_id: fan.zehnder_e300
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: input_boolean.automatic_fan_mode
      state: "on"
    - condition: or
      conditions:
      - condition: state
        entity_id: fan.zehnder_e300
        state: "off"
      - condition: template
        value_template: >
          {{ trigger.from_state and trigger.to_state.attributes.percentage != trigger.from_state.attributes.percentage }}
action:
  - alias: "Turn Automatic Fan Mode off"
    service: input_boolean.turn_off
    target:
      entity_id: input_boolean.automatic_fan_mode

And here is the automation for the fan percentages at midnight and in the morning:

---
# Automation to set the fan to speed 1 at night or speed 2 in the morning
# depends on input_boolean
# 
alias: "Fan speed 1 (midnight) and Fan speed 2 (morning)"
id: fan_midnight_morning
mode: restart
trigger:
  platform: time
  at: 
    - input_datetime.midnight # Triggers at 00:00
    - input_datetime.morning # Triggers at 08:00
condition:
  alias: "Input Boolean Automatic Fan Mode on"
  condition: state
  entity_id: input_boolean.automatic_fan_mode
  state: "on"  
action:
  choose:
    - conditions:
        - alias: "Wait till midnight"
          condition: time
          after: input_datetime.midnight
          before: input_datetime.morning

      sequence:
        - alias: "Set fan speed to 1"
          service: fan.set_percentage
          target:
            entity_id: fan.zehnder_e300
          data:
            percentage: 0
        
        - delay: 1
        - alias: "Turn Input Boolean back on"
          service: input_boolean.turn_on
          target:
            entity_id: input_boolean.automatic_fan_mode

    - conditions:
        - alias: "Wait till morning"
          condition: time
          after: input_datetime.morning
          before: input_datetime.midnight

      sequence:
        - alias: "Set fan speed to 2"
          service: fan.set_percentage
          target:
            entity_id: fan.zehnder_e300
          data:
            percentage: 33

        - delay: 1
        - alias: "Turn Input Boolean back on"
          service: input_boolean.turn_on
          target:
            entity_id: input_boolean.automatic_fan_mode
1 Like

If people will read this, I figured it out as follows:

---
# Automation to override Automatic Mode
# 
alias: "Fan: Automatic Mode off"

id: fan_automatic_mode_off

mode: single

trigger:
  - platform: state
    entity_id: fan.zehnder_e300

condition:
  - alias: "Automatic Mode is on and Fan is off or is manually triggered"
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.fan_automatic_mode
        state: "on"

      - condition: or
        conditions:
        - condition: state
          entity_id: fan.zehnder_e300
          state: "off"

        - condition: template
          value_template: >
            {{ trigger.to_state.context.user_id != None }}

action:
  - alias: "Turn off Automatic Fan Mode"
    service: input_boolean.turn_off
    target:
      entity_id: input_boolean.fan_automatic_mode

  - alias: "Notify devices"
    service: notify.justin
    data:
      title: "Fan"
      message: "Automatic Mode is turned off."

And to activate it again:

---
# Automation to set the fan to speed 1 at night or speed 2 in the morning
# 
alias: "Fan: Set speed in morning and at midnight"

id: fan_midnight_morning

mode: restart

trigger:
  - platform: time
    at: 
      - input_datetime.midnight
      - input_datetime.morning

condition:
  - alias: "Automatic Mode is on"
    condition: state
    entity_id: input_boolean.fan_automatic_mode
    state: "on"

action:
- alias: "Actions on certain times"
  choose:
    - conditions:
        - alias: "Wait till midnight"
          condition: time
          after: input_datetime.midnight
          before: input_datetime.morning

      sequence:
        - alias: "Set fan speed to 1"
          service: fan.set_percentage
          target:
            entity_id: fan.zehnder_e300
          data:
            percentage: 0

        - alias: "Notify devices"
          service: notify.justin
          data:
            title: "Fan"
            message: "Fan speed is set to 1."

    - conditions:
        - alias: "Wait till morning"
          condition: time
          after: input_datetime.morning
          before: input_datetime.midnight

      sequence:
        - alias: "Set fan speed to 2"
          service: fan.set_percentage
          target:
            entity_id: fan.zehnder_e300
          data:
            percentage: 33

        - alias: "Notify devices"
          service: notify.justin
          data:
            title: "Fan"
            message: "Fan speed is set to 2."