This is really important to understand so ill try explaining it for you⌠when you see code going down a page and also strangely indented, its for a good reaso.
Everything underneath and indentated right, they are all commands for the top Left most spaced functionâŚ
on_press:
then:
if:
condition:
- switch.is_off: power_down
then:
- switch.turn_on: power_down
else:
if:
condition:
- switch.is_on: power_down
then:
- button.press: restart_cam
Because on_press is all the way left, then everything underneath it and indented all belong to the on_press function and âthenâ is down 1 and indented 2 spaces which means your âthenâ belons to on_press and gets called second after on_press. Next is âifâ and here its indented more because the âconditionâ, âthenâ, âelseâ belong to the first âif statementâ and all of it belongs to or gets triggered by on_press.
If you have a more complex automation, like more than 1 if-then-else automationsâŚ
on_press:
then:
- if:
condition:
- switch.is_off: power_down
then:
- switch.turn_on: power_down
else:
if:
condition:
- switch.is_on: power_down
then:
- button.press: restart_cam
- if:
condition:
- switch.is_on: power_down
then:
- switch.turn_on: power_down
else:
if:
condition:
- switch.is_on: power_down
then:
- button.press: restart_cam
Here there are 2 âifâ statements or 2 primary ones at least. Notice how they are directly underneath each other and both â- ifâ are indented the same amount? This means both are seperate but equal and one or the other will run, not both. They are 2 seperate automations. Here when on_press happens, it will then check the first âifâ statementâŚ
- if:
condition:
- switch.is_off: power_down
If power_down is Off(True) then it will execute the code underneath that first â - if â
then:
- switch.turn_on: power_down
and so on.
If power_down is ON then the â - if â is False/Not True and then it and wonât execute that second â - if â code block
condition:
- switch.is_off: power_down
Kinda make sense?