Setting a variable from trigger using event data

I’ve been fighting with this for a while and have tired it countless different ways but not having any success.
I am just trying to set may variable using the carcount attribute from the event data.
Any help would be appreciated.
Thanks

Here is my event:

{
    "event_type": "deepstack.image_processed",
    "data": {
        "entity_id": "image_processing.deepstack_person_detector",
        "carcount": 2
    },
    "origin": "LOCAL",
    "time_fired": "2020-09-08T16:59:14.372542+00:00",
    "context": {
        "id": "9fcfb5b3f1f411eaae920f673547a359",
        "parent_id": null,
        "user_id": null
    }
}

And here is my automation:

variable:
  cars_in_driveway:
    value: 0
    restore: true

automation:
  - alias: 'Image Processed'
    trigger:
    - platform: event
      event_type: deepstack.image_processed
    action:
      - service: variable.set_variable
        data:
          variable: cars_in_driveway
          value_template: "{{ trigger.event.data.carcount }}"

It’s a common mistake. In the automation, change:

        data:

to:

        data_template:

You’ll be pleased to know that in an upcoming version, data will behave like data_template. This will obviate the need to use data_template. However, all versions up to the current one do make a distinction between the two and will not evaluate any templates if you use data.

1 Like

Thanks!!! That worked!

1 Like