Hi @palitu @Beef-well
I’m trying to base on your example to use slider input for garden watering.
Configuration:
switch:
- platform: rpi_gpio
name: "Watering"
ports:
5: Water trees
6: Water lawn
input_number:
water_slider:
name: Watering Run Time
initial: 20
min: 1
max: 90
step: 1
Automation:
- id: turn_off_lawn_water
alias: Turn off garden watering
trigger:
- entity_id: switch.water_lawn
platform: state
to: 'on'
action:
- service: script.turn_on
entity_id: script.water_timer
- id: reset_water_timer
alias: Reset water timer
trigger:
- platform: state
entity_id: switch.water_lawn
to: 'off'
action:
- service: script.turn_off
entity_id: script.water_timer
Script:
water_timer:
alias: "Watering Timer"
sequence:
- delay: '00:{{ states.input_slider.water_slider.state | int }}:00'
- service: homeassistant.turn_off
data:
entity_id: switch.water_lawn
My problem is: HomeAss throws error on template parsing {{ states.input_slider.water_slider.state | int }}:
2018-03-17 22:19:54 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.water_timer>
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 131, in async_render
return self._compiled.render(kwargs).strip()
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/filters.py", line 653, in do_int
return int(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1010, in _event_to_service_call
yield from service_handler.func(service_call)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/script.py", line 163, in service_handler
yield from script.async_turn_on(variables=service.data)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/script.py", line 215, in async_turn_on
yield from self.script.async_run(kwargs.get(ATTR_VARIABLES))
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/script.py", line 105, in async_run
delay.async_render(variables))
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 133, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'
While i run the script with static number of minutes it works OK.
Is there workaround? Any other way to read a value from slider?