Ideas to override a ceiling fan automation

I’m looking for some ideas to include an override in my ceiling fan automation(s) so that when I manually adjust my ceiling fan through lovelace or voice commands, the automatic function stops for a few hours using a timer helper. I have this kind of thing working on a bunch of other automations, but those are all triggered either by buttons or scripted voice commands. So I control the input on those and know when they fire. Something like this though, where I might just use a fan card to adjust speed and on/off or through impromptu voice commands is throwing me for a loop.

I’ve thought about an input_boolean to use as a condition, but I’m struggling on where to actually flip it since my automation sets the fan on/off and sets fan speed as well. So, I don’t think I could use those as triggers or conditions unless I can determine the source of the incoming command and maybe condition off that in another automation. :thinking:

Any ideas?

alias: Living Room Ceiling Fan Manager
description: "Controls the living room ceiling fan so that it comes on in the morning at low speed, but adjusts to high speed when the temperature outside rises above 73 degrees."
trigger:
  - platform: state
    entity_id:
      - binary_sensor.mode_manager_morning
    from: "off"
    to: "on"
    id: morning_mode_on
  - platform: state
    entity_id:
      - sensor.weather_station_pro_sensor_temperature
    id: temp_change
    alias: When the outside temperature changes
  - platform: state
    entity_id:
      - input_boolean.good_night
    from: "off"
    to: "on"
    id: good_night
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - morning_mode_on
        sequence:
          - alias: Set the fan to low speed
            service: fan.turn_on
            metadata: {}
            data:
              percentage: 10
            target:
              entity_id:
                - fan.living_room_ceiling_fan
        alias: Morning mode turns on
      - conditions:
          - condition: trigger
            id:
              - temp_change
        sequence:
          - alias: If not in good night mode
            if:
              - condition: state
                entity_id: input_boolean.good_night
                state: "off"
            then:
              - alias: If the outside temp is at or above 73
                if:
                  - condition: state
                    entity_id: binary_sensor.outside_temperature_at_or_above_73
                    state: "on"
                then:
                  - alias: Set the fan to high speed
                    service: fan.turn_on
                    metadata: {}
                    data:
                      percentage: 80
                    target:
                      entity_id:
                        - fan.living_room_ceiling_fan
                else:
                  - alias: Set the fan to low speed
                    service: fan.turn_on
                    metadata: {}
                    data:
                      percentage: 10
                    target:
                      entity_id:
                        - fan.living_room_ceiling_fan
        alias: Outside temp changes
      - conditions:
          - condition: trigger
            id:
              - good_night
        sequence:
          - alias: Turn off the fan
            service: fan.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - fan.living_room_ceiling_fan
        alias: Good night switch turns on
mode: restart

one approach is to use a number helper. pick a value like -1 to means use automatic mode. Then in Lovelace or voice set this number. this number is the override. when it changes set the fan to this helper number value if it != -1.

In this automation you have, set the value as you have it unless the helper != -1.

reset the helper to -1 after your chosen timeout.

I think you are having challenges because you are trying to allow the direct manipulation of the fan speed in the ui

2 Likes

Yeah, I think this might be the way to go. I’m going to try the input_number helper method now and see what I can get away with.

If that doesn’t work, then I’ll probably just resort to having an override button on the dashboard and in Alexa that I have to remember to trigger first to override the automation and start a timer.

I do wonder if there is a way I could trigger off the event of the fan service and see what actually triggered it. :thinking: That would easily solve this.

LOL yeah. Never expect me to do things the easy way. There are times when it may be warm/hot outside and I don’t want the fan blowing at 80%, so I just bark at the Alexa to turn the fan down or off. But then, the automation kicks in and says “nope, you take what I give you”. This is what I get for wanting a smart home that is reactionary. :rofl:

One instance where it was almost impossible to untangle I reversed the approach: the automated behavior sets a short timer. When the state change takes place, there is an if to see if the timer is running. If not, it must be manual.

1 Like

Ooooohhhhh so short-circuiting the automation using a timer? I like that idea too!

I’m confident the input_number will work. I have something similar.

another approach is to have a time/schedule of what you want it to be. and whenever it isn’t what you expect, presume it’s an override.

If you prefer that approach, we can make that happen… but would be easier for me to code it than explain it… so id do it when I’m not on mobile. let me know… happy to do that.

2 Likes

TBH, I kinda like the timer/schedule override approach better. I’d love to see what you can come up with (and thanks also to @Edwin_D for the idea as well).

You guys are awesome.

2 Likes

ok… caveat, i’m on the road, and i didn’t test this, but you’re good enough at this that i hope the framework is enough. here’s the trigger automation. i’m putting the setting of state into a script. for this purpose i’m using the setting of one of my lights that you should switch to your fan.

trigger:
  - platform: state
    entity_id:
      - binary_sensor.test_times_of_day_daytime
      - binary_sensor.test_times_of_day_night_time
    to: "on"
    id: scheduled_change
  - platform: state
    entity_id:
      - light.study_lights_2
    id: override
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.test_fan_schedule_override
    id: manual_override_end
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - scheduled_change
        sequence:
          - if:
              - condition: state
                entity_id: timer.test_fan_schedule_override
                state: idle
            then:
              - service: script.test_set_fan_to_schedule
      - conditions:
          - condition: trigger
            id:
              - manual_override_end
        sequence:
          - service: script.test_set_fan_to_schedule
      - conditions:
          - condition: trigger
            id:
              - override
        sequence:
          - service: timer.start
            target:
              entity_id: timer.test_fan_schedule_override

here’s the script.test_set_fan_to_schedule:

alias: test set fan to schedule
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.test_times_of_day_daytime
            state: "on"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 25
            target:
              entity_id: light.study_lights_2
      - conditions:
          - condition: state
            entity_id: binary_sensor.test_times_of_day_night_time
            state: "on"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 57
            target:
              entity_id: light.study_lights_2
    default:
      - service: script.debugmsg
        data:
          debugtrace: for_bill
          message: this should never happen
          title: fset fan schedule default case

here are my two helper schedules (which you could hard code into the script above instead of using helpers of course)


1 Like

while writing that code, i think i concluded that the input_number override approach has higher code beauty… but i didn’t want to abandon what i was doing… but beauty’s in the eye of the beholder…

1 Like

That’s a bold assumption there. :joy:

You are a rock star! I’ll get something whipped up here shortly. It just occurred to me that I can use my TOD sensors instead of schedules perhaps (I have 5 different TOD sensors that emulate modes (old carry over logic from SmartThings :see_no_evil:) and can probably leverage them in a couple of templates.

I’ll let you know how I get on with it and HUGE thanks for the code.