made 'ended 14 minutes ago' units dynamic
This commit is contained in:
parent
b2c25dbc39
commit
b525de95d3
16
.Rhistory
16
.Rhistory
@ -1,9 +1,3 @@
|
||||
View(values %>%
|
||||
filter(entity_id %in% sensors) %>%
|
||||
filter(time > time_start,
|
||||
time < time_end))
|
||||
values %>%
|
||||
filter(entity_id %in% sensors) %>%
|
||||
filter(time > time_start,
|
||||
time < time_end) %>%
|
||||
group_by(time_rounded, entity_id) %>%
|
||||
@ -444,7 +438,7 @@ token = token,
|
||||
org = org)
|
||||
update_interval <- 5
|
||||
cronjob_interval <- 60
|
||||
power_threshhold <- 5
|
||||
power_threshhold <- 10
|
||||
# ---- set variables
|
||||
entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("washing_machine_power", "dryer_power"))
|
||||
update_data <- function(){
|
||||
@ -505,7 +499,13 @@ render("laundry_status.Rmd",
|
||||
output_dir = "html",
|
||||
output_file = "index.html")
|
||||
}
|
||||
for(i in 1:(cronjob_interval/update_interval)){
|
||||
# for(i in 1:(cronjob_interval/update_interval)){
|
||||
# message(Sys.time())
|
||||
# update_data()
|
||||
# Sys.sleep(60*update_interval)
|
||||
# }
|
||||
continue <- TRUE
|
||||
while(continue){
|
||||
message(Sys.time())
|
||||
update_data()
|
||||
Sys.sleep(60*update_interval)
|
||||
|
@ -23,6 +23,26 @@ power_threshhold <- 10
|
||||
# ---- set variables
|
||||
entities <- data.frame(name = c("washing machine", "dryer"), entity_id = c("washing_machine_power", "dryer_power"))
|
||||
|
||||
# Define a function to calculate the time difference
|
||||
calculateTimeAgo <- function(eventTime) {
|
||||
current <- Sys.time() # Get the current time
|
||||
timeDiff <- as.duration(current - eventTime) # Calculate the time difference
|
||||
|
||||
# Convert the time difference to appropriate units and format the result
|
||||
if (timeDiff >= hours(24)) {
|
||||
result <- paste(round(timeDiff / dhours(24)), "days ago")
|
||||
} else if (timeDiff >= hours(1)) {
|
||||
result <- paste(round(timeDiff / dhours(1)), "hours ago")
|
||||
} else if (timeDiff >= minutes(1)) {
|
||||
result <- paste(round(timeDiff / dminutes(1)), "minutes ago")
|
||||
} else {
|
||||
result <- "Just now"
|
||||
}
|
||||
|
||||
return(result)
|
||||
}
|
||||
|
||||
# ---- update_data function
|
||||
update_data <- function(){
|
||||
|
||||
run_time <- Sys.time()
|
||||
|
@ -15,17 +15,15 @@ this site updates every `r update_interval` minutes
|
||||
|
||||
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"))`
|
||||
:
|
||||
`r ifelse(current_status$washing_machine_power=="on", round(difftime(Sys.time(), washer_last_off, unit = "mins"),0), round(difftime(Sys.time(), washer_last_on, units = "mins"),0))`
|
||||
minutes ago
|
||||
|
||||
`r ifelse(current_status$washing_machine_power=="on", calculateTimeAgo(washer_last_off), calculateTimeAgo(washer_last_on))`
|
||||
|
||||
## 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"))`
|
||||
:
|
||||
`r ifelse(current_status$dryer_power=="on", round(difftime(Sys.time(), dryer_last_off, unit = "mins"),0), round(difftime(Sys.time(), dryer_last_on, units = "mins"),0))`
|
||||
minutes ago
|
||||
`r ifelse(current_status$dryer_power=="on", calculateTimeAgo(dryer_last_off), calculateTimeAgo(dryer_last_on))`
|
||||
|
||||
|
||||
---
|
||||
```{r setup, include=FALSE}
|
||||
|
Loading…
x
Reference in New Issue
Block a user