changed download behavior to cache data in month chunks, changed graphs
Signed-off-by: Ben Varick <ben@dendroalsia.net>
91
ecobee.R
@ -6,22 +6,10 @@ library(jsonlite)
|
||||
library(plotly)
|
||||
library(scales)
|
||||
library(readODS)
|
||||
library(ggrepel)
|
||||
|
||||
setwd("~/Documents/dataProjects/ecobee")
|
||||
|
||||
pause = function()
|
||||
{
|
||||
if (interactive())
|
||||
{
|
||||
invisible(readline(prompt = "Press <Enter> to continue..."))
|
||||
}
|
||||
else
|
||||
{
|
||||
cat("Press <Enter> to continue...")
|
||||
invisible(readLines(file("stdin"), 1))
|
||||
}
|
||||
}
|
||||
|
||||
#make a file called 'apiKey' in your working directory that has your api key for your ecobee
|
||||
if(file.exists('authTokens.Rda')) {
|
||||
#if the authToken file already exists, then refresh it
|
||||
@ -57,7 +45,7 @@ if(file.exists('authTokens.Rda')) {
|
||||
|
||||
# load data ----
|
||||
|
||||
startdate <- ymd('2021-11-13')
|
||||
startdate <- ymd('2021-11-01')
|
||||
|
||||
enddate <- Sys.Date()
|
||||
columns <- c('zoneClimate',
|
||||
@ -73,14 +61,18 @@ columns <- c('zoneClimate',
|
||||
'zoneHumidity',
|
||||
'zoneHvacMode')
|
||||
|
||||
months <- data.frame(start = seq(floor_date(startdate, unit = "months"),
|
||||
floor_date(enddate, unit = "months"),
|
||||
length.out = interval(floor_date(startdate, unit = "months"), enddate) %/% months(1) + 1))
|
||||
months <- data.frame(start = seq(startdate, enddate, by = "month"))
|
||||
months <- months %>%
|
||||
mutate(end = start + months(1) - 1)
|
||||
|
||||
ecobee_new <- list(NULL)
|
||||
ecobee <- list(NULL)
|
||||
for(i in 1:nrow(months)){
|
||||
if(file.exists(paste0('data/',months$start[i], '.Rda')) && Sys.Date() > months$end[i]){
|
||||
|
||||
message(paste("Loading", months$start[[i]], "to", months$end[[i]]))
|
||||
|
||||
load(file=paste0('data/',months$start[i], '.Rda'))
|
||||
} else{
|
||||
message(paste("Downloading", months$start[[i]], "to", months$end[[i]]))
|
||||
|
||||
url <- paste0('https://api.ecobee.com/1/runtimeReport?format=json&body={"startDate":',
|
||||
@ -99,7 +91,7 @@ for(i in 1:nrow(months)){
|
||||
|
||||
# parse data ----
|
||||
|
||||
ecobee_new[[i]] <- tibble(ecobee_month[["reportList"]][[1]][["rowList"]]) %>%
|
||||
ecobee_month <- tibble(ecobee_month[["reportList"]][[1]][["rowList"]]) %>%
|
||||
separate(sep = ",",
|
||||
col = 1,
|
||||
into = c('date', 'time', columns),
|
||||
@ -108,10 +100,15 @@ for(i in 1:nrow(months)){
|
||||
"dateTime" = ymd_hms(paste(date, time)),
|
||||
outdoortemp_bin = round(outdoorTemp)) %>%
|
||||
filter(ymd(date) <= Sys.Date())
|
||||
}
|
||||
ecobee <- bind_rows(ecobee_new)
|
||||
|
||||
save(ecobee, file = 'data/ecobee.Rda')
|
||||
if(Sys.Date() > months$end[i]){
|
||||
save(ecobee_month,
|
||||
file = paste0('data/',months$start[i], '.Rda'))
|
||||
}
|
||||
}
|
||||
ecobee[[i]] <- ecobee_month
|
||||
}
|
||||
ecobee <- bind_rows(ecobee)
|
||||
|
||||
daterange <- data.frame(start = min(ecobee$date), end = max(ecobee$date))
|
||||
|
||||
@ -167,6 +164,12 @@ ggplot() +
|
||||
theme(legend.title = element_blank()) +
|
||||
labs(x = 'Date',
|
||||
y = 'Temperature (\u00B0F)')
|
||||
ggsave(filename = "temp_time_all.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
||||
ggplot() +
|
||||
geom_line(data = ecobee %>% filter(date > Sys.Date() - 3) %>% pivot_longer(cols = c(zoneAveTemp, outdoorTemp, zoneHeatTemp, zoneCoolTemp), names_to = "temp_type", values_to = "temp"),
|
||||
@ -184,6 +187,12 @@ ggplot() +
|
||||
theme(legend.title = element_blank()) +
|
||||
labs(x = 'Date',
|
||||
y = 'Temperature (\u00B0F)')
|
||||
ggsave(filename = "temp_time_last_3_days.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
||||
ggplot(data = ecobee %>%
|
||||
filter(date != "2021-11-13",
|
||||
@ -204,6 +213,12 @@ ggplot(data = ecobee %>%
|
||||
scale_y_continuous(labels = label_percent(), expand = expansion(mult = c(0,0))) +
|
||||
labs(x = 'Outdoor Temperature (\u00B0F)',
|
||||
y = 'Percent of the time the equipment runs')
|
||||
ggsave(filename = "outdoorTemp_equipmentRun_zone.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
||||
ggplot() +
|
||||
geom_col(data = ecobee %>% pivot_longer(cols = c(compHeat1, auxHeat1, compCool1), names_to = "equipment", values_to = "active_sec"),
|
||||
@ -219,6 +234,12 @@ ggplot() +
|
||||
y = 'Time equipment runs (hours)') +
|
||||
scale_y_continuous(sec.axis = sec_axis(trans = ~ .x*5,
|
||||
name = "Temperature (\u00B0F)"))
|
||||
ggsave(filename = "dateDay_timeRunning.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
||||
ggplot() +
|
||||
geom_col(data = ecobee %>% pivot_longer(cols = c(compHeat1, auxHeat1, compCool1), names_to = "equipment", values_to = "active_sec"),
|
||||
@ -234,6 +255,12 @@ ggplot() +
|
||||
y = 'Time equipment runs (hours)') +
|
||||
scale_y_continuous(sec.axis = sec_axis(trans = ~ .x*5/7,
|
||||
name = "Temperature (\u00B0F)"))
|
||||
ggsave(filename = "dateWeek_timeRunning.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
||||
ggplot(data = ecobee %>%
|
||||
filter(date != "2021-11-13",
|
||||
@ -254,4 +281,24 @@ ggplot(data = ecobee %>%
|
||||
scale_color_manual(labels = equipment_types$label, values = equipment_types %>% pull(color, column)) +
|
||||
labs(x = 'Outdoor Temperature (\u00B0F)',
|
||||
y = 'Time equipment runs (hours)')
|
||||
ggsave(filename = "outdoorTemp_equipmentRun.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
||||
ggplot(data = utility_data %>% filter(start_date>startdate)) +
|
||||
geom_point(aes(x = `Electricity (kWh)`,
|
||||
y = heat_pump_hours+heat_aux_hours+cool_pump_hours)) +
|
||||
geom_label_repel(aes(x = `Electricity (kWh)`,
|
||||
y = heat_pump_hours+heat_aux_hours+cool_pump_hours,
|
||||
label = `mid date`)) +
|
||||
scale_x_continuous(limits = c(0, NA), expand = expansion(mult = c(0,0.1))) +
|
||||
scale_y_continuous(limits = c(0, NA), expand = expansion(mult = c(0,0.1)))
|
||||
ggsave(filename = "equipmentRun_electicCost.png" ,
|
||||
path = paste(getwd(),"/figures/", sep = ""),
|
||||
device = "png",
|
||||
width = 11,
|
||||
height = 8.5,
|
||||
units = "in")
|
||||
|
BIN
figures/dateDay_timeRunning.png
Normal file
After Width: | Height: | Size: 255 KiB |
BIN
figures/dateWeek_timeRunning.png
Normal file
After Width: | Height: | Size: 247 KiB |
BIN
figures/equipmentRun_electicCost.png
Normal file
After Width: | Height: | Size: 95 KiB |
BIN
figures/outdoorTemp_equipmentRun.png
Normal file
After Width: | Height: | Size: 233 KiB |
BIN
figures/outdoorTemp_equipmentRun_zone.png
Normal file
After Width: | Height: | Size: 325 KiB |
BIN
figures/temp_time_all.png
Normal file
After Width: | Height: | Size: 359 KiB |
BIN
figures/temp_time_last_3_days.png
Normal file
After Width: | Height: | Size: 177 KiB |