mevellea
(Mevellea)
May 1, 2016, 10:53pm
1
Hello, I want to create a script with a configurable delay but I can’t figure out how to correctly define it.
I tried the following using templating:
countdown_run:
alias: 'Countdown running'
sequence:
- delay:
minutes: '{{states.input_select.timeout_delai.state|int}}'
...
But I end up with this error :
ERROR:homeassistant.bootstrap:Invalid config for [script]: expected int for dictionary value @ data[‘script’][‘countdown_run’][‘sequence’][0][‘delay’][‘minutes’]
Any idea ?
Thks!
balloob
(Paulus Schoutsen)
May 3, 2016, 2:32pm
2
We currently do not support templates in delays
I’d like this too, especially for parsing brightness values from an input_slider…
Just for the sake of it I am going to assume the typo is not in your actual config…right?
mevellea
(Mevellea)
May 7, 2016, 7:01am
5
Well I use to mix french and english in my code…
balloob
(Paulus Schoutsen)
May 9, 2016, 4:35am
6
I like the idea so I’ve added to pivotal . No timeline when it will be done…
2 Likes
Per4merKC
(John Edmonds)
August 23, 2017, 12:46am
7
I can’t believe this doesn’t have more votes. Having the ability to set values of delay with a template will make programming some events really easy. Imagine turning on a light with a motion detector and then turning it off after a programmable delay? You could have it turn off after 10 minutes in the morning and 3 minutes in the afternoon/evening.
For me personally, this would solve the issue of the lights turning off while I am in the shower and the motion detector can’t see me.
3 Likes
arsaboo
(Arsaboo)
August 23, 2017, 1:57am
8
Something like delay: '00:{{ (range(1, 55)|random|int) }}:00'
works. You can modify the same to your liking.
Per4merKC
(John Edmonds)
August 24, 2017, 1:37am
9
That may work, but I need it to be compared to time of day. I can’t get an “If” statement to be accepted in the delay: section.
sjee
August 24, 2017, 4:58am
10
I’m using this:
- delay: '00:{{ states.input_slider.light_timeout.state | int }}:00'
And if you need to compare it to a certain time frame just use conditions. If you want to go the ‘complicated’ way take a look at this: https://community.home-assistant.io/t/custom-component-to-declare-set-variables/25218?u=sjee
1 Like
Per4merKC
(John Edmonds)
August 25, 2017, 9:38pm
11
Thanks everyone. Ultimately this is what I came up with:
In my included sensor.yaml:
- platform: template
sensors:
bathroom_delay:
value_template: >
{% if (states.sensor.local_time.state > "05:00") and (states.sensor.local_time.state < "10:00") %}
15
{% else %}
5
{% endif %}
Then in my included script.yaml:
bathroom_motion_helper:
sequence:
- delay: "00:{{ states.sensor.bathroom_delay.state }}:00"
- service: light.turn_off
data:
entity_id: light.over_sink_light_53
bathroom_motion_timer:
sequence:
- service: script.turn_off
data:
entity_id: script.bathroom_motion_helper
- service: light.turn_on
entity_id: light.over_sink_light_53
- service: script.turn_on
data:
entity_id: script.bathroom_motion_helper
Finally in my automations.yaml:
- id: jwe001
alias: Bathroom Motion Detected
trigger:
- entity_id: binary_sensor.eye_motion_71
platform: state
from: 'off'
to: 'on'
action:
- alias: Turn on bathroom lights
service: script.bathroom_motion_timer
hide_entity: true
All the sensor created needs to be hidden from the interface and would not be necessary if we had a delay_template option.
petr
April 3, 2019, 12:41am
12
It would appear that all is quiet on delay templating and I’m not sure that wait
is going to achieve my end goal.
Having several similar irrigation sensors, I’m trying to reduce the amount of near duplicate code with a universal script.
In my use case, I’d like to concatenate the variable to an entity state, e.g.
- delay:
data_template:
minutes: "states.input_number.duration_{{entity}}.state | int"
AhmadK
(akasma74)
April 3, 2019, 6:06am
13
I don’t think HA people pay attention to our requests at all
Way too busy implementing their own
Per4merKC
(John Edmonds)
April 5, 2019, 12:31am
14
By the way… the new “time of day binary” component should solve this problem!
AhmadK
(akasma74)
April 5, 2019, 7:50am
15
How would the solution be like?
Manuel82
(Manuel Jung)
April 5, 2020, 3:06pm
16
Is there a way to use passed variables in the delay. This for example does not work.
Automation
- alias: test_automation
trigger:
- platform: state
entity_id: input_boolean.test
action:
- service: script.test_script
data:
duration: 10
Script
test_script:
sequence:
- service: notify.alexa_media
data_template:
target: media_player.echo_computer
data:
type: announce
message: 'Test Script 1'
- delay: "00:00:{{ duration }}"
- service: notify.alexa_media
data_template:
target: media_player.echo_computer
data:
type: announce
message: 'Test Script 2'
AhmadK
(akasma74)
April 5, 2020, 4:03pm
17
can you try this
- alias: test_automation
trigger:
- platform: state
entity_id: input_boolean.test
action:
- service: script.test_script
data:
duration: 2
test_script:
sequence:
- service: persistent_notification.create
data_template:
message: 'Test Script 1'
- delay: "00:00:{{ duration }}"
- service: persistent_notification.create
data_template:
message: 'Test Script 2'
It does work as expected for me (and the docs confirm that we can have templates in delay
).
I believe this FR was completed long time ago.