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 }}"