On / Off Switch to run same script

I installed a rangehood that has an IR remote to turn the light on/off, and change speed on the two fans from 1 to 4. The power button is a toggle button as well (meaning no separate buttons for on and off).

I am using a Broadlink RM4 Mini sitting on top of my cabinets (the IR is reflected back down to the rangehood) to send the IR signal. The script to turn on and off the light is:

rangehood_light:
  sequence:
  - service: remote.send_command
    target:
      device_id: db7ca8076ede2fb28d1f8337e336b253
    data:
      device: Rangehood
      command: Light
  mode: single
  alias: Rangehood Light

I am trying to enable Alexa to turn on and off the rangehood light by using the appropriate “turn on” and “turn off” commands. Right now, I can say “turn on” for all my commands and it will toggle the light on the rangehood.

Since the rangehood can also be turned on manually, and it will not report back its state, Alexa and HA have to ignore whether it is on or off, and must just send the command. Using the script alone allows me to turn on the light with Alexa but it will not turn off (she says OK but nothing happens).

I lost track of all my attempts, but below is the latest template I have which is not working correctly (no off in Alexa):

switch:
  - platform: template
    switches:
      blind:
        friendly_name: "Rangehood Bulb"
        value_template: "{{ is_state_attr('input.boolean.rangehood_bulb', 'sensor_state', 'on') }}"
        turn_on:
          service: script.turn_on
          entity_id: script.rangehood_light_on
        turn_off:
          service: script.turn_off
          entity_id: script.rangehood_light_off

It is temporarily called “Rangehood Bulb” to avoid conflicts with the “Rangehood Light” script (think verbal commands to Alexa).

On the frontend I currently just call the scripts and had to format it with large buttons to hide the “Run”:

A momentary button, would be ideal given the actual state will most often be wrong. Or… I can create something for Alexa to allow turning on/off verbally and something different for the UI.

Can someone help me unravel this?

  1. How to I turn on / turn off something via a script by telling Alexa to turn it on or off?

  2. Is there something like a momentary button that can fit better in this type of UI design:

You can automate a boolean to switch back off when triggered.
If you place the boolean in header or footer of a entity card it gives you more of a button.

Regarding the rest about knowing the state, the only advice I can give is to add a light sensor.

1 Like

The most important aspect is for Alexa to allow me to turn it both on and off with natural commands. I will explore you suggestions but I have to figure out the Alexa part first in case it affects the latter.

Your “turn_off” script isn’t working because you are turning it off instead of on. You need to change the service to script.turn_on… better yet, just set the service to the script entity_id:

switch:
  - platform: template
    switches:
      blind:
        friendly_name: "Rangehood Bulb"
        value_template: "{{ is_state_attr('input.boolean.rangehood_bulb', 'sensor_state', 'on') }}"
        turn_on:
          service: script.rangehood_light_on
        turn_off:
          service: script.rangehood_light_off

You can use the custom multiple entity row element to add “momentary” buttons to an entities card

@Didgeridrew - Thank you so much!! It works 100% as I was trying to get it to work. The toggle button moves to the right and turns blue, and then reverts a couple seconds later, which is perfectly ok (even though a different looking button would be less confusing for momentary action) for both on and off.

On the Alexa front, I can now say turn on / turn off Rangehood Light and it works perfectly as well.

Thank you so much for the code!

1 Like