I’m playing with a homebrew led strip controlled by an arduino - I can control it as light from HA via Template light - HA is amazingly capable!
Anyway the simple REST library I’m using on the arduino only accepts a single parameter string so I end up with this template which works fine in Developer Tools - Templates
How can I split it into a multiline template for ease of editing/maintenance/readability? I’ve tried various versions using > but always end up with errors.
you’re overriding the built in string filter/function. Don’t do that.
{% set a = "http://192.168.1.119/switchon?params=" %}
{% set b = states("input_number.ledstrip_hue") | int %}
{% set c = "s" ~ states("input_number.ledstrip_sat") | int %}
{% set d = "l" ~ states("input_number.ledstrip_brightness") | int %}
{{ a ~ b ~ c ~ d }}
or
{% set a = "http://192.168.1.119/switchon?params=" %}
{% set b = states("input_number.ledstrip_hue") | int %}
{% set c = states("input_number.ledstrip_sat") | int %}
{% set d = states("input_number.ledstrip_brightness") | int %}
{{ a }}{{ b }}s{{ c }}l{{ d }}
that’s assuming you even need the ints
or
{% set a = "http://192.168.1.119/switchon?params=" %}
{% set b, c, d = ["input_number.ledstrip_hue", "input_number.ledstrip_sat", "input_number.ledstrip_brightness"] | map('states') | map('int') | list %}
{{ a }}{{ b }}s{{ c }}l{{ d }}
Thanks @123, @petro for all the different solutions. The choices can be overwhelming
I’ve become aware of so many new templating capabilities which hopefully will help others searching with similar issues. .format looks powerful but ~ string concatenation seems nice and straightforward to me.
so my new solution is
{% set a = "http://192.168.1.119/switchon?params=" %}
{% set b = states("input_number.ledstrip_hue") | int %}
{% set c = "s" ~ states("input_number.ledstrip_sat") | int %}
{% set d = "l" ~ states("input_number.ledstrip_brightness") | int %}
{{ a ~ b ~ c ~ d }}