In my old Vera system I had the ability to create a scene with a manual trigger. The scene in Vera is more closely aligned with HA automations than HA scenes because Vera scenes had conditionals.
I want to create an action with a condition and trigger it from my Alexa devices.
For example, I want to say “Alexa, do something cool” and turn on/off a device but only if certain conditions are met.
I was thinking of using a boolean input but then I have to take care of the on/off state of the boolean.
I was able to do this in a script but I was wondering if there was an alternative.
You could use two input booleans.
One for the Trigger and one for the condition.
The boolean for the trigger could be reset by a second automation regardless of the condition.
just wondering why 2 input_booleans? Why not have an automation triggered by the input_boolean, condition with what’s already available and have an action at the end that turns the input_boolean off?
Write a script using service_template and put all of your conditions in that, then write an alexa skill that calls that script.
I have this setup to turn tv on and switch to the correct input on the receiver, with the condition to turn the tv on only if it’s off. If the tv is already on, then it just changes input on the amp.
What conditions are you trying to meet for your action to be performed?
play_playstation_script:
alias: play playstation
sequence:
#TURN ON TV IF OFF
- service_template: >
{% if is_state('binary_sensor.livingroom_tv_status', 'off') %}
script.tv_power_script
{% endif %}
#WAIT FOR TV TO TURN ON
- wait_template: "{{ is_state('binary_sensor.livingroom_tv_status', 'on') }}"
#SWITCH INPUT TO (GAME)
- service: switch.broadlink_send_packet_192_168_1_12
data:
packet:
- "JgBQAAABJpQTEhM2ExITEhI3ExITNhM2EzcTEhI3EzYTEhM2EzcTEhM2ExITNhM2ExITEhMSExISEhM2ExITEhM2EzYUNhM2EwAE9QABJkoTAA0FAAAAAAAAAAA="
I’m checking for the state of a binary sensor that I have configured to ping the tv to know if it’s on or not, but anything can be substituted inside the if statement. Then inside one of my Alexa actions I have a call to script.turn_on to activate that script.
ha ha, yes indeed, use the script component, scripts can be triggered just like switches. I can’t speak to scenes as I’ve never used them, everything in my config is either a light, switch, sensor, script or automation.
When you said ‘script’ in your initial post, I thought you were referring to the script component and not actual Python script. Through all of my messing around with HA I’ve always been able to accomplish what I wanted with the built in components, and have never had the need to write a python script.
What kind of Alexa integration are you doing? are you writing intents i.e. “Alexa [Do Something]” or HA Alexa integration i.e. “Alexa Ask Home Assistant to [Do Something]” the former is a bit more complicated, but uses less words spoken to Alexa as you can omit the ‘Ask Home Assistant’ part. The latter is a bit easier to implement, but can sometimes be a mouthful to say to Alexa.
@Rhavin42 So I added the script using your method and I tested the script by calling it from the services panel. I added it to my Alexa configuration but it is not showing up when I do a Discover from the Alexa website.
I verified on the Alexa page that scripts are supported.
Sorry, I’m not going to be much help here. I’m not using HA Cloud. I’m either using the built in hue emulation in order to be able to say “Alexa turn on/off [light name]” these all show up in the Alexa app when I do a discover. Or I’ve got self hosted Alexa Intents (I think that’s the right term.) through HA and Amazon developer website. Where I can say things like “Alexa how’s the pool” and she will respond with the pool temperature from HA, along with some custom flavor text, or “Alexa Bedtime” and she will turn almost everything off if it’s on.
I did it this way because:
I didn’t feel like $5/month was worth it for HA cloud when I was pretty sure I could figure it out myself (It was a pain in the ass but I finally got it).
For some things that I ask Alexa to do all the time, just being able to say “Alexa [Something]” was shorter than either “Alexa turn on/off [Something]” or “Alexa ask Home Assistant to [Do something]”
The kids can never remember the longer Alexa commands, so the shorter I can make them, the more they are able to do with her.