Page 1 of 1

Thermostat status

PostPosted: Sun Dec 12, 2010 8:37 pm
by erisan500
How are you guys saving the thermostat status into the database? Right now I'm saving on/off change with respective date/time (thus 2 records, 1 for on, 1 for off).
Is there a better way to do this? I'm having some trouble graphing the on/off state over time.
Also, how do you calculate total on time by day if you have 2 records per state change?

Thanks in advance

Re: Thermostat status

PostPosted: Sun Dec 12, 2010 9:37 pm
by Digit
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.