I meant 1.1.0. Sry should confuse someone. I changed that.
Thanks for the insights @alandtse. I was under no impression that this was a trivial endeavor so thank you for all your contributions. This functionality is awesome. I can now say âAlexa, Goodnight.â and she and HA do a complete security sweep of the doors and windows and determines if everyone is in the house. And if all is in order, sets the alarm system. If not, she tells me what is not secured.
Brilliant!
Thank you. Iâll be updating to 1.1.0 soon and hope I donât break anything.
Cheers,
Bart
Ok. Rookie here again. (This starting to feel embarrassing )
I need to update last_alexa immediately. How do I put that
âalexa_media.update_last_calledâ
into an automation?
I updated to 1.1.0 and broke everything then fixed it by deleting the old media_player entities and renaming the new ones to the old names. But now Iâm scratching my head on updating the last_alexa as soon as it enters an automation or script. I was hoping to find an example on the wiki page
I create the sensor like this:
- platform: template
sensors:
last_alexa:
entity_id:
- media_player.<all my echo devices>
- media_player.<all my echo devices, etc.>
value_template: >
{{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}
in my script I have:
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: Sorry, a door or window is still open. Please check and try again.
service: media_player.alexa_tts
But this will send speech to a previously used Echo device, not necessarily the one I spoke to. How does a script update it before sending a message back?
First make sure you have 1,1,0 installed OK.
Check Services in the developers tools. Find the service âalexa_media.update_last_calledâ It should be the first service in the list. You can call this with no service data . If this works it should update the sensor immediately. Check by asking different dots questions.
I donât use yaml automatons, but try this
Yes. The call works as expected so Iâm thinking it is the 1.1.0 version. So far, Iâm finding automations that execute scripts sequentially erratic but havenât pinned down the cause. Iâm in the middle of writing an automation that calls 3 scripts sequentially (I think). Each step along the way has a spoken progress sentence. On my first try, the automation did not speak and only the last script had something to say.
Automation:
- id: test3
alias: test sequence of scripts
trigger:
- entity_id: light.security_check
from: 'off'
platform: state
to: 'on'
condition: []
action:
- service: alexa_media.update_last_called
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: Please wait while I run a teast a.
service: media_player.alexa_tts
- data:
entity_id: script.test_a
service: script.turn_on
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: Npw running test b.
service: media_player.alexa_tts
- data:
entity_id: script.test_b
service: script.turn_on
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: Now running test C.
service: media_player.alexa_tts
- data:
entity_id: script.test_c
service: script.turn_on
and the scripts 1, 2, and 3 look like this:
test_a:
alias: test_1
sequence:
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: this is test A.
service: media_player.alexa_tts
test_b:
alias: test_2
sequence:
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: this is test B.
service: media_player.alexa_tts
test_c:
alias: test_3
sequence:
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: this is test C.
service: media_player.alexa_tts
My next step is to put a delay (or wait?) in the automation between script executions and Iâll post back here when I get this sequence to run correctly and sequentially.
EDIT: Ok, the automation seems to run sequentially after I put:
- delay:
seconds: 5
After every TTS call. Iâm sure the amount of seconds will depend on how long the message is to keep it moving along. Some I dropped to 2 seconds for sentences such as âThis is test Aâ
Hope it helps others having the same difficulty.
I use the last alexa to ensure I speak back to the correct echo triggered by the alexa routine .
To hide the delay your experiencing I construct the alexa routine like this
-
Trigger the alexa app with the wake words
-
trigger the dummy bulb ( this will trigger HA with the response)
-
get alexa app to say âplease wait while I checkâ (anything phase will do)
This ensures the last alexa sensor triggers correctly and the correct echo responds. I suspect the delay is caused by the cloud updating
I think Iâm doing all that @lonebaggie. Here is the beginning of the automation:
- id: lockup
alias: Lock Up
trigger:
- entity_id: light.security_check
from: 'off'
platform: state
to: 'on'
condition: []
action:
- service: alexa_media.update_last_called
- data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: Please wait while I run a security check. Checking garaj doors now.
service: media_player.alexa_tts
- delay:
seconds: 4
- data:
entity_id: script.security_1
service: script.turn_on
I have 4 scripts doing certain checks in sequence by this automation. They only speak if something is not right (like a door is open) if they run, they turn off the light.security_check so the next script wonât run.
But that first âalexa_media.update_last_calledâ doesnât bring the TTS to the echo that I asked to run lockup. When I put a delay right after the call it appears to work fine.
The automation and scripts run too fast and cut off the TTS responses either partially, or fully. So I need the delays after each stage to allow Alexa to finish speaking before the next part runs. This should have been so easy, but itâs being unbelievably problematic. If I knew python scripting, I just might have done this in appdaemon.
Move The delay to the alexa app. I assume the light.security_check is the dummy bulb triggered by the alexa app.
So if the alexa routine is triggered by say âalexa run security checkâ. Then in the alexa app
-
turn on the dummy bulb (this will trigger your automation)
-
in the alexa app get alexa to say âPlease wait while I run a security check. Checking garaj doors nowâ
This should give you enough of a delay
That sounds like it may work, but when the automation kicks off, it will fire the alexa_media.update_last_called service call pretty quick and not wait for Alexa to finish her intro speech. If the first script finds an issue, the speech from that script will cut off Alexaâs intro unless I delay. So either way I would have to put a delay in before running script 1.
My automation worked flawlessly last night while all the windows and doors were closed. Next Iâll be testing various states that the 3 scripts were designed to detect and either do something about it or simply tell me to go close the door and stop processing.
Youâve been a big help @lonebaggie. Thank you.
Ah, finally I understand. I had similar issues. You have to gather all the information, before you issue the TTS to alexa. The â,â is the only tool you have to make the speech sound more natural with a pause . If you issue multiple TTS requests they will cut each other off
Adding delays to script may have issues as HA may not be able to react to anything else while its waiting
Not sure if HA automations allow you to store information or pass parameters between scripts. This is why I wrote Speech Parser script , but basically you need to gather all the information , then speak
FYIâŚanother data point:
After playing around with this I found I needed to add a delay of about 1 second between the service call to update the âlast alexaâ and the service call to play tts.
- delay: 00:00:01
- service: media_player.alexa_tts
data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: >
If I did not have this delay, the update was either too slow (sending tts to the wrong device), or would end up with an exception in the alexa custom component itself (ex. a JSON Decode âexpecting valueâ exception).
Thanks @wmaker. Iâve noticed the occasional âIâm sorry, but something went wrongâ speech from Alexa when I move to a different echo device. Itâs not consistent, but Iâll try adding the delay to see if that stops it.
Iâve just got last_alexa working today after following this thread, but Iâve noticed a strange issue I canât seem to figure out.
Iâm using this sensor in an automation to ask Alexa what my pool temperature is, and it works flawlessly as long as I ask my basement echo dot, or my bedroom echo spot, but for some reason if I ask the echo dot in my spare bedroom, I get the wrong temperature.
My sensor is set up correctly, as when I update the sensor it gets the right device, and it replies to me on whichever device Iâm asking, but in the bedroom and basement I get âThe current temperature is sixty-four point four degreesâ, while in the spare bedroom she responds with âThe current temperature is 32 point zero degreesâ
The TTS message is the same, regardless of which device is playing it, so Iâm not even sure how one device could possibly get a different response than the rest:
message: The current temperature is {{states('sensor.converted_pool_temp')|replace('.', ' point ') }} degrees
Hi all, after a long time I use alexa media component, updated to the last version, I created sensor last alexa, including 2 entities of my 2 echo devices, but the sensor shows always only 1 of the media players even if I use them calling tts, also waiting for the scan interval time (I set 30 seconds).
I donât know why the sensor is not refreshing to the last alexa device used
Thanks for this thread!
Now Iâm able to receive sensors information very easily.
Is it possible to have it work also from my smartphone or tablet app?
Iâve done ./alexa_remote_control.sh -a
and I see
Vittorio's Alexa Apps
This device
in addition to my Echos and TV Fire Sticks.
Iâve added both to my configuration.yaml, but only the first one is added.
In any case, does not work on my phone (for example) .
Is there a way to let it work this way?
Thanks
Using the code edited in the top post, I have a sensor.last_alexa that when I check the states is appropriately updating showing:
media_player.echo_show
(same as when I type {{ states.sensor.last_alexa.state }} into template editor)
When I try to reference it in a media card though I get
a.entity.split is not a function
artwork: full-cover
entity:
â[object Object]â: null
type: âcustom:mini-media-playerâ
code is:
- artwork: full-cover entity: {{ states.sensor.last_alexa.state }} type: 'custom:mini-media-player'
What am I doing wrong here? Tried with and without 's and "s
Last Alexa Called has stopped working for me in v2.5.1. Only 2 out of 5 Alexaâs I have triggered it, reverted back to 2.5.0 and works fine.
Now fixed in 2.5.2
I donât know how long this will work, but this seems to work for now.
- service: media_player.play_media
data:
entity_id: media_player.echo_show_8
media_content_id: "play Dog Bark by halloween haunters"
media_content_type: "AMAZON_MUSIC"
Hello. I am using this template.
sensor:
- platform: template
sensors:
last_alexa:
entity_id:
- media_player.1
- media_player.2
value_template: >
{{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}
Entity_id has been deprecated since 0.115 update. How to rewrite the list within the template and not create a group list?