Long term statistic for when a device is on/off

When I look at the history of my thermostates (climate), I can see when the heating was on/off (-> I assume this is from the climate entity’s attribute hvac_mode: heat vs. off).

Question 1: Is it possible to have the on/off state as a long-term stat?

I’d expect it to assume the value that it had for the longest in the given time frame, e.g., if the heating was on for 3 minutes in a 5 minute time frame, the long-term stat for this 5 minute period would show on. This would also work for non-binary states like presets.

Question 2: How can I enable this on/off history for other devices/domains?

My air purifier (fan) has an on/off state (in this case not an attribute). When I look at the air quality graph (pm2.5), I would like to see when the air purifier was turned on/off just like I’m seeing it for the climate device. Is this possible?