Second switch when the first is unavailable

I’ve been searching the forums and posting in Discord. I have a few switches/plugs/lights that have a LAN option and a Cloud option. Ie. Meross, Tuya, etc.

So I wanted to have a switch template that tries the LAN option first, then if that doesn’t work it reverts to the Cloud option. Here are some I found during my search, but none were exactly the same scenario:

Eventually I made the following "combined/dual" switch template as follows:

      meross_fan_combined:
        friendly_name: "Fan Combined"
        value_template: >
          {% if is_state('switch.meross_lan', 'unavailable') %}
            {{ states('switch.meross_cloud') }}
          {% else %}
            {{ states('switch.meross_lan') }}
          {% endif %}
        turn_on:
          service: switch.turn_on
          target:
            entity_id: "{% if is_state('switch.meross_lan', 'unavailable') %} switch.meross_cloud {% else %} switch.meross_lan {% endif %}"
        turn_off:
          service: switch.turn_off
          target:
            entity_id: "{% if is_state('switch.meross_lan', 'unavailable') %} switch.meross_cloud {% else %} switch.meross_lan {% endif %}"

I wanted to share it for anyone that may search and find the same thing and maybe even for my future self :slight_smile:

Thanks, future me already needed it :rofl:

  - platform: template
    switches:
      meross_fan_combined:
        friendly_name: "Fan Combined"
        value_template: >
          {% if is_state('switch.meross_lan', 'unavailable') %}
            {{ states('switch.meross_cloud') }}
          {% else %}
            {{ states('switch.meross_lan') }}
          {% endif %}
        turn_on:
          service: switch.turn_on
          target:
            entity_id: "{% if is_state('switch.meross_lan', 'unavailable') %} switch.meross_cloud {% else %} switch.meross_lan {% endif %}"
        turn_off:
          service: switch.turn_off
          target:
            entity_id: "{% if is_state('switch.meross_lan', 'unavailable') %} switch.meross_cloud {% else %} switch.meross_lan {% endif %}"
1 Like