This gives me an error
16-05-31 22:31:47 homeassistant.bootstrap: Invalid config for [automation]: [for] is an invalid option for [automation]. Check: automation->trigger->0->for. (See /config/automation.yaml:348)
- alias: "TV off when off"
trigger:
platform: numeric_state
entity_id: sensor.TV_watts
below: 20
for:
minutes: 1
action:
service: switch.turn_off
entity_id: switch.TV
Any idea why?
indentation is wrong (3 spaces instead of 2) and numeric_state doesnāt work with for, you could work around by adding a condition or delay in your script ā¦
Thanks.how can this be done in a condition? I as thinking a script but that seems overly complicated.
if you want to get anything done right, it will be complicated, last time I checked my conf has over 8000 lines of code.
I feel for you as a lot is not straightforward but I prefer the coders advancing the project than the documentationā¦
in your case youāll need to investigate templating with a state trigger, you can put a ā{{ states.sensor.tv_watts.state < 20 and trigger.for > 60 and states.switch.tv == āonā }}ā in a template condition
1 Like
@thefrenchmatt thanks Iāll give that a try.
Ok. here we go:
- alias: "TV off when off"
trigger:
platform: numeric_state
entity_id: sensor.TV_watts
below: 20
condition:
condition: or
conditions:
- condition: template
value_template: '{{ states.sensor.tv_watts.state < 20 and trigger.for > 60 and states.switch.tv == "on" }}'
action:
service: switch.turn_off
entity_id: switch.TV
however the TV does not turn off after 1 minute. I suppose the trigger.for > 60
means 60 seconds right?
Sorry for not answering sooner, spent the last 3 days moving flats and still plenty to fix in my config
I think times are in seconds in ātrigger.forā but Iām not sure as Iām using (āto: state_valueā together with āfor: seconds:ā) in my trigger (here you could tweak the āupdate_intervalā in your sensor.tv_watts config but Iām not sure of the effect nor default values so YMMV).
As you made a nice effort, hereās how Iād do it:
- alias: "TV off when off"
trigger:
platform: state
entity_id: sensor.TV_watts
condition:
- condition: template
value_template: '{{ states.sensor.tv_watts.state < 20 and trigger.for > 60 and states(switch.tv) == "on" }}'
action:
service: switch.turn_off
data:
entity_id: switch.TV
@thefrenchmatt thanks. I tried but it still doesnāt work. Its also very difficult to debug. It simply does not turn off the TV although the wattage is below 20ā¦
Why the different syntax: states.sensor.tv_watts.state < 20
but states(switch.tv)=="on"
- why? shouldnāt it be the same syntax?
havenāt quite figured it out myself, wiki says one syntax will return an error and another doesnāt, but Iām also lost on how to debug the flows properly
one thing that worked for me is using |round(0) after state values, sometimes hass doesnāt interpret the states in the correct format and the jinja2 wiki + stackoverflow are full of answers that may fit your caseā¦
try value_template: '{{ ( states(āsensor.tv_wattsā)|round(0) < ā20ā|round(0) ) }}
then call a script instead of switch_off, you can then add a delay in your script, youāll then need another automation to cancel your switch_off script in case the watts go above 20ā¦