def trigger(hass, config, action):
    event_type = config.get(CONF_EVENT_TYPE)
    event_data = config.get(CONF_EVENT_DATA)

    def handle_event(event):
        """Listen for events and calls the action when data matches."""
        if not event_data or all(val == event.data.get(key) for key, val
                                 in event_data.items()):
            action({
                'trigger': {
                    'platform': 'event',
                    'event': event,
                },
            })

    hass.bus.listen(event_type, handle_event)
    return True
Listen for events based on configuration.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/automation/event.py/trigger