-
Notifications
You must be signed in to change notification settings - Fork 291
Automation examples
- Text to Speech (TTS)
- Live Sensor Reports
- Activating Alexa Routines
- Activating Alexa Sequence Commands
- Room Aware Alexa Routines
Send TTS message after a sensor change: (Be sure to use 'data_template:' when templating.)
scripts.yaml - type: announce (Will make a "ding" sound before speech), type: tts (Alexa will speak right away)
doorbell:
sequence:
- service: media_player.volume_set
entity_id: media_player.downstairs
data:
volume_level: '1.0'
- service: notify.alexa_media
data:
data:
type: tts
target:
- media_player.downstairs
- media_player.upstairs
message: 'Ding-dong. Someone is at the door.'
alexa_announce_example:
sequence:
- service: notify.alexa_media
data:
target: media_player.[NameOfEcho]
message: "This is an example of an announcement"
data:
type: announce
method: all # or speak or show
automation.yaml
- id: washing_machine_finished
alias: Washing machine
trigger:
- entity_id: sensor.washing_machine
platform: state
from: Washing
to: Not washing
action:
- service: notify.alexa_media
data:
data:
type: announce
target:
- media_player.downstairs
- media_player.upstairs
message: 'Yo Remco.. The washing machine is finished. Get off the couch.'
Templating also works in script/automation: (Be sure to use 'data_template:' when templating.)
remco_home:
alias: Remco comes home
sequence:
- wait_template: '{{ is_state(''sensor.broadlink_s1c_sliding_door'', ''open'') }}'
timeout: 00:08:00
- delay: 00:00:12
- service: notify.alexa_media
data_template:
data:
type: announce
target: media_player.downstairs
message: 'Hello Remco. Welcome home. Cherry is {% if is_state("device_tracker.cherry",
"home") -%} also at home. {%- else -%} not at home. {%- endif %} The temperature
inside is {{ states("sensor.broadlink_sensor_temperature") }} degrees. And
outside it is {{ states("sensor.weather_temperature") }} degrees.'
remco_woke_up:
sequence:
- service: notify.alexa_media
data_template:
data:
type: tts
target:
- media_player.upstairs
message: 'Hello Remco. Goodmorning. The temperature outside is {{ states("sensor.weather_temperature")
}} degrees. There will be {% if states("sensor.weather_precipitation") == '0.0' -%}
no rain today. {%- else -%} {{states("sensor.weather_precipitation")}} milimeter
of rain today, bring an umbrella. {%- endif %} Your first calendar item is;
{{ states("sensor.next_appoint_remco_message") }}, at {{ states("sensor.next_appoint_remco_tijd")
}}. Your Travel time to work is approximatly {{ states("sensor.waze_travel_time")
}} minutes if you take {{ states.sensor.waze_travel_time.attributes.route
}}. Have a nice day'
service: media_player.alexa_tts
Using the Last Alexa Sensor and Alexa routines to have Alexa provide information about your HA sensors.
In your sensors.yaml
- platform: template
sensors:
last_alexa:
entity_id:
- media_player.your_echo_name
- media_player.your_echo_name_2
- media_player.your_echo_name_3
- media_player.your_echo_name_4
value_template: >
{{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}
Put this in your configuration.yaml. If you have a lights.yaml, put this there.
light:
- platform: template
lights:
alexa_virtual:
friendly_name: "Alexa Dummy Light"
turn_on:
turn_off:
set_level:
This is the automation
- alias: "Alexa Report"
trigger:
- platform: state
entity_id: light.alexa_virtual
to: 'on'
condition:
action:
- service: alexa_media.update_last_called #this will force update the last Alexa attribute used by the sensor
- delay: 00:00:01 # you may need to increase this value if you dont get the response on the echo you asked the question
- service: notify.alexa_media
data_template:
target:
- '{{ states.sensor.last_alexa.state }}'
data:
type: tts
message: >-
{% if (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 1 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion. For example Degreess
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 2 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion. For example miles
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 3 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion For example minutes
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 4 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 5 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 6 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 7 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 9 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 10 %}
Words. What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
{% else %}
{{ states('light.alexa_virtual.attributes.brightness') }}
{% endif %}
- service: light.turn_off
entity_id: light.alexa_virtual
You need to then expose the "light.alexa_virtual" to your alexas. This is the same as exposing any HA device to your alexa's and not directly related to this component. You can do this with emulated_hue, haaska, or the HA cloud.
Once the light is exposed and you can turn it on/off, etc with your voice start the next steps
Use the alexa app to create a routine Click + to create a new routine Click the + next to "when this happens" Click on Voice and enter what you want to say. For example "Alexa, give me the surf report" Then click on add action I recommend you add a step for "Alexa Says" and enter a short phrase "Let me check for you" is good example Then add another step Smart Home --> Control Device --> Select your Alexa Dummy Light and then select brightness Select a value from 1 to 100, the number will correlate to the automation above Click Save, give it a few minutes, and try it out.
Good uses of this would be to get temp info of a sensor, distance/time to a location using a waze/google sensor, tides, doors open/closed, etc.
First make a routine in the Alexa App. Make the invocation, the same phrase you want to use in the media_content_id:. You can let Alexa read your flash briefing, news, traffic, the weather, your next calendar event, random/custom phrases and all other features available in the Alexa App under Routines. With the entity_id , you can set wich echo will carry out the routine.
scripts.yaml
remco_awake:
alias: Remco woke up
sequence:
- data:
entity_id: media_player.upstairs
media_content_id: remcowakeup
media_content_type: routine
service: media_player.play_media
- wait_template: '{{ is_state("sensor.broadlink_s1c_living_room_door", "open") }}'
- data:
entity_id: media_player.downstairs
media_content_id: remcodownstairs
media_content_type: routine
service: media_player.play_media
Look for available sequences in Sequence commands This is case sensitive, so copy it exactly as it is in the list.
automation.yaml
- id: Remco_welcome_home
trigger:
- platform: state
entity_id: device_tracker.remco
to: home
action:
- wait_template: '{{ is_state("sensor.broadlink_s1c_sliding_door", "open") }}'
- data:
entity_id: media_player.downstairs
media_content_id: Alexa.ImHome.Play
media_content_type: sequence
service: media_player.play_media
condition: []
If you have an echo in every room you can use the sensor.last_alexa
to turn lights or switches on or off in the room you are currently in.
Here are four variations of turn on the lights
routines you may like to setup.
- "turn on the lights"
- "turn on the light"
- "turn on lights"
- "turn on light"
Don't forget to add the "off" Alexa Routines as well. You could setup more routines for on/off, open/close, raise/lower... you get the idea.
In your Alexa app match your Alexa Routines to following scripts. (Using homeassistant.turn_on
allows you to turn on both light.
, switch.
, and group.
entities.)
scripts.yaml
# "Alexa, turn on the lights"
alexa_turn_on_the_lights:
sequence:
- service: homeassistant.turn_on
data_template:
entity_id: >-
{# Use the name of each Echo to determine which room the command likely came from. #}
{%- set room = states("sensor.last_alexa")|replace('media_player.','') -%}
{%- if room == "kitchen" -%}
group.kitchen_lights
{%- elif room == "family_room" -%}
light.family_room
{%- elif room == "master_bedroom" -%}
light.bedroom
{%- elif room == "play_room" -%}
light.play_room
{%- endif -%}
# "Alexa, turn off the lights"
alexa_turn_off_the_lights:
sequence:
- service: homeassistant.turn_off
data_template:
entity_id: >-
{# Use the name of each Echo to determine which room the command likely came from. #}
{%- set room = states("sensor.last_alexa")|replace('media_player.','') -%}
{%- if room == "kitchen" -%}
group.kitchen_lights
{%- elif room == "family_room" -%}
light.family_room
{%- elif room == "master_bedroom" -%}
light.bedroom
{%- elif room == "play_room" -%}
light.play_room
{%- endif -%}
Bonus Tip: Do you have an echo in one room which overrides the Echo in another room? This limitation can be circumvented by changing the wake word to something different on one of the Echos (ie. change one to "Computer").