Hi there
I am trying to automate to switch off a heater after turning it on for x hour.
- alias: 'Rule 3 Heater Auto Off After 1 Hour'
condition:
- platform: state
entity_id: switch.heater
state: 'on'
for:
hours: 1
minutes: 0
seconds: 0
action:
service: switch.turn_off
entity_id: switch.heater
But I am getting an error when starting up the hass-daemon again on my raspberry pi 2
Is there something wrong with my template? Help is much appreciated.
Regards
- alias: 'Rule 3 Heater Auto Off After 1 Hour'
trigger:
platform: state
entity_id: switch.heater
state: 'on'
condition:
- platform: state
entity_id: switch.heater
state: 'on'
action:
service: switch.turn_off
entity_id: switch.heater
I managed to get the rule to work by removing the state trigger condition ‘for:’
Is this a bug? when I set the condition further using this method here home-assistant.io/components/au … te-trigger HA fails to start and giving me an error message below
[quote]yaml.scanner.ScannerError: while scanning for the next token
found character ‘\t’ that cannot start any token
in “/var/opt/homeassistant/configuration.yaml”, line 123, column 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/lib/python3.4/multiprocessing/process.py”, line 254, in _bootstrap
self.run()
File “/usr/lib/python3.4/multiprocessing/process.py”, line 93, in run
self._target(*self._args, **self._kwargs)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/main.py”, line 236, in setup_and_run_hass
skip_pip=args.skip_pip, log_rotate_days=args.log_rotate_days)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/bootstrap.py”, line 240, in from_config_file
config_dict = config_util.load_yaml_config_file(config_path)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/config.py”, line 119, in load_yaml_config_file
conf_dict = load_yaml(config_path)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 25, in load_yaml
raise HomeAssistantError(error)
homeassistant.exceptions.HomeAssistantError: Error reading YAML configuration file /var/opt/homeassistant/configuration.yaml
[/quote]
SOLVED!!! i noticed few mistake in my code and removed the need to use condition.
Here’s the recipe
- alias: 'Rule 3 Heater Auto Off After 1 Hour'
trigger:
platform: state
entity_id: switch.heater
from: 'off'
to: 'on'
for:
hours: 1
action:
service: switch.turn_off
entity_id: switch.heater
3 Likes
Hi!
YAML is sensitive to indentation formatting, spaces and tabs before first character on each line. You really should post your config in a code block in forums etc, to keep the indentation information. The error message you received was probably due to missing indentation.
[quote=“martinhjelmare”]Hi!
YAML is sensitive to indentation formatting, spaces and tabs before first character on each line. You really should post your config in a code block in forums etc, to keep the indentation information. The error message you received was probably due to missing indentation.[/quote]
Hi there, no it wasnt the indentation, it was the wrong code used (i think) and thanks for pointing out the post and i have coded them since.
Cheers
The error message you posted complains about finding a tab character. Tabs are not allowed in yaml . In your first post, the hour, min, sec, are not correctly aligned. They should have two spaces more before them than the ‘for’ on the line above them.
There could be other problems as well, but solving the formatting errors first is good practice.
[quote=“martinhjelmare”]The error message you posted complains about finding a tab character. Tabs are not allowed in yaml . In your first post, the hour, min, sec, are not correctly aligned. They should have two spaces more before them than the ‘for’ on the line above them.
There could be other problems as well, but solving the formatting errors first is good practice.[/quote]
ah it doesnt like tab, so needs to be spaces. got you. thanks for looking into it though, muchly appreciated.
Great example and very usefull
I’m wondering if the time (# of hours) can be set based on an input.select component.
I would like to use it on my grass irrigation automation where the time has to be flexible…
Thanks,
Alfredo.
That I would love to see to happen. I am not entirely sure with this unfortunately. I do too want to be able to change the # hours
It is not possible at the moment, but it is on the to do list: https://www.pivotaltracker.com/story/show/119160513
That would be great!!! It can be used for quite a lot of home automations:
- Grass irrigation (depending on the how dry it is)
- Fill the swimming pool. (depending on the amount of water to put)
- Delay on alarm activation (Depending on how is arriving at home).
Thank you so much for your support !!!
Best Regards,
Alfredo.
I do appreciate the support as well.
Keep it up!