Event Trigger Json help

Using the IOS component I have the following event that triggers trigger.

By using the {{trigger.event.data}} variable I get the following information

{'sourceDeviceName': 'Ryan iPhone', 'actionName': 'ALLINONETRUE', 'sourceDevicePermanentID': 'NULL', 'actiondata': {'mycustomdata': 'foobar', 'entityid': 'light.test'}}

I am trying to extract the values such as light.test or foobar what would be the correct variable?

Hi @rabittn, use the Dev Tools/Templates and play with it.

{% set my_test_data = {'sourceDeviceName': 'Ryan iPhone', 'actionName': 'ALLINONETRUE', 'sourceDevicePermanentID': 'NULL', 'actiondata': {'mycustomdata': 'foobar', 'entityid': 'light.test'}} %}
{{ my_test_data.actiondata.entityid }}

returns light.test

Never thought of using the template tool like that thank you. However it does not seem to work. The error I get when setting the template to

{{ trigger.event.data.actiondata.entityid }}

is

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 74, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 70, in _data_template_creator
    for key, item in value.items()}
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 70, in <dictcomp>
    for key, item in value.items()}
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/service.py", line 72, in _data_template_creator
    return value.async_render(variables)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/template.py", line 104, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'dict object' has no attribute 'actiondata

what does:

{{ trigger.event.data['actiondata']['entityid'] }}

same error. I appreciate your help BTW

homeassistant.exceptions.TemplateError: UndefinedError: 'dict object' has no attribute 'actiondata'

Running the core on debug this is the event info I see on the Bus.

2017-09-27 08:53:15 INFO (MainThread) [homeassistant.core] Bus:Handling <Event ios.notification_action_fired[R]: actionName=ALL_IN_ONE_TRUE, action_data=my_custom_data=foo_bar, entity_id=light.test, sourceDeviceName=Ryan iPhone, sourceDevicePermanentID=REMOVED>
2017-09-27 08:53:15 DEBUG (MainThread) [homeassistant.components.api] STREAM 140097234660304 FORWARDING <Event ios.notification_action_fired[R]: actionName=ALL_IN_ONE_TRUE, action_data=my_custom_data=foo_bar, entity_id=light.test, sourceDeviceName=Ryan iPhone, sourceDevicePermanentID=REMOVED>

so your answer plus an underscore gave me light.test

Thank you.

{{ trigger.event.data['actiondata']['entity_id'] }}

1 Like