Scene Name from Call_service Event

Hi all,

In my home I work a lot with different scenes to manage my lights.
I want to be able to create a custom sensor that shows the last activated scene either manual activated or by automation.

Gebeurtenis 0 afgevuurd 18:15:
    "event_type": "call_service",
    "data": {
        "domain": "scene",
        "service": "turn_on",
        "service_data": {
            "entity_id": "scene.dark"
    "origin": "LOCAL",
    "time_fired": "2021-01-20T17:15:13.719248+00:00",
    "context": {
        "id": "33a8c5338c37b18e45f2c47e4448d5f3",
        "parent_id": null,
        "user_id": "7603683a9d474002ba633c4a55f1fcc8"

Basically I want the data.service_data.entity_id component of this response and then split scene.dark at the β€œ.” character and change the state of a sensor to the last part (dark). But I can’t figure out how to get the data I want.

Maybe you could help me with this.

I have figured it out with the following code:

- alias: Scene Selected
    - platform: event
      event_type: call_service
        domain: scene
        service: turn_on
    - service: python_script.set_state
        entity_id: sensor.last_active_scene
        state: "{% set scn = %}{{scn.split('.')[1]}}"
1 Like