commands over HTTP, eg from my browser, such as http://<ip>/cm?cmnd=Power%20TOGGLE
. This is good!
I can even (confusingly) turn on and off the LED on the power button independently of the power to the load, eg: http://<ip>/cm?cmnd=LedPower%20ON
.
Trying and failing to restore the normal LED functionality, I tried resetting the device, but lost the Local Bytes configuration. I had to set up the WiFi again. I ended up with a reduced Web interface, and no power monitoring, and the power toggle button was ineffective. Boo hiss!
I suggest not doing what I did. Unless you know what you are doing, maybe!
Twitter and Robin Hawkes in particular came to the rescue in minutes: If you lost the config / Tasmota template you can find it here and paste it into the plug settings page. I accidentally hard-reset a plug and this got the measurements back again.
Courtesy of Local Bytes (UK) Power Monitoring Plug (smart-plug-pm-uk)
, pasting the configuration below into Configuration
> Configure Other
> Template
brings it all back as it was to my eye, hurrah!
{"NAME":"LocalBytes PM","GPIO":[0,0,0,32,2720,2656,0,0,2624,320,224,0,0,0],"FLAG":0,"BASE":18}
Now I note that the home page is claiming a mains voltage of ~310V+. It seems still to be ~245V, as it reported before the great resetting. Maybe I partly fried something while it was misconfigured? In any case I have cross-re-calibrated it against the Enphase live reading with http://IP/cm?cmnd=VoltageSet%20248
. That sets a calibration value of 1529, vs the default of 1950. Quite a shift.
Now this looks like what I need:
http://IP/cm?cmnd=Status 8
which returns:
{"StatusSNS":{"Time":"2022-10-05T21:21:53","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.004,"Yesterday":0.000,"Today":0.004,"Power": 6,"ApparentPower":14,"ReactivePower":13,"Factor":0.44,"Voltage":247,"Current":0.058}}}
which contains the live Power
value, hurrah!
(A quick test using my ~6W LED desk lamp indicates an active power of ~7W to ~8W, but a power factor of ~0.5, which is a bit uglier than I expected.)
The next task is to set up a 1-minute poll on the main RPi. It can use wget
to poll the plug, and jq
to parse and extract the power value, which can then be appended to a timestamped log. This would only be enabled when I am actively monitoring an appliance, though could be left to run for hours or days if need be.
I think that the dishwasher pre-wash cycle may make for a good initial case.
Distracted by a day of actual work yesterday, I am back on the case today. And good, I plugged it in and turned it on and it all just worked. Not to be assumed...
I have created a polling/logging script at script/pollLBPlug.sh
.
A basic run of the script with no arguments attempts to poll the plug and spit out the JSON string received:
% sh script/pollLBPlug.sh {"StatusSNS":{"Time":"2022-10-07T14:09:06","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.003,"Yesterday":0.000,"Today":0.003,"Power": 0,"ApparentPower": 0,"ReactivePower": 0,"Factor":0.00,"Voltage":248,"Current":0.000}}}
Running the script with the plug turned off (not running) gives a slightly-variable but not excessive timeout and no output:
% time sh script/pollLBPlug.sh 0.016u 0.014s 0:01.04 1.9% 0+0k 0+0io 0pf+0w % time sh script/pollLBPlug.sh 0.018u 0.014s 0:16.05 0.1% 0+0k 0+0io 0pf+0w
Running the script with the -log
argument is silent on stdout and appends records such as this to the log file named by day, and created if necessary:
% cat LBplug-2022-10-07.log 2022-10-07T13:36:41 {"StatusSNS":{"Time":"2022-10-07T14:36:41","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.003,"Yesterday":0.000,"Today":0.003,"Power": 0,"ApparentPower": 0,"ReactivePower": 0,"Factor":0.00,"Voltage":248,"Current":0.000}}} 2022-10-07T13:36:54 {"StatusSNS":{"Time":"2022-10-07T14:36:53","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.003,"Yesterday":0.000,"Today":0.003,"Power": 0,"ApparentPower": 0,"ReactivePower": 0,"Factor":0.00,"Voltage":248,"Current":0.000}}}
If the plug is not responding no records are appended. So at worst if forgetting to disable a logging cron
job, the filesystem is not filled with garbage!
To set this up in cron
to sample once per minute, append to crontab
(can be commented out when not in use):
# Optional per-minute gathering of data from Local Bytes monitoring plug. * * * * * cd /rw/docs-public/www.hd.org/Damon/Env && sh script/pollLBPlug.sh -lo
The first appliance I will monitor with this will be my old foe the fridge...
2022-10-07T14:01:01 {"StatusSNS":{"Time":"2022-10-07T15:01:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.003,"Yesterday":0.000,"Today":0.003,"Power": 2,"ApparentPower":12,"ReactivePower":12,"Factor":0.13,"Voltage":248,"Current":0.049}}} 2022-10-07T14:02:01 {"StatusSNS":{"Time":"2022-10-07T15:02:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.003,"Yesterday":0.000,"Today":0.003,"Power": 2,"ApparentPower":11,"ReactivePower":11,"Factor":0.15,"Voltage":248,"Current":0.046}}} ...
I can see the consumption rise from 2W to ~7W when I open the door and the (LED) lights come on!
Raw data (.log.gz
) from 7th, 8th, 9th, 10th. See all artefacts.
It seems that a single sample was missed/dropped across the two full days, which is pretty good and may well have been the WiFi system's fault:
% wc -l LBplug-2022-10-0{8,9}.log 1439 LBplug-2022-10-08.log 1440 LBplug-2022-10-09.log
On Twitter @LocalBytesShop
said: We're a big fan of using the PowerDelta command to increase resolution
. The WattRes
command applies when polling over HTTP, I think. For my current purposes, and with only minimal calibration, this is advanced-class material! If I do make use of WattRes
, eg to go to 1DP, then I will have to extend my regex to extract a non-integer power value.
For further examination of the data see 2022-10: Yet More Measurements.
Next in line will probably be the TiVo cable TV box and friends, to see how much energy they are actually using, eg when left on overnight unnecessarily!
Looking at the data I note a couple of things that could probably be fixed:
Z
' has been omitted from the log timestamp, so it is not unambiguously UTC. jq
to be able to extract UTC time and data values. Initially I have fixed only the missing 'Z
'. I have also invoked the WattRes 1
command and will adjust parsing scripts to cope.
Here are some relevant lines from from the log while doing the above:
2022-10-10T07:13:02 {"StatusSNS":{"Time":"2022-10-10T08:13:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.483,"Yesterday":1.230,"Today":0.455,"Power": 3,"ApparentPower": 9,"ReactivePower": 9,"Factor":0.28,"Voltage":246,"Current":0.038}}} ... 2022-10-10T08:56:01Z {"StatusSNS":{"Time":"2022-10-10T09:56:02","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.030,"Yesterday":1.230,"Today":0.003,"Power": 0,"ApparentPower": 0,"ReactivePower": 0,"Factor":0.00,"Voltage":249,"Current":0.000}}} ... 2022-10-10T09:13:01Z {"StatusSNS":{"Time":"2022-10-10T10:13:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.030,"Yesterday":1.230,"Today":0.003,"Power":37.9,"ApparentPower":50.6,"ReactivePower":33.5,"Factor":0.75,"Voltage":249,"Current":0.203}}}
The plug's home page now shows 1DP for the W, VA and VAr values.
Initial observation suggests that the extra digit is not entirely noise!
Jumping the queue, I shall take a quick profile of our dishwasher prewash cycle.
Before, with the dial in the "off" position and no LEDs lit up:
2022-10-10T09:29:01Z {"StatusSNS":{"Time":"2022-10-10T10:29:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.030,"Yesterday":1.230,"Today":0.003,"Power":0.0,"ApparentPower":9.5,"ReactivePower":9.5,"Factor":0.00,"Voltage":249,"Current":0.038}}}
Raw data (.log.gz
) from 10th. See all artefacts.
The entire set of power readings is:
2022-10-10T09:29:01ZZ 0.0 2022-10-10T09:30:01ZZ 0.7 2022-10-10T09:31:02ZZ 0.6 2022-10-10T09:32:02ZZ 0.5 2022-10-10T09:33:01ZZ 24.1 2022-10-10T09:34:01ZZ 9.0 2022-10-10T09:35:01ZZ 102.3 2022-10-10T09:36:01ZZ 103.0 2022-10-10T09:37:01ZZ 102.3 2022-10-10T09:38:01ZZ 99.3 2022-10-10T09:39:02ZZ 103.3 2022-10-10T09:40:01ZZ 101.1 2022-10-10T09:41:01ZZ 100.6 2022-10-10T09:42:01ZZ 101.8 2022-10-10T09:43:02ZZ 101.3 2022-10-10T09:44:01ZZ 102.3 2022-10-10T09:45:01ZZ 101.0 2022-10-10T09:46:01ZZ 102.0 2022-10-10T09:47:01ZZ 10.9 2022-10-10T09:48:01ZZ 0.6 2022-10-10T09:49:01ZZ 0.7 2022-10-10T09:50:01ZZ 0.5 2022-10-10T09:51:01ZZ 0.6 2022-10-10T09:52:01ZZ 0.6
Looking at the before and after 'total' energy values of 3.030kWh and 3.056kWh indicates a total consumption of 0.026kWh (26Wh) as previously estimated.
As of I have the plug monitoring everything in the TV corner. That includes the TV and DVD player and cable box (TiVo), plus a standard lamp and games console. Currently all is off at the wall, so the plug will be silent, and I should treat missing samples as 0W. To that end I am manually inserting 0 samples just after each block of use.
Raw data (.log.gz
) from 10th, 11th, 12th, 13th, 14th, 15th, 16th, 17th, 18th, 19th. See all artefacts.
The TV is on at ~4pm and the log is showing nothing. I think that the plug cannot hear the WiFi router: they are about as far apart as is possible in this house. The (2.4Ghz) channel is already at maximum power. I have tried rebooting the router, and oddly the plug is now visible.
Also, oddly, the total energy accumulator seems to have gone backwards a little bit:
2022-10-10T09:51:01Z {"StatusSNS":{"Time":"2022-10-10T10:51:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.056,"Yesterday":1.230,"Today":0.029,"Power":0.6,"ApparentPower":6.7,"ReactivePower":6.7,"Factor":0.09,"Voltage":249,"Current":0.027}}} 2022-10-10T09:52:01Z {"StatusSNS":{"Time":"2022-10-10T10:52:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.056,"Yesterday":1.230,"Today":0.029,"Power":0.6,"ApparentPower":9.7,"ReactivePower":9.7,"Factor":0.06,"Voltage":248,"Current":0.039}}} 2022-10-10T14:59:01Z {"StatusSNS":{"Time":"1970-01-01T00:24:08","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.048,"Yesterday":1.230,"Today":0.020,"Power":53.2,"ApparentPower":72.7,"ReactivePower":49.6,"Factor":0.73,"Voltage":247,"Current":0.294}}} 2022-10-10T15:00:01Z {"StatusSNS":{"Time":"1970-01-01T00:25:08","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.049,"Yesterday":1.230,"Today":0.021,"Power":56.7,"ApparentPower":78.8,"ReactivePower":54.7,"Factor":0.72,"Voltage":248,"Current":0.318}}}
TV on standby + TiVo cable box seem to be using ~16W total.
2022-10-10T16:07:01Z {"StatusSNS":{"Time":"2022-10-10T17:07:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.101,"Yesterday":1.230,"Today":0.073,"Power":15.8,"ApparentPower":28.1,"ReactivePower":23.3,"Factor":0.56,"Voltage":247,"Current":0.114}}}
The TV and TiVo and lamp on eat ~75W.
2022-10-10T18:36:01Z {"StatusSNS":{"Time":"2022-10-10T19:36:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.215,"Yesterday":1.230,"Today":0.188,"Power":75.4,"ApparentPower":91.9,"ReactivePower":52.6,"Factor":0.82,"Voltage":248,"Current":0.371}}}
The cumulative total seems to have slipped back again when the plug had power removed overnight, again:
2022-10-10T21:01:01Z {"StatusSNS":{"Time":"2022-10-10T22:01:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.397,"Yesterday":1.230,"Today":0.370,"Power":51.3,"ApparentPower":77.0,"ReactivePower":57.4,"Factor":0.67,"Voltage":248,"Current":0.310}}} ... 2022-10-11T05:31:01Z {"StatusSNS":{"Time":"2022-10-11T06:31:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.030,"Yesterday":1.230,"Today":0.003,"Power":23.1,"ApparentPower":33.6,"ReactivePower":24.4,"Factor":0.69,"Voltage":245,"Current":0.137}}}
It is quite possible that the appropriate values are only committed to non-volatile storage after a fairly significant quantum, ie that the plug itself does not expect to lose power often.
For applications such as this I may have to sum implied energy for every minute that I do get a poll response.
Preparation of intermediate files from the central full eight days:
% cat LBplug-2022-10-1{1,2,3,4,5,6,7,8}.log.gz | gzip -d | xz -v -e --best > LBplug-full-8-days.log.xz % cat LBplug-2022-10-1{1,2,3,4,5,6,7,8}.log.gz | gzip -d | sh ./powerExtractZ.sh | xz -v -e --best > LBplug-full-8-days.power.xz % xz -d < LBplug-full-8-days.power.xz | wc -l 4735 % xz -d < LBplug-full-8-days.power.xz | egrep ' 0$' | wc -l 34 % xz -d < LBplug-full-8-days.power.xz | awk '{s+=$2}END{print s/60}' 4133.37
Thus 4701 1-minute records plus 34 manually inserted 0 records. That is ~78h 'on' (~9.6h/d, up to ~8.3h/d watched) out of 192h for a ~41% duty cycle.
A total of 4133Wh (4.133kWh) was used over those 8 days, ie ~517Wh/d, with a mean power of ~22W, or ~53W while on for the "TV corner" as a whole. That is very roughly 10% of daily demand (excluding for hot water via the Thermino).
(Note that the DVD player is not plugged in. The X-box is off, but plugged in.)
% xz -d < LBplug-full-8-days.power.xz | awk '$2>60{++n;s+=$2}END{print n,s/60}' 1730 2261.43 % xz -d < LBplug-full-8-days.power.xz | awk '$2>20&&$2<=60{++n;s+=$2}END{print n,s/60}' 2276 1699.05 % xz -d < LBplug-full-8-days.power.xz | awk '$2>0&&$2<=20{++n;s+=$2}END{print n,s/60}' 695 172.89
This test is a detailed load profile of a cottons cold wash in the Zanussi ZWF01483W washing machine.
Enphase 1-minute sampling is also enabled around this test (.log.gz
). Though I am alone in the house, other appliances are running such as a dishwasher rinse and the fridge/freezer doing its thing. The Enphase battery should largely be able to keep the net grid flow to zero. (Nothing is expected to generate or draw more than 1kW during this test.)
Raw data (.log.gz
) from 29th. See all artefacts.
Total energy consumption apparently 0.407kWh ("Today" 0.410 - 0.003):
2022-10-29T08:34:01Z {"StatusSNS":{"Time":"2022-10-29T09:34:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.030,"Yesterday":1.230,"Today":0.003,"Power":0.0,"ApparentPower":0.0,"ReactivePower":0.0,"Factor":0.00,"Voltage":246,"Current":0.000}}} ... 2022-10-29T11:10:01Z {"StatusSNS":{"Time":"2022-10-29T12:10:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.437,"Yesterday":1.230,"Today":0.410,"Power":0.1,"ApparentPower":8.6,"ReactivePower":8.6,"Factor":0.01,"Voltage":247,"Current":0.035}}}
Consumption (Wh) looks more like expected when minute samples are summed:
% gzip -d < LBplug-2022-10-29.log.gz | sh ./powerExtractZ.sh | awk '{s+=$2}END{print s/60}' 383.238
This test is a detailed load profile of a 50°C 'eco' wash on a moderately full load.
Enphase 1-minute sampling is also enabled around this test (.log.gz
). Though I am alone in the house, other appliances are running such as the fridge/freezer doing its thing.
Raw data (.log.gz
) from 29th. See all artefacts.
Actual duration ~196m, so just short of that indicated by the initial display.
Power consumption from 12:24Z to 15:42Z apparently 0.946kW ("Today" 0.949 - 0.003):
2022-10-29T12:24:01Z {"StatusSNS":{"Time":"2022-10-29T13:24:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.030,"Yesterday":1.230,"Today":0.003,"Power":0.2,"ApparentPower":8.9,"ReactivePower":8.9,"Factor":0.02,"Voltage":247,"Current":0.036}}} ... 2022-10-29T15:42:01Z {"StatusSNS":{"Time":"2022-10-29T16:42:02","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":3.977,"Yesterday":1.230,"Today":0.949,"Power":0.2,"ApparentPower":4.9,"ReactivePower":4.9,"Factor":0.04,"Voltage":247,"Current":0.020}}}
Consumption (Wh) looks more like expected when minute samples are summed:
% gzip -d < LBplug-2022-10-29.log.gz | sh ./powerExtractZ.sh | awk '{s+=$2}END{print s/60}' 761.657
This test is a detailed load profile of two cottons Eco 40°C washes in the Zanussi ZWF01483W washing machine.
Enphase 1-minute sampling is also enabled around this test (.log.gz
).
Raw data (.log.gz
) from 4th. See all artefacts.
Energy consumptions estimated from 1-minute samples, ~0.45kWh and ~1.23kWh:
% gzip -d < run1.log.gz | awk '{s+=$2}END{print s/60}' 454.18 % gzip -d < run2.log.gz | awk '{s+=$2}END{print s/60}' 1228.23
This time we are being careful to manage the load. This load is just the bedding from a single bed.
(Mains inlet temperature ~13°C? Start approx 08:07Z.)
IN PROGRESS