Template sensor - help please

I’m going around in circles and would appreciate any assistance, please.

I have three template switches (switch.av_satellite, switch.av_tv and switch.av_music). These are called by scripts that ensure that only one of these can be on at any one time.

What I am trying to do is create a template sensor named av_mode, the state of which will contain the name of whichever one of the template switches is on.

Thank you.

Here’s one way:

state: >
  {% if is_state('switch.av_satellite','on') %}
    Satellite 
  {% elif is_state('switch.av_tv','on') %}
    TV
  {% elif is_state('switch.av_music','on') %}
    Music
  {% else %}
    Unknown
  {% endif %}

Thanks you! I was close but wasn’t getting the syntax correct!

I really appreciate your help!

1 Like