User a specific indexed item of a splitted string in a direct way

Does anybody knows a more direct way without loop to get item 1 from splitted value hsv?
First (L1) you see the hole content of the value. Second (L2) the result i would like.
Code:

L1: {{ states.sensor.dingz_markise1_state.attributes['led']['hsv'] }}
L2: {% set hsv = states.sensor.dingz_markise1_state.attributes['led']['hsv'] %}
{%- for item in hsv.split(';') %}
{%- if loop.index  == 1 %}
{{ item.split(' ')[0] }}
{%- endif %}
{%- endfor %}

Result:

L1: 180;100;3
L2: 
180

Is there a way to address directly the value I need? Without looping through all the values?

How about this?

{{ state_attr('sensor.dingz_markise1_state', 'led')['hsv']|split(';')[0] }}

No, state_attr doesn’t work.
{{ state_attr('sensor.dingz_markise1_state', 'led')['hsv'] }}
… delivers …
180;100;3
… thats ok. When I add split, like …
{{ state_attr('sensor.dingz_markise1_state', 'led')['hsv']|split(';')[0] }}
… I get no result anymore.

How about:

{{ state_attr('sensor.dingz_markise1_state', 'led')['hsv'].split(';')[0] }}

The template in tom_I’s post should return the value you want (180).

Should you ever need to get more than just the first value, here’s an alternative way. Paste this into the Template Editor and experiment with it:

{% set  h, s, v = state_attr('sensor.dingz_markise1_state', 'led')['hsv'].split(';') %}
{{ h }}
{{ s }}
{{ v }}
1 Like

Perfect … both commands give me 180 back.

{{ state_attr('sensor.dingz_markise1_state', 'led')['hsv'].split(';')[0] }}
{{ states.sensor.dingz_markise1_state.attributes['led']['hsv'].split(';')[0] }}

Thank you for helping … the syntax is sometimes a bit confusing for me.

Use the state_attr form wherever possible. There’s a warning and explanation on the templating documentation page. https://www.home-assistant.io/docs/configuration/templating/#states