Where does the template go in my config?

I am trying to learn more advanced functionality in Home Assistant but am having trouble knowing where in my configuration to put a template I created. I have been all through the docs and forums but can’t figure it out.

I am trying to change the state names of my Roku TV in home assistant. I made a template and validated it in the template creator in developers tools. It works, but now where do I put it in my config to actually have it change the state names?

Here is the template code:

{%if states('media_player.family_room_tv') == "idle"%}
On
{%elif states('media_player.family_room_tv') == "home"%}
On
{%elif states('media_player.family_room_tv') == "playing"%}
On
{%else%}
Off
{%endif%}

Thanks in advance for any help!

You can place it in a template binary sensor.

e.g.

binary_sensor:
  - platform: template
    sensors:
      someone_presence:
      friendly_name: "Someone"
      device_class: presence
      value_template: "{{ is_state('media_player.family_room_tv', 'idle') or is_state('media_player.family_room_tv', 'home') or is_state('media_player.family_room_tv', 'playing') }}"

or you could shorten the template even more:

value_template: "{{ states('media_player.family_room_tv') in ['idle',  'home', 'playing'] }}"
1 Like