I’m having a lot of circuit-breaker trips. I’ve spent a month trying to track it down, but it keeps happening irrespective of which device I disconnect. I’ve asked an electrician to come and do fault-finding.
I want to help them by describing when the outages occur. Maybe I can even describe the power usage, humidity and temperature around those events to provide extra context.
I could do this from my file system cache of the CurrentCost readings, but I feel like playing with EmonCMS.
I’m looking for when the readings are missing or are zero. I’ve tested this script with some recent outages, but now I’m running it from a long time ago to see when things started misbehaving.
Unfortunately I’m only getting about 10 requests a second from my local EmonCMS install which is on a very beefy server, but running in Docker containers. I do know what I’m doing, I have been using Docker in production websites for over five years.
Luckily it’s fine, I’m only doing something like a million requests which will be done in a day. I can wait.
I just wondered if others are using different approaches, perhaps using data.json
on the feed
API endpoint.
Are you finding the performance benefit is worth the extra complexity of doing the analysis on the client side?
Anyway, here’s a the script so you can have a giggle at my lazy implementation.
import datetime
import tqdm
from typing import Generator
from .emoncms import EmonCMS # a thing that fetches a single reading
def generate_moment() -> Generator[datetime.datetime, None, None]:
''' Generate all the moments we're interested in'''
start = datetime.datetime.strptime("2021-04-20T00:00:00", "%Y-%m-%dT%H:%M:%S")
end = datetime.datetime.utcnow()
moment = start
while moment < end:
yield moment
moment = moment + datetime.timedelta(0, 30)
def is_down_at_moment(moment) -> bool:
''' Does the power look like it's gone '''
try:
# 385 is my "use"
reading = EmonCMS.getFeedValue(385, moment)
except:
return True
value = reading["value"]
if value:
return False
return True
def review():
outage_started = None
with open("outages.txt", "a") as outages:
# Convert to list so tqdm can give an ETA
pbar = tqdm.tqdm(list(generate_moment()))
for moment in pbar:
pbar.set_description(moment.isoformat())
if is_down_at_moment(moment):
if outage_started == None:
outage_started = moment
else:
if outage_started:
duration = moment - outage_started
outages.write(outage_started.isoformat() + "\t" + moment.isoformat() + "\t" + str(int(duration.total_seconds())))
outage_started = None
print("Complete")
# Python-y stuff...
def main():
review()
if __name__ == "__main__":
main()