I have two scripts, doing different actions to turn ON/OFF my “TV”, like turn on/off projector, roll down the screen, if after sunset turn off/on lights etc.
Trying to find out what would be the best way to be able to tell Alexa with the cloud component to “Alexa turn on tv” and one of the script would run vs. “Alexa turn off tv” and the other script would run.
Easiest thing to do would be with an input boolean with automations, then your input boolean becomes a switch. When turned on, it runs your TV on script, when turned off, it runs your turn off script. I have a very similar set up for TV lights with scenes.
I’m led to believe that the cloud is more configurable for this sort of thing, but I can tell you how I do it in emulated_hue and hopefully it’ll give you some inspiration…
Create an input_boolean called alexa_tv_control, name it “telly 1” or something without the word ‘on’ or ‘off’
In HA create an automation that triggers when input_boolean.alexa_tv_control changes state, action is a service template. If the boolean is switched on, run your turn on script, if it’s switched off run your turn off script.
Then in the Alexa app create two routines
Command “Alexa turn the TV on”, result turn on Telly 1
Command “Alexa turn TV off”, result turn off telly 1
Thank you, guys! I was also thinking of the input boolean switch. Do you know the top of your head if the input_boolean switch is already in ON state, turning it ON again would run the automation? I can imagine a situation, where the TV was turned off on a different way and the input_boolean is still in ON status while the TV is actually OFF.
Thanks!
That’s the thing you have to work around depending on your circumstances.
In my case I cannot monitor whether the TV is on or not, so I have 2 input_booleans, one for on and one for off. When you call the on one it activates the turn on script and then switches the boolean back off, so the booleans are basically always off and only used as a trigger for an automation.
It’s difficult to have a catch-all method because everyone has different tech.
That was exactly my first idea as well since I cannot monitor the status either.
But the problem with this, how can you turn on-off with Alexa by simply saying “Alexa turn on TV” if you have two switches - as far as I know it can be only one switch what you call “TV” and Alexa will be able to turn that ON and OFF. Having two switches will result to have two command and you need to say e.g. “Alexa turn on TV off”. I hope I was able to explain what I mean.
Is there any switch type which can be asked to turn ON even if it is ON?
Actually, I also created an Alexa app. That way is easy to do whatever you want, but you have to tell e.g. “Alexa tell Amy turn on TV” - Amy is the invocation name of the app. For some reason, Alexa did not get it soo many times. I tried with many different invocation names, the tests are always working properly in the testing tool, but when I am saying the same to the Alexa devices (I have both Echo dot and Echo) it does not know what to do. Responses are like: “A few things share this name, which one do you want?” or “TV is not configured go to you Alexa app…” or do not answer at all…
Does anyone else have the same experience?
That’s the reason I am trying to solve it with the Alexa Cloud component.
Just for the records. First of all, thank you @anon43302295 for the support and for thinking with me on the solution.
What I did:
Create two input_boolean, something like this:
input_boolean:
projector_on:
name: Living Room Movie On
initial: off
icon: mdi:television
projector_off:
name: Living Room Movie Off
initial: off
icon: mdi:television-off
Created two scripts, both start with turning off the previous boolean switch and then run the required automation.
Made two automation which simply run the script in #2 when the status of the input_boolean turn to ON, example:
- alias: "Turn ON Livingroom Projector"
trigger:
- platform: state
entity_id: input_boolean.projector_on
to: 'on'
action:
service: script.turn_on
entity_id: script.turn_on_tv
Configured two Alexa routine for the commands “Alexa, Turn TV on” and “Alexa turn TV off”. Of course, I had to first discover devices to see the switches I built.
I am using Alexa cloud, but the same could be easily achieved with emulated hue as well.
This may be new functionality from Alexa/HA Cloud, but scripts now appear under “Scenes” in Amazon App. You could create an Alexa Routine (in the Alexa App) that activates the scene.