In the ongoing saga…
A few days ago I stupidly left a refrigerator door ajar, and made a bit of a mess, and it occurred to me that IoTaWatt and HA gives me the tools to deal with that. What I really want is a temperature alarm inside the fridge, but batteries do not work well there, and I’m not sure about running a USB cord in through the door insulation. Maybe.
But this is easy. I’m taking minute by minute watt measurements, and I see the fridge is only a few watts at idle, and 100+ separately, and tends normally to run in 30-45 minute periods. So…
So I fired up Node Red and built a flow that is centered on this influxdb query:
select time, ct, Watts
from Watts
where Watts < 40 and ct =~ /Fridge/
group by *
order by time desc
limit 1
tz('America/New_York')
(Line breaks added for clarity). I have two fridges, and the “ct” distinguishes them. This returns a message payload that has the time (sadly not TZ converted, so that aspect is probably moot) of the last time that fridge was using less than 40 watts.
Then in the next node I pull it apart, calculate whether I’ve complained recently or need to complain. The core math looks like this in a function node:
for (loopcnt=0; loopcnt<msg.payload.length; loopcnt++)
{
var last = new Date(msg.payload[loopcnt].time);
var diff = now - last;
var min = Math.round(diff / 1000 / 60);
if(diff > FridgeMaxRuntimeMS)
{
speakstring += (speakstring===''?'':', ');
speakstring += msg.payload[loopcnt].ct + " has been running " + min + " minutes ";
}
}
A nice aspect of Node Red is the loop – I could handle any number of devices that fit this sort of model.
FridgeMaxRuntimeMS is a context variable that gives the limit of how long I let it run before complaining (I use 90 minutes, the time is in milliseconds). I then construct an announcement string and let Google broadcast it on all the house speakers. There’s some logic also in there so it will only repeat the announcement every 30 minutes not even loop.
I did this in Node Red inside of HA, instead of HA itself, as to do it in automation in HA you still need that sort of query (probably in a value template that turns it to “alarm” or “not alarm”), but dealing with the “when and how do I alert” is much easier in Node-Red. I’m doing almost all automation in Node-Red now.
I also threw in a separate calculation into a rollup field for duty cycle that looks like this:
SELECT count(running) / count(total) AS DutyCycle INTO HA.hourly.DutyCycle
FROM
(SELECT Watts AS total FROM HA.autogen.Watts GROUP BY *),
(SELECT Watts AS running FROM HA.autogen.Watts WHERE Watts > 40 GROUP BY *)
GROUP BY *, time(1h) fill(0)
This looks at the minute by minute periods to see when a device is running over 40 watts (a rather arbitrary “idle” limit) and saves as a fraction of total intervals. So this is a decent estimate of the duty cycle in use.
I’m not sure it is hugely better than just kWh used over time, but I figure if it starts to show more a more erratic nature, or starts to grow significantly, it might indicate some kind of issue. I didn’t do this just for the fridge but for anything – the A/C duty cycle should somewhat track outside temperature, if over months I start seeing a significant change I can look into its efficiency or refrigerant levels.
Kind of cool the stuff you can get.
Oh… I left the door open on a fridge that just had sodas and such in it (i.e. nothing went bad); 90 minutes later Google starts complaining. I was surprised, I closed the door and it took almost 2 hours to stop running, so four complaints at least. Good thing google’s got a polite voice.
Here’s what some of the data looked like. One thing I found odd was that my fridge apparently has two speeds for the compressor – after failing to cool adequately for a while, it doubled its current draw. You can see how the yellow envelop, which is duty cycle, pretty much parallels kWh, so it’s not clear how useful that is going to be over time, but who knows.
The peak at about 4pm on 3/27 is when I loaded it up after a trip to the store. What’s mysterious is the 5am peak on 3/29 – some kind of defrost cycle? It jumped up to 500w (from about 100 normally) for about 20 minutes.
Anyway, just sharing stuff in case it helps anyone with ideas.