Creating a graph of time between "last changed" for an entity

I take daily medication and want to use a graph such (preferably Plotly, mini graph card, or something built into Home Assistant) to track this better. When I take the pills, I scan an NFC tag, which updates a datetime helper with the current time.

I want each change of this entity (meaning pills were taken) to add a new column/bar on the X axis, with the Y axis showing the hours elapsed since the last time the pills were taken. The goal being to consistently take the pills every 24 hours and keep each bar the same height.

Here is a mock chart with dummy data from Excel:

Any help with getting the right YAML together for this? I’ve been struggling with it all afternoon. :hugs:

This should give you the delta:

template:
  - trigger:
      - trigger: state
        entity_id: input_datetime.pills
    sensor:
      - name: "Time between meds"
        unique_id: e35ece22-235f-42e5-8c8c-06251c4257c7
        state: "{{ now()|as_timestamp - trigger.from_state.state|as_timestamp(0) }}"
        unit_of_measurement: 's'

I don’t really understand. Can you break this down more and indicate where it should go? I don’t see how it should work.

I tried putting this in the template editor, based off the code you gave me, but it’s not valid:

{{ now()|as_timestamp - input_datetime.last_medication_scan|as_timestamp(0) }}

I think I figured it out. The part I am stuck with now is how to basically add another entry (bar) to the graph each time the state changes and the template sensor goes back to zero, while retaining the old value on the previous bar.