diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 4c278cbf5f0..79c6dcc2312 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -189,7 +189,7 @@ async def async_setup(hass, config): async def trigger_service_handler(entity, service_call): """Handle forced automation trigger, e.g. from frontend.""" await entity.async_trigger( - service_call.data[ATTR_VARIABLES], + {**service_call.data[ATTR_VARIABLES], "trigger": {"platform": None}}, skip_condition=service_call.data[CONF_SKIP_CONDITION], context=service_call.context, ) diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 91531481a99..71727258fcc 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -1355,3 +1355,33 @@ async def test_blueprint_automation(hass, calls): assert automation.entities_in_automation(hass, "automation.automation_0") == [ "light.kitchen" ] + + +async def test_trigger_service(hass, calls): + """Test the automation trigger service.""" + assert await async_setup_component( + hass, + automation.DOMAIN, + { + automation.DOMAIN: { + "alias": "hello", + "trigger": {"platform": "event", "event_type": "test_event"}, + "action": { + "service": "test.automation", + "data_template": {"trigger": "{{ trigger }}"}, + }, + } + }, + ) + context = Context() + await hass.services.async_call( + "automation", + "trigger", + {"entity_id": "automation.hello"}, + blocking=True, + context=context, + ) + + assert len(calls) == 1 + assert calls[0].data.get("trigger") == {"platform": None} + assert calls[0].context.parent_id is context.id