Which works superbly for the first part of the string, thankyou.
So how do I format a second value_template for capturing the second half of this string? (which can occasionally reach 500 characters)
I don’t know what you are trying to achieve here, but what I would do is assign the number of characters in the truncated text to a variable and then get the rest of the characters from there to the end like this:
It grabs all characters after the 255th character, if the string is longer than 255.
And just to explain the code, mystring is a 10 character string.
{% set mystring = '0123456789' %}
If I want to grab the 7th character in my string, call out the 7th index. Which happens to be 6 because lists start at zero. 0 = 1st item, 1 = second item, … 6 = 7th item. So in our case, the 7th item is the number 6. Use brackets after your string to grab that item [index].
Now, i want to grab everything before the 7th item, but not the 7th item. Well using the : character tells the brackets to grab everthing. Depending on what side you place the : on is what you get.
EDIT: Truncate is only useful when you want the pretty … at the end of your truncated string. If you don’t care about that, just cut the string at the index you want.
id: sport led eleven
alias: sport led eleven
trigger:
platform: template
value_template: “{{ state_attr(‘media_player.vu_uno_4k’, ‘source’)[:6] == ‘Eleven’ }}”
action:
data:
entity_id:
script.tv_sport
service: script.turn_on
id: sport led normal
alias: sport led normal
trigger:
platform: template
value_template: “{{ state_attr(‘media_player.vu_uno_4k’, ‘source’)[:6] != ‘Eleven’ }}”
action:
data:
entity_id:
script.tv_normal
service: script.turn_on
works
scripts:
tv_normal:
alias: Led white TV1
sequence:
- service: light.turn_on
data:
entity_id: light.led_tv
rgb_color: [255, 214, 170]
brightness: 80
tv_sport:
alias: Led green TV1
sequence:
- service: light.turn_on
data:
entity_id: light.led_tv
rgb_color: [38, 80, 17]
brightness: 80