If the State Condition evaluates to true then the next action (script.turn_on) is executed. If it evaluates to false then nothing else happens and the script ends.
@123, in your example all execution will stop if the condition is not met, correct? So what if there are subsequent steps that should run? The idea here is to fade the amp out if it’s on, then switch the playlist, and then fade it back up. But if it’s off, I want to turn it on and then fade it in. Here’s my full attempt…
Your original question didn’t mention anything about “subsequent steps”. That’s why I provided an example with a simple, inline State Condition. However, I did add that if you need more flexibility (meaning more than a simple inline condition) then you should use choose.
For example, this will execute script.pioneer_fade_to_zero only if the receiver is on. If it is off it immediately proceeds to the wait_template.
pioneer_fade_to_zero:
sequence:
- alias: "Check the Pioneer is on, else we can bail."
condition: state
entity_id: media_player.pioneer_receiver
state: "on"
- alias: "Set Variables"
variables:
step: 0.01
- alias: "Turn the amp down AS LONG AS the conditions are true"
repeat:
while:
- condition: template
value_template: "{{ states.media_player.pioneer_receiver.attributes.volume_level | round(2) > 0 }}"
sequence:
- service: media_player.volume_set
data_template:
entity_id: media_player.pioneer_receiver
volume_level: >
{% set n = states.media_player.pioneer_receiver.attributes.volume_level %}
{{ n - step }}
- alias: "Set it to exactly zero in case of a math issue."
service : media_player.volume_set
data:
entity_id: media_player.pioneer_receiver
volume_level: 0
If the system is already playing a stream, it will fade down and then change streams and fade up. If it is off, it will turn on, and then start a stream and fade up. Squeezebox has a fade in parameter but not a fade out, hence the need to manually fade the receiver. Nice effect overall! Thanks, @123 !
The Numeric State Condition in your example contains syntax errors. Posted below is the corrected version. However, I don’t understand why you put the condition at the end of the script. There are no actions after it so it doesn’t matter what is the condition’s result because it’s the end of the script anyway.