aboutsummaryrefslogtreecommitdiffstats
path: root/tasmota-cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'tasmota-cli.py')
-rw-r--r--tasmota-cli.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/tasmota-cli.py b/tasmota-cli.py
index c7d6eb7..c151f3f 100644
--- a/tasmota-cli.py
+++ b/tasmota-cli.py
@@ -2,18 +2,24 @@ import asyncio
import tasmotadevicecontroller
import argparse
import getpass
+import json
+import time
-async def main(host, username, password):
+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(watts)
+ print(json.dumps(watts, indent = 4))
if power:
print("'%s' is currently ON" % friendlyname)
@@ -32,7 +38,11 @@ parser.add_argument(
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())
@@ -41,4 +51,4 @@ if __name__ == "__main__":
else:
args["password"] = None
loop = asyncio.get_event_loop()
- loop.run_until_complete(main(args["device_host"], args["user"], args["password"]))
+ loop.run_until_complete(main(args["device_host"], args["user"], args["password"], args["toggle"]))