Template sensor problem

I am stuck with a template sensor which seems not to evaluate as I expect

binary_sensor:
 - platform: template
   sensors:
     bedroom_alarm_clock_buzzing:
       value_template: "{% if 'Vogelgezwitscher' in  states.media_player.mpd.attributes.media_content_id %}on{% else %}off{% endif %}"

when I use the dev tools the template evaluates as expected but still the sensor doesn’t

{% if 'Vogelgezwitscher' in  states.media_player.mpd.attributes.media_content_id %}on{% else %}off{% endif %}

gives on

{{states.binary_sensor.bedroom_alarm_clock_buzzing.state}}

gives off

any ideas why?

The template should result in true or false. Try:

binary_sensor:
 - platform: template
   sensors:
     bedroom_alarm_clock_buzzing:
       value_template: "{{ 'Vogelgezwitscher' in  states.media_player.mpd.attributes.media_content_id }}"

@pnbruckner Thanks. That works!

1 Like