In my case, Thermostat status is saved just as everything else. I don't have a custom "Thermostat" table.
The state of the thermostat (Off, Heating etc.) is a device value, provided by the thermostat API. Only changes are written to the table. So if there are 5 rows with value 3 (which means "Heating") in the table where I store all my historical data on a specific day, I know the thermostat switched to status "Heating" 5 times that day.
Total on time is a minute counter provided by the thermostat API. I store this counter value every hour; the starting value as well as ending value for that period (hour in this case). From there it's simple; if the row for 16:00 starts with 250 and ends with 300, it must have been on for 50 minutes. Sum that for all rows of a specific day and you've got what you want: on time per day.