From 95d293b91147325d6a22be30766ffbc3c8743de3 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Tue, 13 Oct 2026 21:29:02 +0200 Subject: [PATCH] =?UTF-8?q?Bench:=20--plug=20hp=20=E2=80=94=20the=20HP=20t?= =?UTF-8?q?740=20(demo-hp)=20is=20on=20a=20metered=20plug=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit plugmeter.py and plugswitch.py take --plug n100|hp (plug.json / plug-hp.json, outside the repo). The HP plug read 23-33 W while the box started its three guests. --- scripts/bench/README.md | 7 +++++++ scripts/bench/plugmeter.py | 10 +++++++--- scripts/bench/plugswitch.py | 14 +++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/bench/README.md b/scripts/bench/README.md index 33925f24..2e3e8684 100644 --- a/scripts/bench/README.md +++ b/scripts/bench/README.md @@ -46,3 +46,10 @@ update `plug.json`. Its output prints the key — send it to a file, never to a The N100 does **not** start when the plug comes back on after a deliberate power-off (2026-10-13, `documentation/audits/poweroff-2026-10-13/`): press its power button. + +## The HP t740 (demo-hp) is on a metered plug too (2026-10-13) + +Same tools, `--plug hp` (config `~/.config/felhom-bench/plug-hp.json`, the plug at LAN `192.168.0.107`, protocol 3.4, +the HP at `192.168.0.104`). `plugswitch.py off --plug hp` refuses until the HP's switched-off figure (`standby_w`) is +measured. The wizard reads both plugs from one Tuya account; the credentials are `TUYA_DEVICE_ID_N100` and +`TUYA_DEVICE_ID_HP` (renamed from `TUYA_DEVICE_ID` by the operator). diff --git a/scripts/bench/plugmeter.py b/scripts/bench/plugmeter.py index a45cea55..694d9707 100644 --- a/scripts/bench/plugmeter.py +++ b/scripts/bench/plugmeter.py @@ -4,6 +4,7 @@ ~/.venvs/plugmeter/bin/python scripts/bench/plugmeter.py --once ~/.venvs/plugmeter/bin/python scripts/bench/plugmeter.py --duration 600 > run.csv ~/.venvs/plugmeter/bin/python scripts/bench/plugmeter.py --source ha --once + ~/.venvs/plugmeter/bin/python scripts/bench/plugmeter.py --plug hp --once # the HP t740 (demo-hp) CSV columns: utc_time, watts, milliamps, volts, kwh_total. @@ -28,6 +29,8 @@ never printed. Secrets live only in ~/.config/felhom-bench/ (700/600), never in import argparse, datetime, http.client, json, os, socket, ssl, sys, time CONF = os.path.expanduser('~/.config/felhom-bench') +# --plug: which machine's plug (2026-10-13: the N100 on plug.json, the HP t740 on plug-hp.json). +PLUG_FILES = {'n100': 'plug.json', 'hp': 'plug-hp.json'} def log(msg): @@ -39,9 +42,9 @@ def now(): class TuyaSource: - def __init__(self): + def __init__(self, plug='n100'): import tinytuya - c = json.load(open(os.path.join(CONF, 'plug.json'))) + c = json.load(open(os.path.join(CONF, PLUG_FILES[plug]))) self.dps = c['dps'] self.dev = tinytuya.OutletDevice(c['id'], c['ip'], c['key'], version=float(c['version'])) self.dev.set_socketTimeout(5) @@ -119,9 +122,10 @@ def main(): ap.add_argument('--interval', type=float, default=2.0, help='seconds between reads (default 2)') ap.add_argument('--duration', type=float, default=0, help='seconds to run; 0 = until stopped') ap.add_argument('--once', action='store_true', help='one read, then exit (rc 1 if it failed)') + ap.add_argument('--plug', choices=sorted(PLUG_FILES), default='n100', help='which machine (tuya source only)') a = ap.parse_args() - src = TuyaSource() if a.source == 'tuya' else HASource() + src = TuyaSource(a.plug) if a.source == 'tuya' else HASource() print('utc_time,watts,milliamps,volts,kwh_total', flush=True) start = time.monotonic() fails = 0 diff --git a/scripts/bench/plugswitch.py b/scripts/bench/plugswitch.py index f483d257..58934fdd 100644 --- a/scripts/bench/plugswitch.py +++ b/scripts/bench/plugswitch.py @@ -4,6 +4,7 @@ ~/.venvs/plugmeter/bin/python scripts/bench/plugswitch.py status ~/.venvs/plugmeter/bin/python scripts/bench/plugswitch.py off ~/.venvs/plugmeter/bin/python scripts/bench/plugswitch.py on + ~/.venvs/plugmeter/bin/python scripts/bench/plugswitch.py status --plug hp # the HP t740's plug Reads ~/.config/felhom-bench/plug.json (the same file plugmeter.py reads). `off` also needs, in that file: "standby_w": the plug's measured reading with the machine powered off (the A2 figure); @@ -18,14 +19,14 @@ The key and the device id are never printed. Pinned by scripts/bench/test_plugsw """ import json, os, subprocess, sys, time -CONF = os.path.expanduser('~/.config/felhom-bench/plug.json') +PLUG_FILES = {'n100': 'plug.json', 'hp': 'plug-hp.json'} # --plug, as plugmeter.py WINDOW_S = 20 STEP_S = 2 MARGIN_W = 1.0 -def load(): - return json.load(open(CONF)) +def load(plug='n100'): + return json.load(open(os.path.expanduser('~/.config/felhom-bench/' + PLUG_FILES[plug]))) def device(c): @@ -71,11 +72,14 @@ def off_allowed(samples, standby_w, window_s=WINDOW_S): def main(argv): + plug = 'n100' + if len(argv) == 4 and argv[2] == '--plug' and argv[3] in PLUG_FILES: + plug, argv = argv[3], argv[:2] if len(argv) != 2 or argv[1] not in ('on', 'off', 'status'): - print('usage: plugswitch.py on|off|status', file=sys.stderr) + print('usage: plugswitch.py on|off|status [--plug n100|hp]', file=sys.stderr) return 64 cmd = argv[1] - c = load() + c = load(plug) dev = device(c) if cmd == 'status': w, on = read_watts(dev, c)