Create a switch to run different scenes when turned on and off?

Here’s my Emulated Hue config

emulated_hue:
  type: alexa
  host_ip: PI-IP-ADDRESS
  exposed_domains:
    - group
    - input_boolean
    - scene
    - script
    - switch

If you need any more info let me know

I have a Pi exposed to the internet and tried setting up it up as a skill, but had a problem with Amazon/Alexa talking to HA

All I can tell you is that should work, but again, I don’t use emulated Hue, I use the skills.

OK, thanks.

So you don’t know a way of creating a different type of switch to do the same thing? (switch template or something?)

Here is a switch template example that turns off a scene.

Thanks, it looks like it should be possible with that.

Although I’m not sure how I’d adapt it to my simpler switch (just turning on/off scenes or scripts).
I don’t think my understanding of Home Assistant is quite up to that :sweat_smile:

The alternative is to use automation and input select like here. The automation will run your scene when input select goes on and run a scene when it goes off.

The template switch should work but you need to decide how you want its state to appear. If it doesn’t matter how it appears, then you should replace value template with anything.

switch:
  - platform: template
    switches:
      my_scene_switch:
        value_template: "{{ is_state('my_scene_switch', 'on') }}"
        turn_on:
          service: scene.turn_on
          entity_id: scene.my_scene_on
        turn_off:
          service: switch.turn_off
          entity_id: scene.my_scene_off

Thanks a lot for this. It’ll most probably just be used for emulated hue, so won’t matter what it looks like.

I’ll give it a try in the morning, and see if I can get it up and running.

As a follow up to this I tried the test example you wrote and it works really well (and works fine when activated via emulated hue with Alexa) :slight_smile:

I just had to alter the bottom part to

turn_off:
  service: scene.turn_on
  entity_id: scene.my_scene_off

instead of

   turn_off:
      service: switch.turn_off
      entity_id: scene.my_scene_off

So I’ve now done this for all the scenes/scripts I was trying to use previously with Input Boolean (and for some reason wouldn’t work with Alexa).

So thanks a lot (again) for this!

I can’t seem to get this working :frowning:
I tried many things.
Error I get now is:
2017-11-11 17:15:55 ERROR (MainThread) [homeassistant.config] Invalid config for [switch.template]: [Badkamer_Verwarming] is an invalid option for [switch.template]. Check: switch.template->switches->Badkamer_Verwarming. (See ?, line ?). Please check the docs at https://home-assistant.io/components/switch.template/

And this is what i have in my config:

switch:
  - platform: template
    switches:
      Badkamer_Verwarming:
        value_template: "{{ is_state('switch.Badkamer_Verwarming', 'on') }}"
        turn_on:
          service: scene.turn_on
          data:
            entity_id: scene.badkamer_aan
        turn_off:
          service: scene.turn_on
          data:
             entity_id: scene.badkamer_uit

I also tried:

switch:
  - platform: template
    switches:
      Badkamer_Verwarming:
        value_template: "{{ is_state('Badkamer_Verwarming', 'on') }}"
        turn_on:
          service: scene.turn_on
          data:
            entity_id: scene.badkamer_aan
        turn_off:
          service: scene.turn_on
          data:
             entity_id: scene.badkamer_uit

Anyone has any idea?

Try this

switch:

  - platform: template
    switches:
      badkamer_verwarming:
        value_template: "{{ is_state('badkamer_verwarming', 'on') }}"
        turn_on:
          service: scene.turn_on
          entity_id: scene.badkamer_aan
        turn_off:
          service: scene.turn_on
          entity_id: scene.badkamer_uit

Any good?

So capitals letters are not allowed. No errors now but…when I flip the switch it does trigger the scene (badkamer_aan), however the switch flips rigth back to the off state.
So I can’t flip it off manually to run the turn_off scene.
Any idea about that? :slight_smile:

That’s right, you only use lowercase for the code (but can use uppercase letters, spaces etc. in the friendly_name under customize).

Not sure why it would keep switching off. Is there anything else in your code somewhere else that’s could be causing that?

You’ve got a circular reference here. The value template says if this switch is “on”, set the status of this switch to “on”. That’s not going to work.

If you want to stick with a template switch, change the template to something that changes state with your scenes.

I don’t understand your last sentence.

My goal is that I have 1 switch to “toggle” the running of 2 separate scenes.
When turned on it runs the scene that turns my heater on and when turned off it should run the scene that turns my heater off.

I thought reading the earlier posted code would do that.

Let’s say your heater is switch.heater.
Let’s say further that switch.heater is turned on with scene.badkamer_aan and switch.heater is turned off with scene.badkamer_uit.

The you could use this template to determine if the switch is on or off:

“{{ is_state(‘switch.heater’, ‘on’) }}”

Ah ok I understand. Problem is, the heater itself is not a switch. I set a temperature and then the zwave device opens/closes the valve more or less.
So the only reading I can do is the temperature.
If above 26 degrees then the (on) scene to put it on that setting was run.
If it’s below 15 the (off) scene ran to put it on that setting.

So you know how I can change that value template to check whether it’s above or below a certain temp?

I think I’m running into similar problems, I can press once and it seem to activate the scene but it seem to reset the scene state to off even tho its the good one playing. when I press again , nothing happen (probably because its trying to re-do the same scene).

here is what my template looks like:

- platform: template
    switches:
      my_cinema_scene:
        value_template: "{{ is_state('my_cinema_scene', 'on') }}"
        turn_on:
          service: scene.turn_on
          data:
            entity_id: scene.cinema
        turn_off:
          service: scene.turn_off
          data: 
            entity_id: scene.cinema_off

any ideas?


Try changing the type of switch from a toggle to the other kind (can't remember what it's called). Add this in customize.yaml
switch.my_cinema_scene:
  assumed_state: true

Also, for `scene.cinema_off` you should be turning it on (`service: scene.turn_on`), not `service: scene.turn_off` I think.