fsa317
(Frank)
April 3, 2020, 12:13am
1
Working on a template for detecting what is on my roku device. I have a larger template but boiled down my issue to the following.
The two lines below should who the source and then use is_state_attr to check the source.
{{ state_attr("media_player.bedroom","source") }}
{{ is_state_attr("media_player.bedroom","source",'Roku') }}
The output when the source is Roku, as expected is:
Roku
True
However, I turn on the Roku and my cable box and it fails:
{{ state_attr("media_player.bedroom","source") }}
{{ is_state_attr("media_player.bedroom","source",'Cable box') }}
returns
Cable box
False
For some reason the comparison to the word Cable box seems to fail.
AhmadK
(akasma74)
April 3, 2020, 12:23am
2
when you do this, paste the following in Developer tools → Template and post the output here
{{ state_attr("media_player.bedroom","source") is string }}
fsa317
(Frank)
April 3, 2020, 12:58am
3
{{ state_attr("media_player.bedroom","source") is string }}
{{ state_attr("media_player.bedroom","source") }}
{{ is_state_attr("media_player.bedroom","source",'Cable box') }}
OUTPUT:
True
Cable box
False
It seems to have to do with the space, if i rename Cable box
to just cable
it works. But I dont want to do that on all the tvs.
AhmadK
(akasma74)
April 3, 2020, 1:06am
4
this code returns True
on HA 0.107.7
{{ is_state_attr('automation.debug_change_default_log_level', 'friendly_name', 'debug: change default log_level') }}
what’s your setup?
fsa317
(Frank)
April 3, 2020, 1:29am
5
Running on Hassio, 0.107.7.
AhmadK
(akasma74)
April 3, 2020, 1:38am
6
I think the problem in not in is_state_attr
, cannot reproduce it
{{ is_state_attr("binary_sensor.1st_floor_bathroom_extractor_fan_node_status", "friendly_name", 'Cable box')}}
prints True
…
tom_l
April 3, 2020, 3:57am
7
Try cutting and pasting this into the template editor:
{{ is_state_attr('media_player.bedroom', 'source', 'Cable box') }}
AhmadK
(akasma74)
April 3, 2020, 7:03am
8
Tom, I played with different quotes here and still was unable to reproduce the issue.
Can’t see anything else in the code that might be wrong
tom_l
April 3, 2020, 7:10am
9
The only thing I noticed was the mixed use of single and double quotes. While that should work in the template editor it will play havoc with a single line template.
AhmadK
(akasma74)
April 3, 2020, 7:26am
10
I know, but apparently TS uses it in a bug chunk of code
so it’s very unlikely a single line template but I may be wrong here