added door status
This commit is contained in:
parent
1a44fc8ee4
commit
56a2d09dc6
@ -19,7 +19,10 @@ home_assistant <- InfluxDBClient$new(url = "https://influxdb.dendroalsia.net",
|
|||||||
org = org)
|
org = org)
|
||||||
update_interval <- 5
|
update_interval <- 5
|
||||||
cronjob_interval <- 60
|
cronjob_interval <- 60
|
||||||
power_threshhold <- 10
|
power_threshold_on <- 10
|
||||||
|
power_threshold_wash_door <- 4
|
||||||
|
power_threshold_dry_door <- 1.5
|
||||||
|
|
||||||
# ---- set variables
|
# ---- set variables
|
||||||
entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("washing_machine_power", "dryer_power"))
|
entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("washing_machine_power", "dryer_power"))
|
||||||
|
|
||||||
@ -57,7 +60,9 @@ update_data <- function(){
|
|||||||
values <- values %>%
|
values <- values %>%
|
||||||
mutate(
|
mutate(
|
||||||
time = as.POSIXct(time, tz = "America/Chicago"),
|
time = as.POSIXct(time, tz = "America/Chicago"),
|
||||||
status = ifelse(value > power_threshhold, "on", "off"))
|
status = ifelse(value > power_threshold_on, "on", "off")) %>%
|
||||||
|
mutate(door_threshold = ifelse(entity_id == "washing_machine_power", power_threshold_wash_door, power_threshold_dry_door)) %>%
|
||||||
|
mutate(door = ifelse(value < door_threshold, "open", "closed"))
|
||||||
|
|
||||||
values_by_entity <- as.list(NULL)
|
values_by_entity <- as.list(NULL)
|
||||||
for(entity in entities$entity_id) {
|
for(entity in entities$entity_id) {
|
||||||
@ -67,15 +72,20 @@ update_data <- function(){
|
|||||||
}
|
}
|
||||||
values <- bind_rows(values_by_entity)
|
values <- bind_rows(values_by_entity)
|
||||||
|
|
||||||
washer_last_on <- values %>% filter(entity_id == entities$entity_id[1], value > power_threshhold) %>% tail(1) %>% pull(end_time)
|
last_change <- values %>%
|
||||||
washer_last_off <- values %>% filter(entity_id == entities$entity_id[1], value < power_threshhold) %>% tail(1) %>% pull(end_time)
|
group_by(entity_id, status) %>%
|
||||||
|
slice_max(n = 1, order_by = time) %>%
|
||||||
|
pivot_wider(id_cols = domain, names_from = c(entity_id, status), values_from = time)
|
||||||
|
|
||||||
dryer_last_on <- values %>% filter(entity_id == entities$entity_id[2], value > power_threshhold) %>% tail(1) %>% pull(end_time)
|
status_door <- values %>%
|
||||||
dryer_last_off <- values %>% filter(entity_id == entities$entity_id[2], value < power_threshhold) %>% tail(1) %>% pull(end_time)
|
group_by(entity_id) %>%
|
||||||
|
slice_max(n = 1, order_by = time) %>%
|
||||||
|
select(entity_id, door) %>%
|
||||||
|
pivot_wider(names_from = entity_id, values_from = door)
|
||||||
|
|
||||||
current_status <- as.list(NULL)
|
current_status <- as.list(NULL)
|
||||||
for (entity in entities$entity_id){
|
for (entity in entities$entity_id){
|
||||||
current_status[[entity]] <- ifelse(values %>% filter(entity_id %in% entity) %>% tail(1) %>% pull(value) > power_threshhold, "on", "off")
|
current_status[[entity]] <- ifelse(values %>% filter(entity_id %in% entity) %>% tail(1) %>% pull(value) > power_threshold_on, "on", "off")
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---- make plots
|
# ---- make plots
|
||||||
|
@ -10,19 +10,27 @@ updated: `r format(Sys.time(), format = "%A %I:%M %p", tz = "America/Chicago")`
|
|||||||
|
|
||||||
this site updates every `r update_interval` minutes
|
this site updates every `r update_interval` minutes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## The washing machine is currently: `r current_status[["washing_machine_power"]]`
|
## The washing machine is currently: `r current_status[["washing_machine_power"]]`
|
||||||
|
|
||||||
|
|
||||||
The washer `r ifelse(current_status$washing_machine_power=="on", "started", "ended")` its most recent cycle at `r ifelse(current_status$washing_machine_power=="on", strftime(washer_last_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(washer_last_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
The washer `r ifelse(current_status$washing_machine_power=="on", "started", "ended")` its most recent cycle at `r ifelse(current_status$washing_machine_power=="on", strftime(last_change$washing_machine_power_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(last_change$washing_machine_power_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
||||||
:
|
:
|
||||||
`r ifelse(current_status$washing_machine_power=="on", calculateTimeAgo(washer_last_off), calculateTimeAgo(washer_last_on))`
|
`r ifelse(current_status$washing_machine_power=="on", calculateTimeAgo(last_change$washing_machine_power_off), calculateTimeAgo(last_change$washing_machine_power_on))`
|
||||||
|
|
||||||
|
`r ifelse(current_status$washing_machine_power=="off", paste0("The washing machine door is ", status_door$washing_machine_power), "")`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## The dryer is currently: `r current_status[["dryer_power"]]`
|
## The dryer is currently: `r current_status[["dryer_power"]]`
|
||||||
|
|
||||||
|
|
||||||
The dryer `r ifelse(current_status$dryer_power=="on", "started", "ended")` its most recent cycle at `r ifelse(current_status$dryer_power=="on", strftime(dryer_last_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(dryer_last_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
The dryer `r ifelse(current_status$dryer_power=="on", "started", "ended")` its most recent cycle at `r ifelse(current_status$dryer_power=="on", strftime(last_change$dryer_power_off, format = "%A %I:%M %p", tz = "America/Chicago"), strftime(last_change$dryer_power_on, format = "%A %I:%M %p", tz = "America/Chicago"))`
|
||||||
:
|
:
|
||||||
`r ifelse(current_status$dryer_power=="on", calculateTimeAgo(dryer_last_off), calculateTimeAgo(dryer_last_on))`
|
`r ifelse(current_status$dryer_power=="on", calculateTimeAgo(last_change$dryer_power_off), calculateTimeAgo(last_change$dryer_power_on))`
|
||||||
|
|
||||||
|
`r ifelse(current_status$dryer_power=="off", paste0("The washing machine door is ", status_door$dryer_power), "")`
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user