I’m trying to minimize repeat codes in this automation.yaml section. Is there a way to insert an endif after the else section? If I can, there will be only one delay: 5 seconds and one shell_command.. So in summary, if - then - else - endif!
In my coding years, there is a way to end an if. In COBOL, a period ends the if. In LINUX (or UNIX or AIX), endif or fi, depending on the flavor. Example from my RPi 4:
echo "Test if, then,else,...."
export A1='1'
export A2="2"
echo -n 'Press Enter to continue... ';read ok
if [[ $A1 == $A2 ]];then
echo echo "$A1 is equal to $A2"
else
echo echo "$A1 is not EQUAL to $A2"
fi
I want to only code the delay of 5 minutes and then the shell_command once!
So, is the alignment in yaml coding signifies LOGICAL construct, instead of a syntactical coding of endif or fi to signify end of the condition(s)? I’m confused.
This is how I want it to be, logically:
at start of the home assistant, whether it be after a reboot or a manual (auto after an update) restart of the home assistant system
- if my `binary_sensor` is on
then
- turn the `input_boolean` switch to on
else
- turn the `input_boolean` switch to off
- I want to end the if condition here <---------------
So that I can then continue the 5 minute delay and shell_command. That way either on or off, the delay and the shell_command are executed.
in this case there is no “endif”. It is implied from the indentation/spacing.
I’m not even sure if the yaml specification has the if/then/else construct. It might be just created for HA by the HA developers. I do know that was just added recently as an option.
But as an alternate example the Jinja templating has an “if/elif/endif” construct tho.
Yeah, I guess indentation/spacing is the key to the logical construct of yaml coding. I am not familiar with python coding at all! So is python based on indentation or spacing, not free form based on logical construct?
I’ll try this indentation/spacing approach on what I intend to in logic I want to follow. And I’ll trigger an alert at the then, an alert at the else, then an alert at the end. We’ll see.
Now, I see it in the UI, too. At the end of the then, there is “Add Action”. If there is no more action under the then, you proceed to do the else. At the end of the else, there is “Add Action”. If there is no more action under the else, you proceed to the next “Add Action”, which aligns with the if. Perfect! Now understand how to end the if-then-else.