Help with Virtual Switch to Alexa

Hi everyone, HA newbie here and need some help!

I have exposed a template virtual switch to Alexa using the Nabu Casa cloud service, and plan on using it to trigger routines in Alexa directly for some ring camera announcement snoozing I’d like to do.
My problem is I cannot get the switch to change states via a toggle or button dashboard card in HA. I can change its state in the States Developer Tool and Alexa sees the state change, but I can’t do it in HA.

Switch code that’s in my config.yaml below:

switch:
  - platform: template
    switches:
      alexa_snooze_switch:
        value_template: "{{ is_state('sensor.alexa_snooze_switch', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.alexa_snooze_switch_on
        turn_off:
          service: switch.turn_off
          target:
            entity_id: switch.alexa_snooze_switch_off

I have also tried changing the entity_id’s to just the alexa_snooze_switch for both the turn on and off services, but neither way works.
I have also tried the input boolean route and can get that to change via dashboard buttons, but Alexa doesn’t see it change state even though it discovers it when I expose it, so I’m back to attempting the virtual switch.

What am I missing? Thanks in advance.

Infinite regression is not allowed. Use a different entity (like an input boolean) as the target for the actions and to provide the state value.

1 Like

So something like this? Created an input boolean called alexa_snooze_inp

switch:
  - platform: template
    switches:
      alexa_snooze_switch:
        value_template: "{{ is_state('input_boolean.alexa_snooze_inp', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: input_boolean.alexa_snooze_inp
        turn_off:
          service: switch.turn_off
          target:
            entity_id: input_boolean.alexa_snooze_inp

Almost, services are usually domain-specific, so you need to use input_boolean.turn_on / input_boolean.turn_off instead of switch.turn_on / switch.turn_off.

1 Like

Thank you for your help! I actually tried the code I mentioned in my post before your latest response and it worked! Not sure how, but I’ll take it. I will keep this in mind for future switches