I have tested if conditions in the data template. All of the set values are valid options for input_select.stoveamstart.
The current attribute āstart_timeā of calendar.delphine_work_calendar is ā2019-11-19 09:30:00ā - which when used with the [11:19] evaluates to 09:30:00.
{{ (state_attr(ācalendar.delphine_work_calendarā, āstart_timeā) [11:19]) == ā09:30:00ā }} shows true in the templates dev tool. All of the other conditions evaluate to false currently.
However I try, it does not do what I want.
Call the service input_select.select_option with data entity_id: entity_id: input_select.stoveamstart and time: 07:00.
As you may notice, I have tried changing the ā07:00ā to ā07:00ā in the automation - changes nothing.
I really cannot see why itās not working - Anyone like to enlighten me?
Are there any error messages in the log related to the execution of this automation?
If you execute this automation manually, it will skip the trigger and condition and execute the action. If you try it and it works, then it means there may be a problem with the automationās condition.
Thanks everyone. Removing the quotes worked.
OF course, 123 Taras suggestion to look in the logs showed that ā07:00ā was not a valid option.
I had tried triggering manually, without errors.
I also had an else in my data template, but it appears to work fine without it. Is that perhaps because it is the last bit of code in my automations yaml file? I thought I had read that with elif you can end with simply endif.
Your - if then elif elif elif will work fine UNTIL it doesnāt match any preceeding statement, then it will crash (the automation) big style.
Besides itās just bad programming practice and you should try to cater for a case you didnāt specifically program for
Okay, just as long as you didnāt leave the else statement blank (that will also cause errors)
If you are certain you āhaveā covered all possibilities, then there is no harm in just converting your last elif to an else and removing the evaluation
Good luck
As you rightly said, itās bad programming practice. The calendar entries that are used are manually entered. There could always be a type in the entry, with the start time not being one of the possibilities, then I would run into trouble. My else covers that - to change nothing if one of the possibilities is not met.
Without the else statement and if all of the other āif/elifā statements fail then the worst that will hapen is the automation will write an error into the log saying something about invalid data for the service call. And of course there will be no action taken since the automation failed.
But to say ācrash big styleā sounds way more ominous.
But I also agree that you probably should always try to include an āelseā for no other reason than itās good programming practice. Oh, and the fact that 6 months from now youāll be looking through the log and see an error and you wonāt have any idea where itās coming from and itāll drive you batty trying to figure out whatās causing it. Or at least it would meā¦
Re reading, it is more than a bit ambiguous (I have edited the post to make it clearer).
But āgenerallyā people posting questions, seem (not suggesting neal did here) to only tell the part of an automation they are having difficulty with.
The fact that they later add 4 actions to it (and it works) is okay with them. But when there is no āelseā and the template hits it, then no further actions will be carried out. Iād call that, crashing (the automation) big style, even if it crashes nothing else (it wouldnāt)
I am, anyway, always cognisent that the ānextā reader will just learn the lessons contained within an āapparentā solution, without thought to the wider implications - especially if it works the two or three times they test it.
Thanks for the opportunity to clarify
Itās a shame that itās not possible to mark two answers as a solution - AFAIK.
This forum is a hive of very useful information and advice - and I thank everyone that contributes. While researching the use of ifā¦elifā¦esleā¦endif - I came across some documentation with an example that did not contain the else. And copied that example, unaware that it could break my automation if none of the if or elif conditions were met.
In order to try to clarify a bit:
My automation was not taking the expected actions due tome putting quote marks around the input_select options. By doing so, my automation started performing as expected.
I had also researched using variables in automations - How long has it been possible to use set t = in a template? I was not aware and did not find the information searching.
So, I came here looking to understand why, after inspecting my code and testing parts of it, the automation did not work. I got the answer to that, and a LOT of VERY useful advice that will enable me to be more efficient in creating automations in the future. I could not have hoped for more.
Mutt - Iām not sure I understand what you find more than a bit ambiguous - I would be happy to disambiguate if I knew - and yes, the next reader will take what he wants rather than what any of us would like them to. You can lead a horse to waterā¦ but you cannot force it to drink!
Very true my friend but with some members entrenchment I do sometimes wish that āshooting itā was an available option
Ambiguity - finity and I often butt heads on terminology, and more often than not we both learn something from it. (Iād rather fight with finity than have someone (wrongly) agreeing with me).
Finityās remark was that I āimpliedā the fault would crash HA or some such rather than just NOT continuing the automation. I agreed and have changed my post.
Every post I write, I hope to be of value to at least the next 5 readers that come across it (until HA moves the goalposts, and we have to start again )
AND if you learnt more than you intended to (and were grateful for that), (sorry, but I hate the āonly tell me what to put in the templateā attitude, cos they will learn nothing) then thatās a happy consequence.
Iām sure both finity and I will be pleased to assist you in future, a few other members - I tend to avoid, they ātakeā to solve this but never learn/expand to solve the next themselves - blackholes of need.
Besides Iām sure you will help out in line with your abilities (which expand with exposure )
Edit: 2 solutions, no I think in all fairness Phil provided the solution, at best the other members here ārefinedā it (I generally learn more from the refinements, but without the solution they are pointless )
I started using Home Assistant over a year ago so I can confidently say it has supported variables within a template for āat least a yearā. However, it has probably had that capability since it adopted the Jinja2 templating engine so the real answer is āfor many yearsā.
Thanks again for your replies and insight.
This forum is one of the most useful and helpful that I personally use on the net.
XDA developers used to be like this back in the day, but like so many forums, there are soooo many trolls, rude, entitled people and general a**h*les about that itās no longer a source of help / info for me.
Here, I learn every day from helpful and friendly people that just wanna share the good thing they got.
I try to provide some help to others here, but there are so many helping, I nearly always get beaten to it!