I am trying to rely more on the voice than the dash board. My problem is this. The sensor spits out the best route as this: SR-4 BYP S; Springfield Pike Springdale. So I don’t have to watch the sensor all the time and rewrite everytime it changes wording. Is there a way to make it replace SR-4 BYP S (only) with BYPASS 4? Write now I have to create if statements for the whole phrase. If it changes I get nothing. If I can change each word that would be great.
Perfection! thanks. I knew there was a better way. I just could not get my head wrapped around it. This will help is a lot other places also. The only things I had to change was
{% set ns = namespace(s=states('sensor.YOUR_SENSOR_ID')) %}
to this
{% set ns = namespace(s=state_attr('sensor.df_electronics', 'route')) %}
Thanks for sharing this wonderful solution. I had similar requirement where I wanted to replace multiple occurrences of time in a string. I wanted to convert from '%I:%M %p' to '%H:%M' since the later sounds better in TTS. I was trying various options from past 3 days. I could slightly modify this and made it to work.
{% set info_original = namespace(s=states('sensor.calendar_info')) %}
{% set date_regex = (info_original | regex_findall ("([0-2][0-9]:[0-5][0-9]+ [AaPp][Mm])+")) %}
{% for item in date_regex | select('in',info_original.s) %}
{% set date24h = strptime(item, '%I:%M %p').strftime('%H:%M') %}
{% set info_original.s = info_original.s | replace(item, date24h) %}
{% endfor %}
{{ info_original.s }}