Device activity context from recorder DB?

I already have this figured out as per the below scenario but there should be a better way to do this… It doesn’t appears to be exposed by the history_stats integration either… This data is not anywhere in the recorder?

I need to know, only when something it turned off if it was turned off manually. I use that in my logic to avoid turning lights back on from a motion sensor for 5 minutes after somebody has manually turned off a wall light switch for example so that it won’t go back on while they’re walking out of the room (right after turning the light off!).

Therefore my logic relies upon this (and input helpers that keep the time when it happens manually, etc:

template:
#
# Dining Room Chandelier (for accessing these and with the last_changed value):
# {{ states('sensor.dining_room_chandelier_off_context') }}
# {{ states.sensor['sensor.dining_room_chandelier_off_context'].last_changed }}
#
  - trigger:
      - platform: state
        entity_id: light.dining_room_chandelier_matter
    sensor:
      - name: "Dining Room Chandelier Off Context"
        state: >
          {% set c_id = trigger.to_state.context.id %}
          {% set c_parent = trigger.to_state.context.parent_id %}
          {% set c_user = trigger.to_state.context.user_id %}
          {% if states('light.dining_room_chandelier_matter') == 'on' %}
            n/a
          {% elif c_id != none and c_parent == none and c_user == none %}
            physical
          {% elif c_id != none and c_parent == none and c_user != none %}
            dashboard_ui
          {% elif c_id != none and c_parent != none and c_user == none %}
            automation
          {% else %}
            unknown
          {% endif %}
        unique_id: dining_room_chandelier_off_context
#