I use a variable custom integration available in HACS (hass-variables).
variable:
last_motion:
value: 'Not set'
restore: true
attributes:
icon: mdi:map-marker
friendly_name: 'Last Motion'
then for the automation I use this:
- alias: 'AS Update Last Motion'
initial_state: 'on'
mode: parallel
trigger:
- platform: state
entity_id:
- binary_sensor.computer_room_camera_motion
- binary_sensor.deck_camera_motion
- binary_sensor.diningroom_camera_motion
- binary_sensor.front_entrance_camera_motion
- binary_sensor.garage_camera_motion
- binary_sensor.kitchen_camera_motion
- binary_sensor.livingroom_camera_motion
- binary_sensor.rear_parking_camera_motion
- binary_sensor.upper_hall_camera_motion
- binary_sensor.front_entrance_camera_motion_cam
- binary_sensor.front_porch_motion
- binary_sensor.computer_room_motion_sensor
- binary_sensor.garage_motion
- binary_sensor.kitchen_door_motion
- binary_sensor.main_hallway_motion
- binary_sensor.mbr_motion
- binary_sensor.spare_bedroom_motion
to: 'on'
action:
- service: variable.set_variable
data:
variable: last_motion
attributes:
history_1: "{{ states('variable.last_motion') }}"
history_2: "{{ state_attr('variable.last_motion','history_1') }}"
history_3: "{{ state_attr('variable.last_motion','history_2') }}"
history_4: "{{ state_attr('variable.last_motion','history_3') }}"
history_5: "{{ state_attr('variable.last_motion','history_4') }}"
history_6: "{{ state_attr('variable.last_motion','history_5') }}"
history_7: "{{ state_attr('variable.last_motion','history_6') }}"
history_8: "{{ state_attr('variable.last_motion','history_7') }}"
history_9: "{{ state_attr('variable.last_motion','history_8') }}"
history_10: "{{ state_attr('variable.last_motion','history_9') }}"
- service: variable.set_variable
data:
variable: last_motion
value: >
{{ trigger.to_state.attributes.friendly_name }} : {{ as_timestamp(trigger.to_state.last_changed)| timestamp_custom('%x, %X') }}
and this is the lovelace card to display it:
- type: entities
title: Motion Sensor History
show_header_toggle: false
state_color: true
entities:
- variable.last_motion
- type: custom:entity-attributes-card
heading_name: Name
heading_state: State
entity: variable.last_motion
filter:
include:
- variable.last_motion.history_1
- variable.last_motion.history_2
- variable.last_motion.history_3
- variable.last_motion.history_4
- variable.last_motion.history_5
- variable.last_motion.history_6
- variable.last_motion.history_7
- variable.last_motion.history_8
- variable.last_motion.history_9
- variable.last_motion.history_10