my objective is to use 3 soundtouch speakers to broadcast messages via the tts command. In an automation I generate fields for the number of devices switched on, the status of the spotify player and lists for switched on/off devices. I pass those field to a script. After the tts sequence, I want to switch off those media_players, which were not on at the beginning (mediaplayer_off). This works fine with
unless all media_players are on. Then mediaplayer_off is an empty list. I also restart spotify, if the spotify player played before with the following sequence:
but this sequence is not executed. I tried the sequence in the developer_tools → templates and got in my opinion the right output, which would restart spotify, when all 3 mediaplayers (soundtouch) are on. Any idea, why the combination of service_template and data_template is not working?
first you need to properly format your posted code blocks so re more readable. add three backticks (```) before and after the code blocks.
second “service_template” and data_template" are no longer used. just use “service” and “data” and HA will be smart enough to know if you use a template.
I recommend you take a moment to read the forum’s FAQ.
FWIW, it’s not mandatory to use choose but it does make it easier because the template logic you created has loopholes that can cause errors. For example, what happens if count_off is zero or spotify_on is false? The template’s if-elif fails to handle those situations so the template produces nothing … and that’s not a valid service call.
NOTE
Only one post in the entire thread can be marked with the Solution tag. You should mark Mati24’s post (as you originally did) with the Solution tag, not mine, because you are using it’s suggestion to fix the problem.