Would somebody walk me through an automation to set a timer for a fan?

Hi,

I’ve read through the documentation on there Jason page and some of the example configurations on github, but I can’t figure out how to make an automation/script for a fan.

I wanted to make a timer for an exhaust fan I have when soldering in my workshop. I want to be able to input a timer on a slider that will turn on a fan does said time. I can understand creating the sliders, but how do you pass the intended timer time and switch back to ha?

Thanks,

Hello again,

Could someone please look over this configuration for me? I am getting an error on bootup of HA for the automatoin I am trying to create:

16-06-27 17:03:15 homeassistant.bootstrap: Invalid config for [script]: expected int for dictionary value @ data[‘script’][‘mancavefantimer_off’][‘sequence’][0][‘delay’][‘minutes’]

And this is what my configuration looks like (all are in their own .yaml file).

automation.yaml

- alias: 'Man Cave Fan Timer' trigger: platform: state entity_id: input_boolean.fantimer state: 'on' action: service: script.mancavefantimer_on

input_slider.yaml

mancavefantimer:
name: Minutes
icon: mdi:timer
initial: 5
min: 5
max: 60
step: 5

input_boolean.yaml

fantimer:
name: Fan Timer
initial: off
icon: mdi:fan

mancavefantimer_on.yaml script

sequence:

  • service: script.turn_off
    data:
    entity_id: script.mancavefantimer_off
  • service: switch.turn_on
    data:
    entity_id: switch.catfan
  • service: script.turn_on
    data:
    entity_id: script.mancavefantimer_off

    mancavefantimer_off.yaml script

    sequence:
  • delay:
    minutes: ‘{{ states.input_slider.mancavefantimer.state }}’
  • service: switch.turn_off
    data:
    entity_id: switch.catfan

Any help is greatly appreciated.

Thanks,

As far as I’m aware it’s not possible to anything other than a number.

This is also reflected by your error.
16-06-27 17:03:15 homeassistant.bootstrap: Invalid config for [script]: expected int for dictionary value @ data['script']['mancavefantimer_off']['sequence'][0]['delay']['minutes']

At the moment delay can only be an int.
it is on the do to list:
https://www.pivotaltracker.com/n/projects/1250084/stories/119160513

Ah, that explains a bit. Thanks for the information. There is no way to convert the number to an integer is there?

Thanks,

That is correct. I tried to do the same thing with a fan timer and found that it did not work. For now you just have to add the numbers of minutes as an integer.

Hopefully this feature gets added soon!

hi @Kip

Could you please post your configuration?

Thanks,

Sure thing:

script:
  fan_autooff_script:
    alias: "Automatically turn off fan"
    sequence:
      # Cancel old timers
      - service: script.turn_off
        data:
           entity_id: script.timed_fan_turnoff
      # Set new timer
      - service: script.turn_on
        data:
          entity_id: script.timed_fan_turnoff
  timed_fan_turnoff:
    alias: "Turn off fan after X minutes"
    sequence:
      - delay:
          minutes: 120 #{{states.input_slider.fanautooffslider.state}}
      - service: switch.turn_off
        data:
          entity_id: switch.linear_ws15z1_switch_4
input_boolean:
  fanautooff:
    name: "Turn Fan Off Automatically"
    initial: off
    icon: mdi:fan

And here’s the config from my automation file, I have a condition where it only actives the turn off timer if I have a boolean set to on:

- alias: "Auto turn fan off"
  trigger:
    platform: state
    entity_id: switch.linear_ws15z1_switch_4
    from: 'off'
    to: 'on'
  condition:
    condition: state
    entity_id: input_boolean.fanautooff
    state: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: script.fan_autooff_script

You can see in the one script I have a input slider that’s waiting to be used:

input_slider:
  fanautooffslider:
    name: "Fan Auto-Off Time"
    initial: 90
    min: 0
    max: 240
    step: 5
    icon: mdi:timelapse

Hi @Kip

Since 0.25 my script will turn on the fan I intended, but won’t turn off after xx minutes. Did you ever test your script to find out if it works now?

I have not tested it recently, this may be a rather dumb question but are you using the input_slider condition? If so, make sure it’s set to on (I have mine off by default).

I’ll give it a check tonight to see if it’s working still.

KIp

I assume it’s not working for you either?
I see it’s still an open action on https://www.pivotaltracker.com/n/projects/1250084/stories/119160513

Anyone have an alternative, can we mask the data somehow?
Rich

Hi Rich, sorry I forgot to get back to you. Yes it is working for me, I haven’t modified the code above in any way so not sure why it’s not working now for you.

Kip

Hi Kip, but your current code posted above: “minutes: 120 #{{states.input_slider.fanautooffslider.state}}”
equates to:
{
“minutes”: 120
}
It is not using the commented out code after the ‘#’.

Is there a later copy which you are using?

Rich

That it is correct, I’m still not using the commented out code. I haven’t kept up with the change logs recently to see if the ability to use sliders has been added yet.

Kip

Apparently it should work, the https://home-assistant.io/getting-started/scripts/ wiki has the example:
//Waits however many minutes input_slider.minute_delay is set to
//Valid formats include HH:MM and HH:MM:SS
delay: ‘00:{{ input_slider.minute_delay | int }}:00’

Which was merged on the 22nd July, in “Allow templates for script delay configuration sequence items #2560
https://github.com/home-assistant/home-assistant/pull/2560

However, there example fails:

homeassistant.exceptions.TemplateError: UndefinedError: ‘input_slider’ is undefined

Right, the example is wrong.

Here is the correct code:

delay: '00:{{ states.input_slider.minute_delay.state | int }}:00'

Rich

Brilliant!
I’m curious if

- delay:
          minutes: {{states.input_slider.fanautooffslider.state | int }}

would also work?! I’ll have to try it out.

Yes that should work. But I think you may be limited to 59 minutes maximum as the template effectively emulates the time code HH:MM:SS with MM being the variable we are changing by the slider. I’m not that deep enough into the code to look into this in more detail but I can see you there may be other ways to implement this.
Rich

hi @Kip and @Richard.Huish

I kind of forgot about this timer and never really got it working the way I wanted it to. I’ve been trying over the holiday break, and while I get no script errors I do not get the desired result I want. I have a slider and button set up to allow input of minutes and to turn on a fan, but it does not turn off after the delay(set by the slider) is up. Would you please take a look at my config and let me know where I am going wrong please?

input_boolean.yaml

  fantimer:
    name: Fan Timer
    initial: off
    icon: mdi:fan

input_slider.yaml

  mancavefantimer:
    name: Minutes
    icon: mdi:timer
    initial: 5
    min: 5
    max: 60
    step: 5

script (mancavefan.yaml (using includes in configuration.yaml file)

 timed_fan_turnoff:
   sequence:
     - delay: '00:{{ states.input_slider.mancavefantimer.state | int }}:00'
     - service: switch.turn_off
       entity_id: switch.catfan

and finally, the automation: (mancave.yaml)

- alias: 'Man Cave Fan Timer'
  trigger:
      platform: state
      entity_id: input_boolean.fantimer
      state: 'on'
  action:
    - service: script.turn_on
      entity_id: script.mancavefan
    - service: switch.turn_on
      entity_id: switch.catfan

Thanks for all the help so far!

I actually haven’t been able to get mine working either. It’s been fall/winter here though I so haven’t had need for the script and thus haven’t spent any time trying to figure it out.

Not sure if this is it but you may need to change your script to add the data line:

     - service: switch.turn_off
       data:
         entity_id: switch.catfan