I’ve noticed the same tendency to use choose
where a template is sufficent. It’s a very good addition to the toolbox but, at the moment, it’s suffers from “When you’re a hammer, everything looks like a nail”.
Indeed, the problem being that generating huge chunks of messy code (especially in something like yaml where indentation is so important) exacerbates the likelihood of mistakes creeping in, whilst simultaneously making it harder to read and spot any errors.
Hey ho
That’s really nicely put together. I’ve also used variables in my automations, but that didn’t cross my mind now.
Choose has it’s place when you need to execute multiple actions on different conditions, and when those actions vary a lot.
@123 Taras & Gentlemen,
Thank you so much for helping me out!
Actually it’s strange that this part of code is not displayed in GUI of Automation builder.
- platform: time
at:
- '19:00:00'
- '22:00:00'
- '06:00:00'
- '08:00:00'
It just shows “Time”, but no possibility to adjust from interface.
Not critical for me though.
The Automation Editor/Builder is designed for convenience. However, it has limitations that prevent it from supporting everything that is possible. It has been improved, and continues to be improved, but the current version still falls short of creating automations (and scripts) directly in YAML. That means if you create certain things in YAML mode they will not be displayed correctly in UI mode.
When using the Automation Editor, you can click the overflow menu in the right hand corner (three dots) and it will allow you to easily switch between UI and YAML mode.
Yes, that’s right.
Strange, but in the morning script has been executed, but preset_mode did not turn on ‘eco’…
What was the temperature at 06:00
?
Yes, temperature was stable below 10C (it always remains like this nowadays).
Doesn’t trigger
- platform: numeric_state
entity_id: sensor.bme280_temperature
below: 10
repeat the condition mentioned here?
{% set t = states('sensor.bme280_temperature') | float %}
{{ 'none' if t <= 10 and (19 <= h <= 22 or 6 <= h <= 8) else 'eco' }}
I tried to delete the trigger
- platform: numeric_state
entity_id: sensor.bme280_temperature
below: 10
and leave only time trigger, but I noticed that time mentioned in the code below
entity_id: climate.termostat_khoz_spalnia
preset_mode: >
{% set h = now().hour %} {% set t = states('sensor.bme280_temperature') |
float %} {{ 'none' if t <= 10 and (19 <= h <= 21 or 6 <= h <= 7) else 'eco' }}
Exactly “H” that stands for hour does not match trigger time, so I changed hour from 22 to 21 and 8 to 7. Will try to see if it works out…
Hang on a second…
If the temperature was below 10 at 6am when the automation fired, according to the logic of the automation it should be set to ‘none’, but you’re saying that it didn’t work because it wasn’t set to ‘eco’? Sounds like it worked exactly right.
Between 6 and 8 o’clock automation should set preset to “none”, but I said that after 8 it did not revert back to “eco”, although it should…
I think I see why it fails to set it to eco
at 06:00
and 22:00
. It’s because of this line here:
{{ 'none' if t <= 10 and (19 <= h <= 22 or 6 <= h <= 8) else 'eco' }}
Change it to this:
{{ 'none' if t <= 10 and (19 <= h < 22 or 6 <= h < 8) else 'eco' }}
It’s a subtle but important difference.
The hours of 22:00
and 06:00
were included as part of the time range for none
. They should represent the start of the time range for eco
. All that’s needed is to change the <=
to just <
for 22
and 8
.