The goal is to turn off a light after x minutes depending on the time of day. Between 00h and 06h I’d like the delay to be 3 minutes and 30 minutes the rest of the time.
I have a script that turn off the light after a fix time, that work fine.
It’s the dynamic delay that I cannot get working.
Invalid config for [script]: expected int for dictionary value @ data['script']['timer_off']['sequence'][0]['delay']['minutes']. Got '{ % if now().hour < 6 % }3{ % else % }30{ % endif% }'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/script/
timer_off: [source /config/packages/white_led_strip.yaml:66]
alias: Turn off lamp after 20 minutes
sequence: [source /config/packages/white_led_strip.yaml:68]
- delay: [source /config/packages/white_led_strip.yaml:69]
minutes: { % if now().hour < 6 % }3{ % else % }30{ % endif% }
I also tried without the ' but got:
17-02-27 15:34:43 ERROR (Thread-1) [homeassistant.util.yaml] while scanning for the next token
found character '%' that cannot start any token
in "/config/packages/white_led_strip.yaml", line 70, column 22
17-02-27 15:44:29 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [script]: expected int for dictionary value @ data['script']['timer_off']['sequence'][0]['delay']['minutes']. Got '{% if now().hour < 6 %}3{% else %}30{% endif %}'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/script/
17-02-27 15:48:28 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [script]: expected int for dictionary value @ data['script']['timer_off']['sequence'][0]['delay']['minutes']. Got '{{% if now().hour < 6 %}3{% else %}30{% endif %}}'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/script/
timer_off:
alias: "Turn off lamp after 20 minutes"
sequence:
- delay: '00:{{% if now().hour < 6 %}3{% else %}30{% endif %}}:00'
and got:
17-02-27 15:52:42 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [script]: [delay] is an invalid option for [script]. Check: script->script->timer_off->sequence->0->delay. (See ?, line ?). Please check the docs at https://home-assistant.io/components/script/
I’ll try with the new spacing
EDIT: with the new spacing: - delay: '00:{{% if now().hour < 6 %} 3 {% else %} 30 {% endif %}}:00'
17-02-27 15:55:10 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [script]: [delay] is an invalid option for [script]. Check: script->script->timer_off->sequence->0->delay. (See ?, line ?). Please check the docs at https://home-assistant.io/components/script/