Action not working but error msg impires it should be

What is wrong with this action? I only ask because the error implies it is all ok.

action:
    - delay: >
        value_template:
          {% if is_state('input_boolean.holiday_settings_lights', 'on') %}
            00:{{ "{:02d}".format(range(1, 2)|random|int) }}:{{ "{:02d}".format(range(0, 30)|random|int) }}
          {% endif %}
    - service: homeassistant.turn_on
      entity_id: switch.hall_light

Log Details (ERROR)

Thu Apr 12 2018 15:13:07 GMT+0100 (GMT Summer Time)

Error rendering 'Hall light on at dusk' delay template: offset value_template:

00:01:29 should be format 'HH:MM' or 'HH:MM:SS'

from the error message it would appear you’re missing a single quote around your delay:

{% if is_state('input_boolean.holiday_settings_lights', 'on') %}
            '00:{{ "{:02d}".format(range(1, 2)|random|int) }}:{{ "{:02d}".format(range(0, 30)|random|int) }}'
          {% endif %}

Yeah, I tried that too…
(The error looks even more strange!)

Log Details (ERROR)

Thu Apr 12 2018 16:11:06 GMT+0100 (GMT Summer Time)

Error rendering 'Hall light on at dusk' delay template: offset value_template:
  
    '00:01:10' should be format 'HH:MM' or 'HH:MM:SS'

It doesn’t look like there’s as a value / value_template for a delay.
Have you tried:

    - delay: >
        '{% if is_state('input_boolean.holiday_settings_lights', 'on') %}
            00:{{ "{:02d}".format(range(1, 2)|random|int) }}:{{ "{:02d}".format(range(0, 30)|random|int) }}
          {% endif %}'

Brilliant! Thank you very much, that worked (but I removed the single quotes you have around the entire statement).

1 Like

Oh dear, I spoke too soon. For some reason it doesn’t work after all.

Edit: I think it needed an ‘else’. (Not sure if 00:00:00 would have been valid)

{% if is_state('input_boolean.holiday_settings_lights', 'on') %}
  00:{{ "{:02d}".format(range(1, 14)|random|int) }}:{{ "{:02d}".format(range(0, 59)|random|int) }}
{% else %}
  00:00:01
{% endif %}

  action:
    # delay a random amount of time between 1 and 15 minutes if on holiday 
    - delay: >
        {% if is_state('input_boolean.holiday_settings_lights', 'on') %}
          00:{{ "{:02d}".format(range(1, 14)|random|int) }}:{{ "{:02d}".format(range(0, 59)|random|int) }}
        {% endif %}
    - service: homeassistant.turn_on
      entity_id: switch.dining_room_light

Slightly different error.

Log Details (ERROR)

Thu Apr 12 2018 21:15:30 GMT+0100 (GMT Summer Time)

Error rendering 'Dining room light on at dusk if someone is home' delay template: offset should be format 'HH:MM' or 'HH:MM:SS'

yes that makes sense, a delay needs a value, so you would need the else statement…