GleDel
(Gle Del)
1
Hello,
I’m trying to create a simple binary sensor based on a media player state but I cannot get it to work.
This is my binary sensor:
template:
- binary_sensor:
- name: Sonos Move Playing
unique_id: "sonos_move_playing"
state: >
{% if is_state('media_player.sonos_move ', 'playing') %}
on
{% else %}
off
{% endif %}
This results in the sensor being off when the media player state is actually ‘playing’
Is there anyone who can tell me what i’m doing wrong here?
tom_l
2
Binary sensor templates need to resolve to true or false. This should do it:
template:
- binary_sensor:
- name: Sonos Move Playing
unique_id: "sonos_move_playing"
state: "{{ is_state('media_player.sonos_move ', 'playing') }}"
Though that is a pretty simple test you could perform anywhere, why do you need a binary sensor?
GleDel
(Gle Del)
3
I need a binary sensor to change the color of an icon in a custom lovelace card. The card requires a binary sensor.
I also tried your suggestion. As you can see In the image in my first post
{{ is_state('media_player.sonos_move ', 'playing') }}
returns ‘False’ even if the state of ‘media_player.sonos_move’ is ‘playing’
EDIT:
It looks like ‘is_state’ is not giving the correct result no matter what sensor I use.
There is a blankspsce where it shouldn’t be (behind the entity_id):
is_state('media_player.sonos_move ' , 'playing') }}
GleDel
(Gle Del)
5
Thank you. I feel so stupid for not noticing 
1 Like