diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f939db --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +data/* + +figures/* + diff --git a/laundry_status.R b/laundry_status.R new file mode 100644 index 0000000..9192c6a --- /dev/null +++ b/laundry_status.R @@ -0,0 +1,57 @@ +#setup ---- +library(tidyverse) +library(influxdbclient) +library(rmarkdown) + +setwd("~/Documents/dataProjects/laundry_status") + +# parameters needed to make connection to Database +token <- substr(read_file("data/api_key"), 1, 88) +org = "home_assistant" +bucket = "home_assistant" +## make connection to the influxDB bucket +home_assistant <- InfluxDBClient$new(url = "https://influxdb.dendroalsia.net", + token = token, + org = org) + + +values <- home_assistant$query('from(bucket: "home_assistant") |> range(start: -7d) |> filter(fn: (r) => r["entity_id"] == "lamp_b_power" or r["entity_id"] == "lamp_a_power") |> filter(fn: (r) => r["_field"] == "value") |> filter(fn: (r) => r["_measurement"] == "W")') +values <- bind_rows(values) +values <- values %>% + rename(value = "_value") +values <- values %>% + mutate(status = ifelse(value > 1, "on", "off"), + end_time = c(values$time + minutes(1))) + +# ---- set variables +entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("lamp_a_power", "lamp_b_power")) + +# ---- generate html +current_status <- as.list(NULL) +for (entity in entities$entity_id){ + current_status[[entity]] <- ifelse(values %>% filter(entity_id %in% entity) %>% tail(1) %>% pull(value) > 5, "on", "off") +} + +plot_1week <- ggplot(data = values) + + geom_rect(aes(xmin = end_time, + xmax = time, + ymin = ifelse(entity_id == "lamp_a_power", 0, 2) + 0.5, + ymax = ifelse(entity_id == "lamp_a_power", 0, 2) + 1.5, + fill = status)) + + scale_y_continuous() + + scale_x_datetime(date_breaks = "24 hours", date_labels = '%A', date_minor_breaks = "6 hours") + + theme(axis.text.x = element_text(angle = 30, vjust = 0.5)) + + labs(title = "Last week") + +plot_1day <- ggplot(data = values %>% filter(time >= max(values$time) - hours(24))) + + geom_rect(aes(xmin = end_time, + xmax = time, + ymin = ifelse(entity_id == "lamp_a_power", 0, 2) + 0.5, + ymax = ifelse(entity_id == "lamp_a_power", 0, 2) + 1.5, + fill = status)) + + scale_y_continuous() + + scale_x_datetime(date_breaks = "4 hours", date_labels = '%I:%M %p', date_minor_breaks = "6 hours") + + theme(axis.text.x = element_text(angle = 30, vjust = 0.5)) + + labs(title = "Last 24 hours") + +render("laundry_status.Rmd") \ No newline at end of file diff --git a/laundry_status.Rmd b/laundry_status.Rmd new file mode 100644 index 0000000..a4a8432 --- /dev/null +++ b/laundry_status.Rmd @@ -0,0 +1,26 @@ +--- +title: "Laundry Status" +output: html_document +--- + +updated: `r format(Sys.time(), format = "%A %I:%M %p")` + +## The washing machine is currently: `r current_status[["lamp_a_power"]]` + +## The dryer is currently: `r current_status[["lamp_b_power"]]` + +-------- +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` +This site tracks the washing machine and dryer of our building. It is just a suggestion of when the machines might be free, not a guarantee. + +```{r plot_1day, echo=FALSE} +plot(plot_1day) +``` + +```{r plot_1week, echo=FALSE} +plot(plot_1week) +``` + +If you have any issues or questions, please email `admin@dendroalsia.net` diff --git a/laundry_status.html b/laundry_status.html new file mode 100644 index 0000000..31c13c6 --- /dev/null +++ b/laundry_status.html @@ -0,0 +1,418 @@ + + + + + + + + + + + + + +Laundry Status + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +

updated: Monday 04:16 PM

+
+

The washing machine is currently: off

+
+
+

The dryer is currently: off

+
+

This site tracks the washing machine and dryer of our building. It is +just a suggestion of when the machines might be free, not a +guarantee.

+

+

+

If you have any issues or questions, please email +admin@dendroalsia.net

+
+ + + + +
+ + + + + + + + + + + + + + +