aboutsummaryrefslogtreecommitdiffstats
path: root/tasmotaHTTPClient.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2025-02-16 14:16:43 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2025-02-16 14:16:43 +0000
commitdd7790dab8d3fbea8f2b58eb4d5aaffc36b3cb09 (patch)
treecd02b6348c1fd856133d934ed3459d35e0cf672e /tasmotaHTTPClient.py
parent8fc3775a16a6195f8ecf792cffe81afcf3b8a857 (diff)
downloadTasmotaCLI-master.tar.gz
TasmotaCLI-master.zip
Renamed the scripts to adhere to python conventionsHEADmaster
Diffstat (limited to 'tasmotaHTTPClient.py')
-rw-r--r--tasmotaHTTPClient.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tasmotaHTTPClient.py b/tasmotaHTTPClient.py
new file mode 100644
index 0000000..c151f3f
--- /dev/null
+++ b/tasmotaHTTPClient.py
@@ -0,0 +1,54 @@
+import asyncio
+import tasmotadevicecontroller
+import argparse
+import getpass
+import json
+import time
+
+async def main(host, username, password, toggle):
+ if username is None:
+ device = await tasmotadevicecontroller.TasmotaDevice.connect(host)
+ else:
+ device = await tasmotadevicecontroller.TasmotaDevice.connect(url = host, username = username, password = password)
+
+ if toggle:
+ await device.setPower(tasmotadevicecontroller.tasmota_types.PowerType.TOGGLE)
+ time.sleep(2)
+
+ friendlyname = await device.getFriendlyName()
+ power = await device.getPower()
+ status8 = await device.sendRawRequest("status 8")
+ watts = status8["StatusSNS"]["ENERGY"]
+ print(json.dumps(watts, indent = 4))
+
+ 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"
+)
+parser.add_argument(
+ "-t", "--toggle",
+ action = "store_true",
+ help = "Toggle current power status"
+)
+
+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"], args["toggle"]))