Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt watt.py to changed status response starting Tasmota 14.x #2840

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions packages/modules/smarthome/tasmota/watt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@
import sys
import time
import json
import jq
import urllib.request
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S tasmota watty.py", named_tuple)
devicenumber = str(sys.argv[1])
ipadr = str(sys.argv[2])
uberschuss = int(sys.argv[3])
relais = 0
jsonurl1 = "http://"+str(ipadr)+"/cm?cmnd=Status"
jsonurl2 = "http://"+str(ipadr)+"/cm?cmnd=Status%208"
jsonpow = ".Status.Power"

try:
answer2 = json.loads(str(urllib.request.urlopen("http://"+str(ipadr) +
"/cm?cmnd=Status", timeout=3).read().decode("utf-8")))
r_status = int(answer2['Status']['Power'])
answer = json.loads(str(urllib.request.urlopen(jsonurl1, timeout=3).read().decode("utf-8")))
p_status = jq.compile(jsonpow).input(answer).first()
if type(p_status) is int:
relais = p_status % 2
elif type(p_status) is str:
relais = int(p_status, 2) % 2
else:
relais = 0
except Exception:
r_status = 0
answer = json.loads(str(urllib.request.urlopen("http://"+str(ipadr) +
"/cm?cmnd=Status%208", timeout=3).read().decode("utf-8")))
relais = 0

try:
aktpower = int(answer['StatusSNS']['ENERGY']['Power'])
answer = json.loads(str(urllib.request.urlopen(jsonurl2, timeout=3).read().decode("utf-8")))
aktpower = int(answer['StatusSNS']['ANALOG']['CTEnergy']['Power'])
powerc = int((answer['StatusSNS']['ANALOG']['CTEnergy']['Energy']) * 1000)
except Exception:
aktpower = 0
if (aktpower > 50) or (r_status == 1):
relais = 1
powerc = 0
powerc = 0

answer = '{"power":' + str(aktpower) + ',"powerc":' + str(powerc) + ',"on":' + str(relais) + '} '
f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w')
json.dump(answer, f1)
Expand Down