Now thanks to ESPresense, I have a custom sensor called “sensor.avPhone” that changes its state to “office, bedroom, kitchen and etc” depending on which room I am in at the moment. IT take between 2-5 sec to update, which is generally fine.
My question is: How can I automate it by using template or script or both or whatever, so when ANY of my echos speak, It is always from the echo that is in the room that I am in.
**Example:** I have automation every morning at 10am that notify/announce on my "echo_kitchen" to take my vitamins. I dont want to have the "echo_kitchen" hardcoded. If at that time I am in the office I want that notification/announce to be on my "echo_office"
P.S. When I am in the bathroom/restroom I have no ESPresense there or if I am outside my home and it says "not_home" Is there a way to change it to “away” or “offline” or anythng else custom?
One method would be to replace your notify service calls with a script.
alias: Room Presence TTS
description: ''
fields:
message:
name: Message
description: The message you want to have spoken
example: This is a test
selector:
text:
type: text
multiline: false
type:
name: Type
description: Whether to use the 'tts' or 'announce' method
example: announce
selector:
select:
options:
- "tts"
- "announce"
sequence:
- service: notify.alexa_media
data:
message: "{{ message }}"
target: "media_player.echo_{{ states('sensor.avPhone') | default('kitchen', 1) }}"
data:
type: "{{ type | default('tts', 1) }}"
I understand code from the "sequence: below, but not above. Where did that part go? Can you please explain it to me like dumb&dumber I am just getting my feat wet with scripts. I know they are like automations without trigger/condition.
I think I figured it out. This is not a script, but an automation with “scripting”.
I was able to do what I want, thank you
Here is the GUI, for other dumb people like me. The “title” does not do anything in this case.
I dont understand this part default('kitchen', 1) }}"
What does it mean? If there is “not_home” in ESPresense it will speak by default to the Kitchen Echo? How about the 1 after kitchen, and 1 after tts? I guess I can replace the that last line is type: tts or type: announce ?
In the example above it works with type: TTS or without it by default is TTS
When I try go do type: announce it does not do anything, unless set all the targets where I want this aannouncement. The only difference is I hear some kind of bell before Alexa speak my message. Is that it?
Go to the top right of the script editor and select “Edit in Yaml” then paste the whole thing there and save.
The field configuration key allows you to name predefined variable that can be used further along in the script and be seen in the script editor. I have updated it above to also use selectors so it’s a little more UI editor friendly.
No, it is a script, not an automation. Automations have triggers, what I posted does not have it’s own trigger.
default is a filter used with templates used to define a default value. As configured it will default to playing on the kitchen echo, you can change that to whichever room you want or expand the script to do something else entirely. The 1 is a shorthand for true, telling the template to also use the default when the variable is undefined.
Using “announce” does makes a chime sound prior to the message and that is the only difference in general use. But, it is required to use “announce” when outputting to an Alexa speaker group.