Entity State Change -- how to Log and also write to Entity view viewing?

I found code below that the author and others say will write lock events to the HA log… but looks like its not, I cant find any evidence in the log.

Also, I’d like to write these to an Entity so the dashboard can show the date/times of the last 10 actions for each Entity. Anyone know how to do that?

thx!

template:
  - trigger:
    - platform: event
      event_type: zwave_js_notification
      event_data:
        device_id: lock.front_entry_deadbolt
        label: Access Control
    sensor:
      - name: "Front Door Lock Event"
        state: "{{now() | as_local }}"
        unique_id: front_door_lock_event
        attributes:
          log: >
            {% set log = this.attributes.get('log', []) %}
            {% set new = [{
               "event": trigger.event.data.event_label | default ('unknown', true),
               "user": trigger.event.data.parameters.userId | default ('None', true),
               "time": (trigger.event.time_fired | as_local).isoformat() }] %}
            {{ (new + log)[:10] }}

If you really want to post the events to the Logbook, you can find the correct action in the docs: Logbook - Custom Entries

That is what the template sensor is doing. States are always strings and are limited to 255 characters, so the sensor is storing the data from the last 10 events it has captured in an attribute named log. You can use a Markdown Card to list the values from the attribute.

1 Like

aw, thank you. I didnt know it was creating the Entity!

I also see its only capturing states: Unknown and Unavailable.

How do I get it to capture all activities?