How do you use "is defined" in a script?
I'm trying to get a script built. I want to check if a variable exist and include it if it does. Just really struggling to figure out the formatting. Something like
script:
sequence:
target:
entity_id: "{{ entity }}"
{% if variable is defined %}
data: "{{ variable }}"
{% endif %}
This looks like the right answer, since OP's jinja is correct.
OP, you can go to developer tools to test your template syntax against the live data in HA.
Is it possible to do this in a way that completely omits data: from the command if the variable isn't defined?
It worked the same as your suggestion above. In cases the variable is used it does works as intended but in the situation the variable is not set it's still sending data: just with a blank value.
When I tried playing with omit in the template editor I got an error about omit being undefined so probably not built in. Bummer because that would be a very elegant solution to this. I'm going to put this down for the night and try picking it back up tomorrow. I really appreciate all the suggestions. Hopefully it will lead me to a solution.
To give more context I'm working on a media control dashboard. The script or rather scripts I have to send commands to kodi is as follows
I would like to condense all of this down to a single script using "is defined" to omit the parts not needed for certain commands so something like
Problem with the above is I get "result is not a dictionary"