Service template, jinja,

Hello!

Can someone explain to me why code 1 works, but code 2 doesn’t? It should produce the same command fed to the service … according to dev tools > templates
I either get
input_boolean.turn_on
or
input_boolean.turn_off

in both cases.

#code1
- service: >
    {% if 'hold' in command %} 
      input_boolean.turn_on
    {% else %}
      input_boolean.turn_off
    {% endif %}

Vs.

#code2
- service: >    
      input_boolean.turn_{{ 'on' if 'hold' in command else 'off' }}

No. I cant explain it. They should be equivalent.

What error do you see with the second version?

None… I can safely reload my automations without errors but the automation stops working.
And that is the only change made in the automation
And makes the difference from working to non working

What about the automation trace?

Does that reveal anything?

I’ll have to get back to you on that, tracing does not appear to work while the automation is in a package.
The option is disabled.

Does the automation have an id:?

I thought that was the only requirement for trace to be able to be used.

Did not know that, alright. I’ll give it a go after lunch :clap: thank you

1 Like

Alright thank you once again, I’ve narrowed down the culprit.
It wasn’t the service at all, was just unfortunate enough to try the code change
with different circumstances (light was on as opposed to off) which showed me an unrelated fault in my code :stuck_out_tongue:

nice feature, wasnt even aware of tracing before this!

2 Likes