Date Time Helper as Time Condition

Hi there,

I want to play a certain radio when Christmas is around. Playing with the date helpers but it doesn’t work, it always return true.

condition: time
after: input_datetime.christmas_time_start
before: input_datetime.christmas_time_end

So, how can I make it work that it only works between those two dates.

Thanks in advance.


https://www.home-assistant.io/docs/scripts/conditions/#time-condition

You will have to use a template condition.

Thanks for your quick reply.

So, something like this would work in my case:

condition:
  alias: "Christmas"
  condition: template
  value_template: "{{ (state_attr('input_datetime.christmas_time_start', 'timestamp')|int) > 
   (state_attr('input_datetime.christmas_time_end', 'timestamp')|int) }}"

Try this:

  condition: template
  value_template: "{{ state_attr('input_datetime.christmas_time_start', 'timestamp') < now().timestamp() < state_attr('input_datetime.christmas_time_end', 'timestamp') }}"
1 Like

Yes, this seems to work. Thanks a lot!

2 Likes