Automation Event extracting from sensor

Hi all,

I’m trying to create an automation even that triggers when my Nest doorbell button is pressed. I’m using badnest to extract the data from Nest.

When the doorbell button is pressed, it triggers an update of entity ‘sensor.front_door_events’ with data that looks like this:

- start_time: '2020-09-05T22:08:57+00:00'
  end_time: '2020-09-05T22:10:57+00:00'
  is_important: true
  importance: 100
  in_progress: false
  types:
    - doorbell
  face_name: ''
  zone_ids: []
- start_time: '2020-09-05T22:17:40+00:00'
  end_time: '2020-09-05T22:20:08+00:00'
  is_important: true
  importance: 100
  in_progress: false
  types:
    - doorbell
  face_name: ''
  zone_ids: []
- start_time: '2020-09-05T22:26:52+00:00'
  end_time: '2020-09-05T22:28:52+00:00'
  is_important: true
  importance: 100
  in_progress: false
  types:
    - doorbell
  face_name: ''
  zone_ids: []

I’m trying to figure out how to have an automation trigger when it detects a doorbell press and then have my Alexa devices speak text (I have that portion working). I’m stuck on what the trigger would look like. Is this even possible with a running event entity like this?

Thank you ahead of time for the assistance.

It’s not clear what you mean with this.
I assume it’s an attribute of the sensor with a list?
Can you show us a screen shot of the entity in Dev Tools/states?

It appears badnest is just scraping the Nest web interface for events in the timeline for the camera. This is what the state for that sensor looks like:

You can use the state trigger for your automation.
Using it without the optional parameters will trigger on every change of the state or attribute of the sensor.

automation:
  trigger:
    platform: state
    entity_id: sensor.front_door_events
  action:
    service: ...

EDIT: Maybe cool down the automation if it triggers multiple times.

Thank you! I will give it a go.

Thanks for the cool down suggestion. This is working but I have a follow up question.

This sensor picks up doorbell presses, motion and people detection.

The doorbell press event looks like this:

  - start_time: '2020-09-06T10:22:16+00:00'
    end_time: '2020-09-06T10:24:16+00:00'
    is_important: true
    importance: 100
    in_progress: false
    types:
      - doorbell
    face_name: ''
    zone_ids: []

The motions events look like this:

  - start_time: '2020-09-06T10:23:48+00:00'
    end_time: '2020-09-06T10:24:09+00:00'
    is_important: true
    importance: 98
    in_progress: false
    types:
      - motion
      - person
    face_name: ''
    zone_ids:
      - 218283
      - 0

And the person detection looks like this:

  - start_time: '2020-09-06T10:23:48+00:00'
    end_time: '2020-09-06T10:23:53+00:00'
    is_important: true
    importance: 100
    in_progress: false
    types:
      - face
    face_name: PersonsName
    zone_ids: []

The sensor puts this all together into the one event ‘sensor.front_door_events’ and looks like this:

Is there any way you can think of just to have the automation trigger on the types: - doorbell portion?

Are these attributes persistent until the next event?

The badnest integration extracts 10 minutes worth of Nest timeline data from the time an event is detected and then displays it in sensor.front_door_events. The sensor.front_door_events does not update unless a new event is detected on the Nest timeline then it updates sensor.front_door_events again.

So if the doorbell is pressed, the first event is always of type ‘doorbell’ ?
Then maybe a condition would work.

automation:
  trigger:
    platform: state
    entity_id: sensor.front_door_events
  condition:
    condition: template
    value_template: "{{ 'doorbell' in state_attr('sensor.front_door_events', 'events')[0].types }}"
  action:
    service: ...

Thanks! I owe you a beer!