Automation on state changed event

I’m using the abandoned gtask custom component and would like to run a automation when a task is marked as done.

I understand that I should use state changed event but I’m not sure how to find the right task.

Maybe a loop?

The event is looking like this.

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.gtasks_dagpass",
        "old_state": {
            "entity_id": "sensor.gtasks_dagpass",
            "state": "3",
            "attributes": {
                "attribution": "Data from this is provided by gtasks.",
                "tasks": [
                    {
                        "task_title": "Task 1",
                        "due_date": "2020-05-21"
                    },
                    {
                        "task_title": "Task 2",
                        "due_date": "2020-05-21"
                    },
                    {
                        "task_title": "Task 3",
                        "due_date": "2020-05-21"
                    }
                ],
                "unit_of_measurement": "Task(s)",
                "friendly_name": "gtasks_Dagpass",
                "icon": "mdi:check-bold"
            },
            "last_changed": "2020-05-21T20:19:18.759482+00:00",
            "last_updated": "2020-05-21T20:19:49.765550+00:00",
            "context": {
                "id": "2ab98943ff1947b692811904d227c0f4",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.gtasks_dagpass",
            "state": "2",
            "attributes": {
                "attribution": "Data from this is provided by gtasks.",
                "tasks": [
                    {
                        "task_title": "Task 1",
                        "due_date": "2020-05-21"
                    },
                    {
                        "task_title": "Task 3",
                        "due_date": "2020-05-21"
                    }
                ],
                "unit_of_measurement": "Task(s)",
                "friendly_name": "gtasks_Dagpass",
                "icon": "mdi:check-bold"
            },
            "last_changed": "2020-05-21T20:21:13.866009+00:00",
            "last_updated": "2020-05-21T20:21:13.866009+00:00",
            "context": {
                "id": "6488df8e04af4fde97b96ed3dd0b93e6",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-05-21T20:21:13.866204+00:00",
    "context": {
        "id": "6488df8e04af4fde97b96ed3dd0b93e6",
        "parent_id": null,
        "user_id": null
    }
}
1 Like