Check Config did not show any error?
I just did some of my light switches to expose them to Alexa but the ones I have in my scripts.yaml are indented differently:
A script is ‘on’ as long as it’s running and then goes to off.
You should group your switches and use the state of the group for the value_template. value_template: "{{ is_state('group.your_switches', 'on') }}"
I have the exact same problem. Not sure what you mean by grouping the switches, since there is only one switch???
I tried adding an input_boolean and used that to set the state of the template switch. That worked insofar as the template switch remained in the on state, but then the scripts would not run, neither on nor off.
That’s because @Asaf_Davidof has multiple switches in his script.
If you have only one switch in the script, then value_template: "{{ is_state('switch.your switch', 'on') }}"
should work.
Thanks a lot, but this made no difference. The scripts are only run when the template switch is set manually, not when it is set by the input_boolean…
Just to explain what I am trying to do: I want to use Alexa to turn on/off the stereo. Thus I need a single switch or an input_boolean that Alexa can set and that will run the remote commands.
The scripts work fine when run manually. Next I will try to run the scripts as automations directly off the input.boolean state. If that doesn’t work I am out of ideas.
Seems like there should be a simpler solution. Still don’t understand why the template switch didn’t work. Oh well, at least it works now. Thanks for the support!
I had the excact same problem with alexa, and devices that doesn`t report back states.
The problem you now will encounter, is that if you turn off your your stereo from your remote, the state of the input_boolean will still be on, so when you ask alexa then, it will not excecute your on-script.
What you want is a template switch that excecutes your command, regardless of the state of input boolean (template switches can be on, but still excecute the on-scripts).
I saw you were close earlier, just adjust the template to if is_state like this:
Thanks a lot but we’re not quite there yet. This doesn’t work either. It is just the same as my first attempt: the template switch tracks the input_boolean but the commands are not executed. If I set the template switch manually, the on command is executed but the switch turns right back off.
Guess I’ll have to spend some more time understanding templating. It is still a mystery to me.
Good catch on the risk for state mismatch if someone uses the physical remote though. Maybe I’ll just hide that…
Yes! Using the scripts work, even though the template switch stays on all the time. It also requires that the input_boolean is set to initially: on and then never touched. Thank you so much for your help and Happy Easter!
Glad you got it working I do not have any initial state on my input_boolean which also works, but since it`s never touched, that is irrelevant. Happy Easter!
I have the same problem as the topic starter. Created a switch which uses an on/off script but somehow the when I turn on the switch it goes back to off after 2 seconds.
I tried various combination with input_boolean or directly calling the remote send service but all does same. Any idea why?
Currently I have this:
configuration.yaml:
input_boolean:
aircopower:
name: Airco Power
initial: off
scripts.yaml:
airco_on:
alias: Airco Power On
sequence:
- service: remote.send_command
entity_id: remote.xiaomi_miio_192_168_2_70
data:
command:
- 'm01mcwlk3m03mEsms5mEsmc0mgBHgEfLJiAR4EdzECPwCPA18FnwCFmoCPgWeCh4EfzCWTYIopnMwDSm0yCYYAg5iAR4DUgR+ARYI7ga9NQGjnABCzMAhAI/AjoEdJsA14DTg++BH4VWzMOAwCCm80G9IAg5hAA='
icon: hassio:fan
airco_off:
alias: Airco Power Off
sequence:
- service: remote.send_command
entity_id: remote.xiaomi_miio_192_168_2_70
data:
command:
- 'm01mcwlk3m03mEsm0ymEsmc0mABHgEfLJjNJiAi4BEARvM5wBG4FkAa+AjAKFAEfMZqAj4FizUGJwCIBH8CzwBCAj8AiwHimIKDgEKBZ4DTTYPvwUPAR8KGwdJBHQBrwEfBQ8CPgCECGabzQb0gCDmEA'
icon: hassio:fan
So, the on/off script works and so the switch does but the switch state goes automatically to off again after 2 seconds (without sending the off command).
If I do it manually to off within those 2 seconds the off command is sent.
can you give me a hint please, how to call a script entity by addressing a switch. or light. entity?
Broadlink sends IR commands by scripts, but script entities are not compatible with all the cards.