NEAT ! I just started with TTS last week end I was looking how to give it more ‘personality’ this week-end. I will definitely try something like you !
My favorite:
"Welcome Home " ~ person + ". We have missed you. Or at least Molly did."
Guessing that Molly is the dog… hilarious!
I would love to have this Bugs Bunny clip played for random folks that open the door:
Molly is our cat. She occasionally plays guard dog though…
After we put our fake dog barks on snooze for 30 minutes.
Priceless. We need to make Molly the HA Mascot.
Thanx for sharing the code! I am using Alexa and Google Home. Anyone who can point me into the right direction?
Hi all,
please help to debug this… I spent the whole last night debuging and at a loss what is wrong.
I am on 0.53 version of HA.
my configs are passing the checks and there are no errors loading HA.
‘People Greeting’ automation fails…
Underlying scripts work fine.
I pretty much now trying to make CCOSTAN’s code work on my HA.
My Sonos TTS script itself works and I tested it with some hardcoded values. ‘Dexter Pee Call’ script works perfectly. But my automation below, which calls simular script fails with the error: “trigger is undefined”
Btw, Dexter is my dog and what I am really building here is ability for him to communicate with us.
I already have AWS IOT button and a lambda function working, so when Dexer press the button attached to the door, it goes out via Lambda to an MQTT server and back to HA to either speak the request to go pee over Sonos or send a push notification to our phones if we are not home. The idea is to make his “pee call” dynamic and level of intensity of the message will depend on how many times he pressed the button… So that at first it will be like (depending on who is home): Daddy or mommy I want to go pee. and after a few times we ignore him, it will be more like: “I will pee on the floor now if you will not take me out…” I also plan to switch do Yandex TTS, because it allows for voice intonation. and I can make the voice more angry with later messages.
I looked at other threads where people had the same error and my syntax does not contain the errors that helped the other person. For example I am already using data_template and my yaml indents seem correct… But maybe not… Please help to spot what is wrong…
Here is the error:
Sep 13 08:22:29 HomeControl hass[2156]: 2017-09-13 08:22:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: entity_id=automation.people_greeting, message=has been triggered, domain=automation, name=People Greeting>
Sep 13 08:22:29 HomeControl hass[2156]: 2017-09-13 08:22:29 INFO (MainThread) [homeassistant.helpers.script] Script People Greeting: Executing step call service
Sep 13 08:22:29 HomeControl hass[2156]: 2017-09-13 08:22:29 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Sep 13 08:22:29 HomeControl hass[2156]: Traceback (most recent call last):
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/template.py", line 102, in async_render
Sep 13 08:22:29 HomeControl hass[2156]: return self._compiled.render(kwargs).strip()
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 1008, in render
Sep 13 08:22:29 HomeControl hass[2156]: return self.environment.handle_exception(exc_info, True)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 780, in handle_exception
Sep 13 08:22:29 HomeControl hass[2156]: reraise(exc_type, exc_value, tb)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/jinja2/_compat.py", line 37, in reraise
Sep 13 08:22:29 HomeControl hass[2156]: raise value.with_traceback(tb)
Sep 13 08:22:29 HomeControl hass[2156]: File "<template>", line 1, in top-level template code
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/jinja2/sandbox.py", line 385, in getattr
Sep 13 08:22:29 HomeControl hass[2156]: value = getattr(obj, attribute)
Sep 13 08:22:29 HomeControl hass[2156]: jinja2.exceptions.UndefinedError: 'trigger' is undefined
Sep 13 08:22:29 HomeControl hass[2156]: During handling of the above exception, another exception occurred:
Sep 13 08:22:29 HomeControl hass[2156]: Traceback (most recent call last):
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
Sep 13 08:22:29 HomeControl hass[2156]: result = next(coro)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/automation/__init__.py", line 343, in async_trigger
Sep 13 08:22:29 HomeControl hass[2156]: yield from self._async_action(self.entity_id, variables)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/automation/__init__.py", line 433, in action
Sep 13 08:22:29 HomeControl hass[2156]: yield from script_obj.async_run(variables)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/script.py", line 151, in async_run
Sep 13 08:22:29 HomeControl hass[2156]: yield from self._async_call_service(action, variables)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/script.py", line 181, in _async_call_service
Sep 13 08:22:29 HomeControl hass[2156]: self.hass, action, True, variables, validate_config=False)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 74, in async_call_from_config
Sep 13 08:22:29 HomeControl hass[2156]: config[CONF_SERVICE_DATA_TEMPLATE]))
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 70, in _data_template_creator
Sep 13 08:22:29 HomeControl hass[2156]: for key, item in value.items()}
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 70, in <dictcomp>
Sep 13 08:22:29 HomeControl hass[2156]: for key, item in value.items()}
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 72, in _data_template_creator
Sep 13 08:22:29 HomeControl hass[2156]: return value.async_render(variables)
Sep 13 08:22:29 HomeControl hass[2156]: File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/template.py", line 104, in async_render
Sep 13 08:22:29 HomeControl hass[2156]: raise TemplateError(err)
Sep 13 08:22:29 HomeControl hass[2156]: homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined
Sep 13 08:22:29 HomeControl hass[2156]: 2017-09-13 08:22:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1973448880-89>
Sep 13
Here is my automation and scripts:
- alias: 'People Greeting'
trigger:
platform: state
entity_id: device_tracker.dmitry
from: 'not_home'
to: 'home'
for:
minutes: 1
action:
service: script.arrive_greetings
data_template:
speech_message: >
{% set person = trigger.entity_id.split('.')[1]|replace('_', ' ')%}
{%- macro greeting_sentence(person) -%}
{{ [
"Welcome back home " ~ person,
"Guess who is home?" ~ person +" is!",
person + " is now in the house.",
"Welcome Home " ~ person + ". We have missed you. Or at least Dexter did.",
"Our home is now complete, Rest your head and relax your feet! Welcome Back " ~ person,
"Life is like a song, you’re back where you belong. Welcome home " ~ person,
"Hey there " ~ person + " Welcome Home!",
"Knock Knock. Who is There? " ~ person +" is!",
person ~ "! You are home!",
"I know a secret! " ~ person +" is home!"
] | random }}
{%- endmacro -%}
"{{greeting_sentence(person)}}"
And the script it calls below:
(note that dexter_pee_call script works perfectly. I used it to test… Dexter is my dog btw… )
arrive_greetings:
alias: "Greetings on Arrival Home"
sequence:
- service: script.sonos_say
data_template:
sonos_entity: media_player.living_room
volume: 0.4
message: "{{ speech_message }}"
delay: '00:00:03'
dexter_pee_call:
alias: "Dexter Pee Action Script"
sequence:
- service: script.sonos_say
data:
sonos_entity: media_player.living_room
volume: 0.4
message: 'Daddy, I want to go pee'
delay: '00:00:03'
sonos_say:
alias: "Sonos TTS script"
sequence:
- service: media_player.sonos_snapshot
data_template:
entity_id: "{{ sonos_entity }}"
- service: media_player.sonos_unjoin
data_template:
entity_id: "{{ sonos_entity }}"
- service: media_player.volume_set
data_template:
entity_id: "{{ sonos_entity }}"
volume_level: "{{ volume }}"
- service: tts.google_say
data_template:
entity_id: "{{ sonos_entity }}"
message: "{{ message }}"
- delay: "{{ delay }}"
- service: media_player.sonos_restore
data_template:
entity_id: "{{ sonos_entity }}"
Try changing out the trigger variable and work backwards…
{% set person = “Dexter” %}
Hi CCOSTAN,
I have done exactly that and it works.
{% set person = “Dexter” %}
This line:
{% set person = trigger.entity_id.split(’.’)[1]|replace(’_’, ’ ')%}
seem to be causing a problem.
Can you explain what it does? it seem to split the “device_tracker.dmitry” on the “.” into the array of
{‘device_tracker’,‘dmitry’) and you are taking array slot [1], which is "dmitry’
but then you replacing “underscore” with a "space " Why? There is not an underscore in device tracker id?
unless you are assuming that device tracker is owntracks something like “dima_dmitry” and you want to further split it on “_” ???
Anyhow, I tried to modify that code and removed spliting on “_” but it still fails with the same error.
Any ideas?
Also, what happens when multiple people arrive at the same time?
@CCOSTAN, this speech engine obviously took you a serious amount of time to build.
If i go and make a speech engine myself, what is the best way to start building it? This to prevent myself from finding out i did it all wrong halfway
- i’d like a buildup where a bunch of switches determine what phrases to use
- the incoming request sets all the right states to the switches
- all the different variations of messages are then triggered by just 1 action
atleast, that’s what i get from looking at your code
Thanks. For me it was about reusability of the code. Think about all the types of variables you will want to send to the engine. Who, What, where basically. and build an override for emergencies…
Mine is still a work in progress though…
Are you willing to share your buildup schematically? like: the speech action refers to this script, refers to this template, triggered by this bool…
I’ve written some of my thoughts down at my Blog :
Schematically will be tough as the house speaks VOLUMES throughout the day for all sorts of various things. Take a look at my house’s twitter feed as well. The twitter feed is very similar to my speech throughout the house.
Https://twitter.com/BearStoneHA
-Carlo
@CCOSTAN Thanks for making your configs public. Being new to Hassio and yams, python, json and so on…I can certainly learn from this. Trying to understand how one can test your speech_engine by triggering it from the dev-service, i’m having trouble passing the correct parameters.
can anyone show how to pass the parameters for @CCOSTAN speech_engine from dev-service as well from an automation?
Really enjoying trying to learn as much as possible. I’ve went in circles for days but somehow can’t get this to work.
From the dev service, select the name of the script you use to create the message and in the data field add the bits you want to call, something like:
{
"call_greeting" : 1 ,
"call_introduction" : 1 ,
"message" : "THIS IS A TEST" ,
"call_bye" : 1
}
@anon43302295, thank you very much, that looks so simple, i guess this is part of the learning curve. i ran it and i heard the engine running. this puts me in the right direction. Thanks again.
Sorry to bring up an old thread again but anyone know about “random” still working?
I get an error from the CONFIG because of the character “|”
ie:
action: - service: tts.google_say entity_id: media_player.living_room_home data_template: message: > '{{ ["OK", "Sure", "If you insist", "Done"] | random }}'
This is what I use.
automation.yaml
- id: family_greeting
alias: Family Greeting
trigger:
platform: state
entity_id:
- binary_sensor.cameron_home
- binary_sensor.corey_home
- binary_sensor.courtney_home
- binary_sensor.mom_home
- binary_sensor.morgan_home
- binary_sensor.wendy_home
- binary_sensor.jasmine_home
- binary_sensor.brandon_home
- binary_sensor.andy_home
- binary_sensor.nicole_home
from: 'off'
to: 'on'
for: '00:01:45'
condition:
condition: time
# At least one of the following is required.
after: '10:00:00'
before: '00:00:01'
action:
- wait_template: "{{ is_state('script.say_greeting', 'off') }}"
- service: script.say_greeting
data_template:
entity_id: "media_player.livingroom"
person: >
{{ trigger.to_state.name }}
{%- for s in states.binary_sensor
|rejectattr('entity_id','eq',trigger.entity_id)
|selectattr('state','eq','on')
if '_home' in s.entity_id and
(now() - s.last_changed).total_seconds() < 105 -%}
{{ (' and ' if loop.last else ', ') ~ s.name }}
{%- endfor %}
message: >
{{ ["Hey there PERSON Welcome Home, during your stay, don't be a azzhole!",
"Sometimes you feel like a nut, Sometimes you don't, Sometimes you feel like PERSON, l o l Welcome Back",
"Hello PERSON, damn, I wonder, how many peopl, we can fit in this, tiny house?",
"Welcome back PERSON, Do you know what a gay cow eats? ,. ., . ,. ., ., ., ., ., Heyaaaaaaaaaaaaaaa , ., ., ., ., hahaha",
"Welcome home PERSON, Did you hear about the crook who stole a calendar? He got twelve months.",
"Welcome home PERSON, I asked God for a bike, but I know God doesn’t work that way. So I stole a bike and asked for forgiveness.",
"Welcome home PERSON, I want to die peacefully in my sleep, like my grandfather.. Not screaming and yelling like the passengers in his car",
"Welcome home PERSON, Sex is not the answer. Sex is the question. Yes, is the answer.",
"Welcome home PERSON, The last thing I want to do is hurt you. But it’s still on the list",
"Welcome home PERSON, We live in a society where pizza gets to your house before the police",
"Welcome home PERSON, Light travels faster than sound. This is why some people appear bright until you hear them speak",
"Welcome home PERSON, If I agreed with you we’d both be wrong",
"Welcome home PERSON, We never really grow up, we only learn how to act in public",
"Welcome home PERSON, Having sex is like playing bridge. If you don’t have a good partner, you’d better have a good hand",
"Welcome home PERSON, War does not determine who is right , only who is left",
"Welcome home PERSON, Knowledge is knowing a tomato is a fruit, Wisdom is not putting it in a fruit salad",
"Welcome home PERSON, Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason",
"Welcome home PERSON, Going to church doesn’t make you a Christian any more than standing in a garage makes you a car",
"Welcome home PERSON, The early bird might get the worm, but the second mouse gets the cheese",
"Welcome home PERSON, Children, You spend the first 2 years of their life teaching them to walk and talk. Then you spend the next 16 years telling them to sit down and shut-up",
"Welcome home PERSON, My mother never saw the irony in calling me a son-of-a-bitch",
"Welcome home PERSON, Evening news is where they begin with, Good evening, and then proceed to tell you why it isnt.",
"Welcome home PERSON, If sex is a pain in the ass, then you’re doing it wrong",
"Welcome home PERSON, If you think nobody cares if you’re alive, try missing a couple of payments",
"Welcome home PERSON, Better to remain silent and be thought a fool, than to speak and remove all doubt",
"Welcome home PERSON, If God is watching us, the least we can do is be entertaining",
"Welcome home PERSON, If 4 out of 5 people SUFFER from diarrhea, does that mean that one enjoys it?",
"Welcome home PERSON, To steal ideas from one person is plagiarism. To steal from many is research",
"Welcome home PERSON, I thought I wanted a career, turns out I just wanted paychecks",
"Welcome home PERSON, Some people are like Slinkies, not really good for anything, but you can’t help smiling when you see one tumble down the stairs",
"Welcome home PERSON, Never, under any circumstances, take a sleeping pill and a laxative on the same night",
"Welcome home PERSON, How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?",
"Welcome home PERSON, Did you know that dolphins are so smart that within a few weeks of captivity, they can train people to stand on the very edge of the pool and throw them fish?",
"Welcome home PERSON, I didn’t fight my way to the top of the food chain to be a vegetarian",
"Welcome home PERSON, A bank is a place that will lend you money, if you can prove that you do not need it",
"Welcome home PERSON, A computer once beat me at chess, but it was no match for me at kick boxing",
"Welcome home PERSON, Why does someone believe you when you say there are four billion stars, but check when you say the paint is wet?",
"Welcome home PERSON, Women will never be equal to men until they can walk down the street with a bald head and a beer gut, and still think they are sexy",
"Welcome home PERSON, Whenever I fill out an application, in the part that says, If an emergency, notify, I put doctor, Whats my mother going to do?",
"Welcome home PERSON, A clear conscience is usually the sign of a bad memory",
"Welcome home PERSON, The shinbone is a device for finding furniture in a dark room",
"Welcome home PERSON, I didn’t say it was your fault, I said I was blaming you",
"Welcome home PERSON, God must love stupid people. He made SO many, do you hear what i am laying down PERSON",
"Welcome home PERSON, The voices in my head may not be real, but they have some good ideas",
"Welcome home PERSON, Laugh at your problems, everybody else does",
"Welcome home PERSON, Artificial intelligence is no match for natural stupidity",
"Welcome home PERSON, Crowded elevators smell different to midgets",
"Welcome home PERSON, The sole purpose of a childs middle name, is so he can tell when hes really in trouble",
"Welcome home PERSON, Always borrow money from a pessimist. He won’t expect it back",
"Welcome home PERSON, He who smiles in a crisis ...... has found someone to blame",
"Welcome home PERSON, You do not need a parachute to skydive ...... You only need a parachute to skydive twice",
"Welcome home PERSON, It’s not the fall that kills you ...... it’s the sudden stop at the end",
"Welcome home PERSON, Some people say, If you can’t beat them, join them. I say, If you can’t beat them, beat them, because they will be expecting you to join them, so you will have the element of surprise",
"Welcome home PERSON, Why do Americans choose from just two people to run for president .... and 50 for Miss America?",
"Welcome home PERSON, My opinions may have changed .... but not the fact that .... I am always right says Wendy",
"Welcome home PERSON, We have enough gun control .... What we need is idiot control .... cough .... cough .... trump",
"Welcome home PERSON, Some cause happiness wherever they go ... ... Others whenever they go",
"Welcome home PERSON, My psychiatrist told me I was crazy .... and I said I want a second opinion .... He said okay .... you’re ugly too",
"Welcome home PERSON, Worrying works .... 90% of the things I worry about .... never happen .... says Wendy .... all day everyday",
"Welcome home PERSON, I always take life with a grain of salt .... plus a slice of lemon .... and a shot of tequila",
"Welcome home PERSON, Just remember .... if the world didn’t suck .... we’d all fall off",
"Welcome home PERSON, I used to be indecisive .......... Now I’m not sure",
"Welcome home PERSON, Jesus loves you .... but everyone else ..... thinks you’re an asshole",
"Welcome home PERSON, Did you know that, Squirrels are nature’s speed bumps?",
"Welcome home PERSON, Two antennas met on a roof ..... fell in love and got married ...... The ceremony wasn’t much ..... but the reception was excellent."
"Welcome home PERSON, Being in a nudist colony .... probably takes all the fun out of Halloween",
"Welcome home PERSON, Married men live longer than single men ...... but they’re a lot more willing to die",
"Welcome home PERSON, If you go to sleep with a itching azz ...... you will wake up with a stinking finger",
"Welcome home PERSON, We are all time travelers moving at the speed of exactly 60 minutes per hour",
"Welcome home PERSON, I bet you, I could stop gambling",
"Welcome home PERSON, Should crematoriums give discounts .... for burn victims",
"Welcome home PERSON, Everyone has the right to be stupid, but you are abusing the privilege",
"Welcome home PERSON, If the number two pencil is the most popular ..... why is it still number two",
"Welcome home PERSON, I was thinking about how people seem to read the Bible a whole lot more as they get older. Then it dawned on me, they were cramming for their finals",
"Welcome home PERSON, Constipated people .... don’t give a crap",
"Welcome home PERSON, If a turtle doesn’t have a shell, is he homeless or naked",
"Welcome home PERSON, I’m in shape...... Round is a shape isn’t it",
"Welcome home PERSON, Just about the time when you think you can make ends meet, somebody moves the ends",
"Welcome home PERSON, If Wal-Mart is lowering prices every day, why isn’t anything in the store is free yet",
"Welcome home PERSON, What has four legs and an arm? A happy pit bull",
"Welcome home PERSON, 1 in 5 people in the world are Chinese. There are 5 people in my family, so it must be one of them. It’s either my mom, or my, dad, Or my older brother Cameron, Or my younger brother Ho-Cha-Chu, But I think it’s Cameron",
"Welcome, to the, Hotel, California, PERSON",
"Welcome home PERSON, Call me Buffy ... because that's what I slay like",
"Welcome home PERSON, Gucci Gang, Gucci Gang, Gucci Gang",
"Welcome home PERSON, Employee of the month is a good example of how somebody can be both a winner and a loser at the same time",
"Welcome home PERSON, I don’t have a girlfriend, but I know a girl that would get really mad if she heard me say that",
"Welcome home PERSON, My drug test came back negative. My dealer sure has some explaining to do",
"Welcome home PERSON, I have 3 kids and no money, why I can’t I have no kids and 3 money",
"Welcome home PERSON, I think it’s wrong that only one company ... makes the game Monopoly",
"Welcome home PERSON, My therapist says I have a preoccupation with vengeance ............ We’ll see about that ......... insert evil laugh ...... ha ha ha",
"Welcome home PERSON, Words of wisdom ...... The worst time to have a heart attack ... is during a game of charades",
"Welcome home PERSON, I have the world’s largest collection of seashells ...... you may have seen it ...... I keep it scattered on beaches all over",
"Welcome home PERSON, The problem isn’t that obesity runs in your family ......... The problem is no one ..... runs in your family",
"Welcome home PERSON, When you look like I do, it’s hard to get a table for one at chuckee cheese",
"Welcome home PERSON, My ex girlfriend had this really weird fetish ....... She used to like to dress up like herself ..... and act like a fucking bitch all the time",
"Welcome home PERSON, Circumcision is popular because ......... Jewish girls won’t touch anything ..... that’s not at least 15% off",
"Welcome home PERSON, I have a friend ... He keeps trying to convince me he’s a compulsive liar ...... but I don’t believe him",
"Welcome home PERSON, I have a lot of growing up to do ........... I realized that the other day inside my fort",
"Welcome home PERSON, I taught Sunday School for two years ... And I got fired ..... I abused my authority ...... I used to teach class like this ..... OK, if one more person talks, everybody is ... going to Hell",
"Welcome home PERSON, It’s not that I’m afraid to die, I just don’t want to be there when it happens"
"Welcome home PERSON, According to most studies ..... people’s number one fear is public speaking ....... Number two is death ..... Death is number two? ....... Does that sound right? ...... This means to the average person ... if you go to a funeral ... you’re better off in the casket than doing the eulogy"
] | random }}
script.yaml
say_greeting:
sequence:
service: media_player.alexa_tts
data_template:
entity_id: "{{ entity_id }}"
message: "{{ message.replace('PERSON',person) }}"
I do use this with my Alexa TTS
I think you just need to get rid of the quotes. Like this:
action:
- service: tts.google_say
entity_id: media_player.living_room_home
data_template:
message: >
{{ ["OK", "Sure", "If you insist", "Done"] | random }}
Oh I’ll give that a go.
That was someone else’s example but didn’t work.
This works fine for me, same as above;
- alias: Say good night
initial_state: true
trigger:
platform: state
entity_id: switch.table_light
to: 'off'
action:
service: tts.google_say
entity_id: media_player.speaker_1
data_template:
message: '{{ [ "Good night. " , "Good evening. " , "Sweet dreams. " , "See you
tomorrow. " , "Have a wonderful night. " , "See you in the morning. " ] |random }}'