How to configure Pie Chart to represent String States over time

I am using InfluxDB on Ubuntu to store data captured from home automation devices, with Grafana v9.4.3 to visualize. I have a functioning State Timeline which shows the operating state of my thermostat (possible states are: idle/heating/cooling).
StateTimeline

I would like to add a Pie Chart which reflects the percentage of time for each state, but I am a bit flummoxed as to the proper query/configuration to get it working correctly.
PieChart

Anyone have some advice / good example to point me in the right direction?

I think you will need to use the elapsed or event.duration functions and format your query like the one shown in this thread.