Automation and call_service event

Hello all,

I’m trying to implement an automation, which is listening on the call_service event. My code:

 automation:
    id: auto_1
    alias: "Test Automation"
    trigger:
      - platform: event
        event_type: call_service
        event_data:
          domain: input_text
          service: set_value
    action:
     - service: mqtt.publish
       data_template:
         topic: "test"
         payload_template: "{{ trigger }}"

This automation works, the fired event shows up in mqtt. What I get:

{‘platform’: ‘event’, ‘event’: <Event call_service[L]: service=set_value, domain=input_text, service_data=entity_id=input_text.it_wecker_montag, value=17:53, service_call_id=140382509888064-2>}

But I can’t find a way to access the deeper event data. especially the entity_id and the value in service_data.Is it somehow possible to access the data in an event object?

1 Like

OK, I’ve managed to solve it by myself by looking into core.py:

payload_template: “{{ trigger.event.as_dict().get(‘data’).get(‘service_data’).get(‘entity_id’) }}: {{ trigger.event.as_dict().get(‘data’).get(‘service_data’).get(‘value’) }}”

This sends a string with

entity_id: value

of each input_text to mqtt after changing the field.

The whole automaition (after some cosmetic changes):

automation:
   id: auto_1
   alias: "Test Automation"
   trigger:
     - platform: event
       event_type: call_service
       event_data:
         domain: input_text
         service: set_value
   action:
     - service: mqtt.publish
       data_template:
         topic: "test"
         payload_template: >
           {% set service_data = trigger.event.as_dict().get('data').get('service_data') %}
           {{ service_data.get('entity_id') }}: {{ service_data.get('value') }}
4 Likes