How to use different time trigger in different situation/season

I want to change the water in my fish tank at different times in different season. I want the automation to trigger at 23:00 in summer and autunm, at 13:00 in winter and spring. I’ve tried the following code but it didn’t work. I can’t find the reason. Could you please give me some help? Thanks very much.

  - alias: fishtank_change_water_auto
    trigger: 
      platform: time
      at: >-
        {% if now().month in (6,7,8,9,10,11) %}
          23:00:00
        {% elif now().month in (12,1,2,3,4,5) %}
          13:00:00
        {% endif %}

But I got the following error message:

Invalid config for [automation]: Expected HH:MM, HH:MM:SS or Entity ID with domain 'input_datetime' or 'sensor' @ data['at'][0]. Got None. (See ?, line ?).

I’ve also tried to add quotation marks to the time format. It didn’t work either.

  - alias: fishtank_change_water_auto
    trigger: 
      platform: time
      at: >-
        {% if now().month in (6,7,8,9,10,11) %}
          '23:00:00'
        {% elif now().month in (12,1,2,3,4,5) %}
          '13:00:00'
        {% endif %}

I just can’t figure out what’s wrong with my code. I’ll appreciate if you can point out my mistake. Thanks!

I can’t see what is wrong.
The only thing I see is the - missing before platform.
But I think that is optional if you only have one trigger so it shouldn’t be that.

Another method is to trigger twice a day then have a choose with template to split the automation in the action instead.

Thanks for your prompt reply. I’m using two automation instants as you suggest, but I still want to make them one if possible. Hyphen is not necessary as you say if there is only one trigger. I have other automation instants that work well without it. It looks quite straight forward but I just can’t find out the reason. I think it’s probably because “at” doesn’t support template.

I don’t know if it supports sensor states.
I know you can use an input datetime as at, but the yaml you have would be nice to have in a template sensor and trigger on that.
It says in the docs that only input datetimes work but wonder if it’s limited to it, or what happens if you force a sensor in there.

I didn’t mean to have two automations. I meant something like:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: time
    at: '13:00:00'
    id: early
  - platform: time
    at: '23:00:00'
    id: late
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: late
          - condition: template
            value_template: '{{ now().month in (6,7,8,9,10,11) }}'
        sequence:
          - service: notify.notify
            data: {}
      - conditions: 
          - condition: trigger
            id: early
          - condition: template
            value_template: '{{ now().month in (12,1,2,3,4,5) }}'
        sequence: 
          - service: notify.notify
            data: {}
    default: []

Hi Hellis81, thank you so much! You solve my problem and show me how to use choose in action. It’s the first time I use this feature. Thanks and have a nice day!

1 Like