diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-11-21 18:29:57 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-11-21 18:29:57 +0000 |
commit | 6009f6fad75113fab55cb6c80a93035e979901dd (patch) | |
tree | d336ef419eba2060d6b245eafe2a90950dbd7507 | |
parent | 03cb041367cacdf0b05f29ae065dac7267a59cfa (diff) | |
download | TasmotaCLI-6009f6fad75113fab55cb6c80a93035e979901dd.tar.gz TasmotaCLI-6009f6fad75113fab55cb6c80a93035e979901dd.zip |
Added polling current stats
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | tasmota-cli.py | 44 |
2 files changed, 46 insertions, 0 deletions
diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c292ad5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +tasmotadevicecontroller +aiohttp diff --git a/tasmota-cli.py b/tasmota-cli.py new file mode 100644 index 0000000..c7d6eb7 --- /dev/null +++ b/tasmota-cli.py @@ -0,0 +1,44 @@ +import asyncio +import tasmotadevicecontroller +import argparse +import getpass + +async def main(host, username, password): + if username is None: + device = await tasmotadevicecontroller.TasmotaDevice.connect(host) + else: + device = await tasmotadevicecontroller.TasmotaDevice.connect(url = host, username = username, password = password) + + friendlyname = await device.getFriendlyName() + power = await device.getPower() + status8 = await device.sendRawRequest("status 8") + watts = status8["StatusSNS"]["ENERGY"] + print(watts) + + if power: + print("'%s' is currently ON" % friendlyname) + else: + print("'%s' is currently OFF" % friendlyname) + +parser = argparse.ArgumentParser() +parser.add_argument( + "-d", "--device-host", + type = str, + help = "Tasmota host port", + required = True +) +parser.add_argument( + "-u", "--user", + type = str, + help = "Username to login with" +) + + +if __name__ == "__main__": + args = vars(parser.parse_args()) + if args["user"] is not None: + args["password"] = getpass.getpass("Input password for %s@%s: " % (args["user"], args["device_host"])) + else: + args["password"] = None + loop = asyncio.get_event_loop() + loop.run_until_complete(main(args["device_host"], args["user"], args["password"])) |