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 %}
  • bob_wiley@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I looked at all the comments after I posted this and saw your full code. The suggestion I put there isn’t as nice as default(omit), but still probably much better than trying to go with this conditional route, which will probably increase code instead of reducing it. I think that should solve your problem. I didn’t really think about building the entire data payload on the fly until seeing your post, but it makes sense as a solution.