@alandtse Ok I put the code from @petro into the wiki, instead of the one that was there before. Hope that was ok. The example before did not have the entity id’s, ending in a blank state.
Did not know that it was so easy to change the wiki. It doesn’t need confirmation of you @alandtse? Do you at least get a notification that someone changed it, so in case it is none-sense, you can change it back?
Thanks. Git has a history so we can revert it if someone destroys stuff. If we notice issues, we may lock it down, but for now, I think most people want to help.
If you have 1.1.0, any future updates will be available through custom_updater. So in theory, updating to 1.1.0 is the last one you have to do manually.
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?
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.
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’
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.
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.
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.
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