How to compare current time?

Hello,

I’m trying to use the current time in a data_template, without any luck. I guess the compare expression is wrong but I can’t find what should return now().

- alias: Chambre Parents Allume Lumière si Présence
  trigger:
    platform: state
    entity_id: sensor.aeotec_zw100_multisensor_6_burglar_2_10
    from: '0'
    to: '8'
  condition:
    condition: sun
    after: sunset
    after_offset: "-00:30:00"
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.homeseer_hswd100_wall_dimmer_level_3_0
        brightness: >
          {% if now() <= '22:00:00' %}
             255
          {% else %}
             100
          {% endif %}

Here’s some code that might help you:

https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/script/voice_notify.yaml

Down toward the bottom. You can’t compare time to a string.

Thank you. That did the trick.

Is there a way to know the output format of a function? documentation or screen output?

Not that I know of. I just hack at it. :slight_smile: Glad the automation helped you along.

Yeah, if you were to put {{now()}} into the template editor in the dashboard you should see the string version of the timestamp. I believe they are actually some sort of datetime object, so that’s why your compare to a string wouldn’t work.

From documentation

datetime.strftime(format)
Return a string representing the date and time, controlled by an explicit format string. For a complete list of formatting directives, see section strftime() and strptime() Behavior.

So you can see using that, the datetime object is converted to a string using a format, in @CCOSTAN example he just uses %H which extracts the hour, and then he converts that to an int.

thank you for the tip!