Automation to turn fan on and off during summer months

alias: Garage Fan
description: Runs at night during summer
trigger:
  - platform: time
    at:
      - "01:00:00"
      - "05:00:00"
condition:
  - condition: template
    value_template: "{{ now().month >= 4 or now().month <= 10 }}"
action:
  - target:
      device_id: 3ba7186ea35512381ec31e92ba1400e7
    data: {}
    action: switch.turn_{{ 'on' if now().hour == 20 else 'off' }}

according to the logs this triggers as ‘last seen’ but the device does not seem to be turning on.

maybe i have the months in the wrong order? YAML looks weird to me as i typically think of an SBC as a small block chevy, not a single board computer.

What does testing with run have for results for your logic? Screen captures can be paste using the graphics icon to the right of </> sign

the ‘run’ and ‘run actions’ items do not appear to do anything. i am sure the output is in some screen i have not stumbled across yet, and googling with those common words is unhelpful.

Let me summarize the logic in the automation currently:

  1. Trigger at 1:00am and again at 5:00am every day.
  2. Check if the numeric month is greater or equal to 4, or less than or equal to 10. The result will always be true because every real number meets one of those two conditions.
  3. Turn on the switch only if it is between 8:00pm-8:59pm, which it will not be. So instead, turn off the switch.

You should be able to look at the traces of the automation to confirm this is what is happening. Click the 3 dots to the right of the automation and select “traces”.

what i want is for it to run between 1a.m. and 5a.m. every night of April through October. are these things stackable?

That is where I was heading the conversation, I was hoping the OP would screen capture the trace results.

I think it’s only the last line you need to change.

action: switch.turn_{{ 'on' if now().hour == 1 else 'off' }}

I think @Hellis81 is correct: currently it will only trigger at 1am (01:00) and 5am (05:00), but then it will only turn on at 8pm (20:00). Since it never triggers at 8pm, it will never turn on. The traces should show it only does “off” each time.
-David

i tried changing the 20 thinking that it was a time reference but got an error when saving…
apparently YAML wants time as ‘1’ in this location not ‘01’

how do those look?

The time on the screenshot indicates that you are running the automation by forcing it to run.
This automation will not work that way. It should only run by itself.

yes, i was basically just making sure i was error free and trying to get the time change to show, as i had just made the change.

it should work tonight as it is now?

Why don’t you use 2 triggers with ID?
This way you have an automation with a trigger at 1:00 to turn on and another at 5:00 to turn off

You need to change this line too:

    value_template: "{{ now().month >= 4 and now().month <= 10 }}"

Another way to do the same thing.

alias: Garage Fan
description: Runs at night during summer
trigger:
  - id: 'on'
    platform: time
    at: "01:00:00"
  - id: 'off'
    platform: time
    at: "05:00:00"
condition:
  - condition: template
    value_template: "{{ 4 <= now().month <= 10 }}"
action:
  - action: "switch.turn_{{ trigger.id }}"
    target:
      device_id: 3ba7186ea35512381ec31e92ba1400e7

i R t3h n00b?!?

to what? that is the same line twice? or i am dyslexic (i am)

oooh this one is borderline id10t understandable. i will try.

THANKS ALL

You missed the “or” to “and”.
But Taras put it all together

1 Like