I agree but do you have an alternative for cases where there really isn’t an else but there are further steps in the automation?
The only other way I have come up with is to always call a separate script which performs one function and let that script have the condition. Probably slightly more correct but in my opinion slightly less maintainable. YAML is bad enough without having tiny bits of code all over the place just to deal with a logic problem.
Agreed. Tonight I have actually been able to remove it from the few templates I was using it in by using either David’s suggestion to put the last option in the else case or petro’s condition suggestion. e.g.
condition:
- condition: template # Only if currently running any heat mode
value_template: "{{ 'Heat' in states.input_select.lounge_ac_mode.state }}"
action:
service_template: >
{% if is_state('input_select.lounge_ac_mode', 'Powerful Heat') %} shell_command.lounge_ac_powerful_heat
{% elif is_state('input_select.lounge_ac_mode', 'Normal Heat') %} shell_command.lounge_ac_normal_heat
{% elif is_state('input_select.lounge_ac_mode', 'Silent Heat') %} shell_command.lounge_ac_silent_heat
{% endif %}
Not quite. There’s a gap between 41 and 70 that should not result in the (else) lights_75 case. I just closed it by bringing that first test down to >40.
@anon43302295, that is another good solution using a condition but I am interested in if there is a solution when it is not the last action in an automation.
Let’s say for some reason I then wanted to to check if was St. Georges day(!), or something else more useful and not even date related, or even something that didn’t even need a condition to be met. (A real world example could be a delay until the birthday greeting TTS was finished.)
Like I don’t know what your birthday greeting script does, or what your St George’s day script would do, but if this is all part of an announcement over tts for example, I would run a ‘say’ script and put the logic for what needs saying and when in that.
Like my announcements script uses the status of a random binary sensor to decide whether or not to add an ‘interesting fact’ to the end of each message, you could easily use the same principle to work out if it’s somebody’s birthday (or saints day!) and just have it built in to the message.
Your TTS script was one of the first really cool things I saw when I joined this forum and I did indeed nick most of it to good effect
I became slightly disenchanted with the whole TTS in HA thing though due to it not being able to queue messages so getting message clash and also announcements always being in a predefined order does get a bit samey.
This prompted me to come up with a different method which currently might just about be as good as yours (at best) but I think will be more flexible if ever there is a way to queue messages and if I can put the work in to get around the 256 character input text limit. MQTT seems the best option at the moment for that but there is always something more interesting to do with HA than rework existing working features!
Heh, there are ways to queue the messages, just depends how much effort you want to put in. You could use a counter for example, and increment the counter with each message and get the number ‘in the queue’ to wait for the message to be spoken at the start of the script, and use a wait template.
Randomising the order of the sections of speech shouldn’t be too difficult either, the real ball-ache being how much time it takes to refine these things and try to cover every eventuality
please let me join this here, with a related question. I think I got it working, but I am not using the fail safe dummy script yet, and not sure if I even need to.
consider this:
If the announcement is on, it takes precedence over notify even if that is on. If announcement is off, evaluate if notify is on and if yes, notify.
If none are on, do nothing.
Would I need the ‘else’ here?
bottom one would be better, but you wouldn’t even need the elif. Because your or statement in the value_template would filter it down to those 2 options. Just keep in mind, with your current logic, if both are on, only 1 will fire (announce_presence).