Join does'nt work as expected

Hello everyone,
i would like to reformat the return value of a sensor. the sensor returns the value

“Gelsenkirchen Wertstofftonne mit zweiwöchentlicher Abfuhr in 12 tagen”

the result should be:

“Wertstofftonne Abfuhr in 12 Tagen”

I use the following filter:

value_template: “{{ states(‘sensor.next_pickup’).split(‘Gelsenkirchen’)[1].split()[-4:] | join(’ ') }}”

However, this filter only returns the result “Abfuhr in 12 tagen”; the join is therefore missing.

Any hints?

Try this:

value_template: "{{ states('sensor.next_pickup').split('Gelsenkirchen')[1]|replace('mit zweiwöchentlicher ', '') }}"

Also in future please format your pasted config correctly.

Tom, Thank you. This did the trick.

I will pay attention to the code formatting next time. thanks for your advice.

1 Like