Automation time condition template

Hello, I need some help to configure a more complexe automation.
I need to trig several time and have conditions.

Basicaly, its’

alias: "test"
trigger:
  - platform: time
    at: "10:37:00"
    
  - platform: time
    at: "10:38:00"
    
  - platform: time
    at: "10:39:00"
    
  - platform: time
    at: "10:40:00"
   
  - platform: time
    at: "10:41:00"
    
  - platform: time
    at: "10:42:00"
    
condition:  
        - condition: template
          value_template:  "{{ (is_state('sensor.time','10:37:00')) or 
                               (is_state('sensor.time','10:38:00')) or 
                               (is_state('sensor.time','10:39:00')) or
                               (is_state('sensor.time','10:40:00')) or
                               (is_state('sensor.time','10:41:00')) or
                               (is_state('sensor.time','10:42:00'))  }} "
    
action:

- service: notify.email
  data:
      title: "Home assistant info"
      message: "Test. Trigger: {{trigger.entity_id}}" 

The action is never fired.
Can any body correct me ?

Many thanks in advance !
Regards

Hello tom_1, thanks to reply.

The goal of my automation is to enhance the thermostat behavior.
I want to start it eary, depending of time and temperature.

I have several time and temperature points and if for a given time the temperature is below his point I want to start the heater

Basically, there is one trigger every 30 minutes from 5:00 until 8:00
Conditions for firing action only if for a given time the temperature is below the level.

Sorry for my bad English…

Regards

Hello,
you means no trigger part ?

Your suggestion is the same as my post isn’t it ?

This automation never fire…

Sorry if I don’t understand…

It never fire.
to be sur, here is my automation:

alias: "test"
trigger:
  - platform: time
    at: "11:57:00"
    
  - platform: time
    at: "11:58:00"
    
  - platform: time
    at: "11:59:00"
    
  - platform: time
    at: "12:00:00"
   
  - platform: time
    at: "12:01:00"
    
  - platform: time
    at: "12:02:00"
    
condition:  
        - condition: template
          value_template:  "{{ is_state('sensor.time','11:57:00') or 
                               is_state('sensor.time','11:58:00') or 
                               is_state('sensor.time','11:59:00') or
                               is_state('sensor.time','12:00:00') or
                               is_state('sensor.time','12:01:00') or
                               is_state('sensor.time','12:02:00') }} "
    
action:

- service: notify.email
  data:
      title: "Home assistant info"
      message: "Test. Trigger: {{trigger.entity_id}}" 
       
         

Regards

The automation is triggered at the specified time(s) but the condition blocks execution of the action. Why? Because the condition compares sensor.time to a string contains hours, minutes and seconds. However sensor.time has a value containing only hours and minutes.

Screenshot from 2020-11-13 12-14-39

Either remove the seconds portion of the time in the condition (like in tom_I’s example) or, even better, remove the entire condition because it serves no useful purpose.


EDIT

Use this for experimentation:

alias: "test"
trigger:
- platform: time
  at: 
    - "10:37:00"
    - "10:38:00"
    - "10:39:00"
    - "10:40:00"
    - "10:41:00"
    - "10:42:00"
action:
- service: persistent_notification.create
  data:
    title: "{{now().timestamp()|timestamp_local()}}"
    message: "Test. Trigger: {{trigger.now}}" 

In your example, you used {{trigger.entity_id}} however a Time Trigger does not have an entity_id.

What it does have is trigger.now which is a datetime object. For example trigger.now.hour and trigger.now.minute return the hour and minute when the trigger occurred.

How sorry!
So I understand time return hour and time.

The condition as to check for every point in the curve if for y given time the temperature is below the point I fixed.
Now the script is:

alias: "test"
trigger:
  - platform: time
    at: "12:49:00"
    
  - platform: time
    at: "12:50:00"
    
  - platform: time
    at: "12:51:00"
    
  - platform: time
    at: "12:52:00"
   
  - platform: time
    at: "12:53:00"
    
  - platform: time
    at: "12:54:00"
    
condition:  
        - condition: template
          value_template:  "{{ is_state('sensor.time','12:49') or 
                               is_state('sensor.time','12:50') or 
                               is_state('sensor.time','12:51') or
                               is_state('sensor.time','12:52') or
                               is_state('sensor.time','12:53') or
                               is_state('sensor.time','12:54') }} "
    
action:

- service: notify.email
  data:
      title: "Home assistant info"
      message: "Test." 

and still never fire…
Many thanks for your help.

That should fire (it does for me) but note that sensor.time might not yet have updated when it fires so the sensor could still be 12:49 when it fires at 12:50:00. Better to use e.g. trigger.now like Taras said.

hmm.
I tested the automation I copy and it never fire…

Can you please write an example with trigger.now in a condition part ?

Many thanks for your help.

You have created an automation that triggers at 12:50:00 and then the condition checks if the automation triggered at 12:50. Why? In this particular case, I can’t think of a good reason to double-check the trigger time like that. What’s your reason?

the reason is:
Effectively there is fiew trigger time based from 5:00 to 8:00
The goal is to start the heater.
But, when one of time conditions is ok, I have to check what time is it to check the temperature value:

at 5:30 if the temperature is below 17,5 or
at 6h if the temperature is below 18 or

The original script is hre (not working):

# La temperature en chauffage monte d'environ 1,13 degré par heure si la cuisine ou le salon chauffe
alias: "cuisine thermostat amelioration"
trigger:
  - platform: time
    at: "07:30:00"
    
  - platform: time
    at: "07:00:00"
    
  - platform: time
    at: "06:30:00"
    
  - platform: time
    at: "06:00:00"
   
    
  - platform: time
    at: "05:30:00"
    
  - platform: time
    at: "05:00:00"
   
      
condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.save_electricity
          state: 'off'
        - condition: state
          entity_id: input_boolean.home_presence_state
          state: 'on'
        
        - condition: template
          value_template:  "{{ (is_state('sensor.time','07:30') and states('sensor.dining_room_temp')|float < 19.5) or 
                               (is_state('sensor.time','07:00') and states('sensor.dining_room_temp')|float < 19) or 
                               (is_state('sensor.time','06:30') and states('sensor.dining_room_temp')|float < 18.5) or
                               (is_state('sensor.time','06:00') and states('sensor.dining_room_temp')|float < 18) or
                               (is_state('sensor.time','05:30') and states('sensor.dining_room_temp')|float < 17.5) or
                               (is_state('sensor.time','05:00') and states('sensor.dining_room_temp')|float < 17) }} "
         
     
action:
  - service: climate.set_hvac_mode
    entity_id: climate.neviweb_climate_salle_a_manger
    data:
          hvac_mode: "heat"
          
  - service: climate.set_temperature
    entity_id:  climate.neviweb_climate_salle_a_manger
    data:
          temperature: 20
          
  - service: notify.email
    data:
      title: "Home assistant info"
      message: "Demarrage anticipe du chauffage de la cuisine. Trigger: {{trigger.entity_id}}" 

  - delay: '00:30:00'
  
  - service: climate.set_hvac_mode
    entity_id: climate.neviweb_climate_salle_a_manger
    data:
          hvac_mode: "auto" 
  
  - service: notify.email
    data:
      title: "Home assistant info"
      message: "Chauffage de la cuisine remi en mode auto"
  

It’s a curve with fiew points
If the temperature is below one point I start the hvac for 30 minutes and back in auto mode.
Many thanks for your help
Regards

Try this:

# La temperature en chauffage monte d'environ 1,13 degré par heure si la cuisine ou le salon chauffe
alias: "cuisine thermostat amelioration"
trigger:
  - platform: template
    value_template: >
      {% set t = states('sensor.time') %}
      {% set temp = states('sensor.dining_room_temp')|float %}
      {{ (t == '07:30' and temp < 19.5) or 
         (t == '07:00' and temp < 19) or 
         (t == '06:30' and temp < 18.5) or
         (t == '06:00' and temp < 18) or
         (t == '05:30' and temp < 17.5) or
         (t == '05:00' and temp < 17) }} 
condition:
  - condition: state
    entity_id: input_boolean.save_electricity
    state: 'off'
  - condition: state
    entity_id: input_boolean.home_presence_state
    state: 'on'
action:
  - service: climate.set_hvac_mode
    entity_id: climate.neviweb_climate_salle_a_manger
    data:
      hvac_mode: "heat"
  - service: climate.set_temperature
    entity_id:  climate.neviweb_climate_salle_a_manger
    data:
      temperature: 20
  - service: notify.email
    data:
      title: "Home assistant info"
      message: "Demarrage anticipe du chauffage de la cuisine. Trigger: {{trigger.entity_id}}" 
  - delay: '00:30:00'
  - service: climate.set_hvac_mode
    entity_id: climate.neviweb_climate_salle_a_manger
    data:
      hvac_mode: "auto" 
  - service: notify.email
    data:
      title: "Home assistant info"
      message: "Chauffage de la cuisine remi en mode auto"
1 Like

Wahouh !!!

Many thanks for your help !

I will try and keep you in touch.

Many thaks for your help !

Best regards !

I am sorry Taras, but your suggestion doesn’t work
I try this simplified automation and still never fire:

alias: "test"
trigger:
   - platform: template
     value_template: >
      {% set t = states('sensor.time') %}
     
      {{ (t == '09:46' ) or 
         (t == '09:47' ) or  
         (t == '09:48' ) }} 
    
action:

- service: notify.email
  data:
      title: "Home assistant info"
      message: "Test." 

Many thanks for your help
Regards

It does work. The problem is your example doesn’t pass Configuration > Server Controls > Check Configuration:

Screenshot from 2020-11-14 10-06-48

Fix the template’s indentation.

Here’s my version of your example and it passes Check Configuration and works properly.

  alias: "test"
  trigger:
  - platform: template
    value_template: >
      {% set t = states('sensor.time') %}
      {{ (t == '10:13' ) or 
          (t == '10:15' ) or  
          (t == '10:17' ) }} 
  action:
  - service: persistent_notification.create
    data:
      title: "Home assistant info"
      message: "Test." 

Screenshot from 2020-11-14 10-16-02

hmm,.
I am so sorry, but for me it doesnt work !

I copy past and change the time.
Verify the syntax using h.a tool
reload automations
test with developpement tool manual executing .

but still doesn’t work

check the time displayed on the hmi: correct !

What can cause this automation doesn’t fire ???

I try this automation, it fire but doesn’t print the t value.

alias: "test"
trigger:
  - platform: template
    value_template: >
      {% set t = states('sensor.time') %}
      {{ (t == '10:52' ) or 
          (t == '10:53' ) or  
          (t == '10:54' ) }} 
  - platform: time
    at: "10:52:00"        
    
action:
  - service: persistent_notification.create
    data:
      title: "Home assistant info"
      message: "Test at: {{t}}"

Can you help me to print the value of t ?
in the logbook, it is: “time triggered by time”

Thanks for your patience…

Like you did it, the t only exists inside the value template of the trigger, it’s not available to the action.

Ok thanks you.
Can you do hypothesis why the trigger based on t variables doesn’t fire (for my station)??

Did you setup the time sensor? Do you have sensor.time when you go to Developer Tools -> States?

When you go to Developer Tools -> Templates and enter the following (replace 10:52 with the current time)

{{ states('sensor.time') == '10:52' }}

does it show True?

sensor ‘time’ was not declared in configuation.yaml

I am so sorry !

Many thanks for your help !