I’m trying to get a script to invoke another script depending on the value of an input_select. That part is working, but then I want the first script to wait until the script it invokes has finished. That part is hanging. I think the issue is it’s not able to automatically determine the entities involved due to the way I constructed the template. The template works ok when I test it on the Templates page of the front end, but I think that’s because it just evaluates it and doesn’t need to extract the entities for waiting on corresponding state changes.
Here are the two templates in my script:
- service_template: >
{% set map = {"Off": "lr_ipc_off",
"Stream": "lr_ipc_stream",
"Record": "lr_ipc_record",
"Auto Off": "lr_ipc_auto_off",
"Auto Detect Outside": "lr_ipc_auto_detect",
"Auto Record All": "lr_ipc_auto_record" } %}
script.{{ map[states("input_select.lr_ipc_op")] }}
- wait_template: >
{% set map = {"Off": "lr_ipc_off",
"Stream": "lr_ipc_stream",
"Record": "lr_ipc_record",
"Auto Off": "lr_ipc_auto_off",
"Auto Detect Outside": "lr_ipc_auto_detect",
"Auto Record All": "lr_ipc_auto_record" } %}
{{ is_state("script."+map[states("input_select.lr_ipc_op")], "off") }}
I also tried this so that the full names of the scripts can be seen, but it still doesn’t work:
- service_template: >
{% set map = {"Off": "script.lr_ipc_off",
"Stream": "script.lr_ipc_stream",
"Record": "script.lr_ipc_record",
"Auto Off": "script.lr_ipc_auto_off",
"Auto Detect Outside": "script.lr_ipc_auto_detect",
"Auto Record All": "script.lr_ipc_auto_record" } %}
{{ map[states("input_select.lr_ipc_op")] }}
- wait_template: >
{% set map = {"Off": "script.lr_ipc_off",
"Stream": "script.lr_ipc_stream",
"Record": "script.lr_ipc_record",
"Auto Off": "script.lr_ipc_auto_off",
"Auto Detect Outside": "script.lr_ipc_auto_detect",
"Auto Record All": "script.lr_ipc_auto_record" } %}
{{ is_state(map[states("input_select.lr_ipc_op")], "off") }}
Any ideas? I know in some cases (such as template sensors) it let’s you list the entities explicitly in case “the automatic analysis fails to find all relevant entities.” Apparently wait_template
doesn’t have this feature. (I even tried adding entity_id
but it doesn’t accept it.)
And to complete the picture, this is what I had before that works, it’s just a bit messier:
- wait_template: >
{% if is_state("input_select.lr_ipc_op", "Off") %}
{{ is_state("script.lr_ipc_off", "off") }}
{% elif is_state("input_select.lr_ipc_op", "Stream") %}
{{ is_state("script.lr_ipc_stream", "off") }}
{% elif is_state("input_select.lr_ipc_op", "Record") %}
{{ is_state("script.lr_ipc_record", "off") }}
{% elif is_state("input_select.lr_ipc_op", "Auto Off") %}
{{ is_state("script.lr_ipc_auto_off", "off") }}
{% elif is_state("input_select.lr_ipc_op", "Auto Detect Outside") %}
{{ is_state("script.lr_ipc_auto_detect", "off") }}
{% else %}
{{ is_state("script.lr_ipc_auto_record", "off") }}
{% endif %}