Re: domoticz et prise connecté smart life
Publié : 21 sept. 2021, 21:37
Le dossier Domoticz-TUYA est bien créé dans le dossier plugin de DomoticZ ?
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
2021-09-22 12:03:23.531 tuya: (tuya) TUYA plugin started
2021-09-22 12:03:23.532 tuya: (tuya) Debug logging mask set to: PYTHON CONNECTION
2021-09-22 12:03:23.532 tuya: (tuya) 'HardwareID':'52'
2021-09-22 12:03:23.532 tuya: (tuya) 'HomeFolder':'/home/pi/domoticz/plugins/Domoticz-TUYA-Plugin/'
2021-09-22 12:03:23.532 tuya: (tuya) 'StartupFolder':'/home/pi/domoticz/'
2021-09-22 12:03:23.532 tuya: (tuya) 'UserDataFolder':'/home/pi/domoticz/'
2021-09-22 12:03:23.532 tuya: (tuya) 'Database':'/home/pi/domoticz/domoticz.db'
2021-09-22 12:03:23.532 tuya: (tuya) 'Language':'fr'
2021-09-22 12:03:23.532 tuya: (tuya) 'Version':'1.0.12'
2021-09-22 12:03:23.532 tuya: (tuya) 'Author':'Wagner Oliveira contributed Xenomes'
2021-09-22 12:03:23.532 tuya: (tuya) 'Name':'tuya'
2021-09-22 12:03:23.532 tuya: (tuya) 'Port':'0'
2021-09-22 12:03:23.532 tuya: (tuya) 'Username':'xxxxxxxxxx@free.fr'
2021-09-22 12:03:23.532 tuya: (tuya) 'Password':'xxxxxxxxxxxx'
2021-09-22 12:03:23.532 tuya: (tuya) 'Key':'tuya'
2021-09-22 12:03:23.532 tuya: (tuya) 'Mode1':'1'
2021-09-22 12:03:23.532 tuya: (tuya) 'Mode2':'tuya'
2021-09-22 12:03:23.532 tuya: (tuya) 'Mode6':'18'
2021-09-22 12:03:23.532 tuya: (tuya) 'DomoticzVersion':'2021.1 (build 13482)'
2021-09-22 12:03:23.532 tuya: (tuya) 'DomoticzHash':'e8eb6e363'
2021-09-22 12:03:23.532 tuya: (tuya) 'DomoticzBuildTime':'2021-08-24 17:14:18'
2021-09-22 12:03:23.533 tuya: (tuya) Device count: 0
2021-09-22 12:03:23.534 tuya: (tuya) in handlethread
2021-09-22 12:03:23.638 tuya: (tuya) onHeartbeat called time=1632305003.6379702
2021-09-22 12:03:23.639 tuya: (tuya) in handlethread
2021-09-22 12:03:23.639 tuya: (tuya) Device count: 0
2021-09-22 12:03:33.055 tuya: (tuya) onHeartbeat called time=1632305013.0551653
2021-09-22 12:03:43.074 tuya: (tuya) onHeartbeat called time=1632305023.07472
2021-09-22 12:03:53.093 tuya: (tuya) onHeartbeat called time=1632305033.093152
2021-09-22 12:04:03.069 tuya: (tuya) onHeartbeat called time=1632305043.0695364
2021-09-22 12:04:13.089 tuya: (tuya) onHeartbeat called time=1632305053.089601
2021-09-22 12:04:23.057 tuya: (tuya) onHeartbeat called time=1632305063.056877Code : Tout sélectionner
Plug State Information:
{'dps': {'1': True, '9': 0, '17': 100, '18': 1292, '19': 2907, '20': 2281, '21': 1, '22': 590, '23': 27702, '24': 15312, '25': 2720, '26': 0, '38': 'memory', '39': False, '42': '', '43': ''}}
Plug DPS List:
1;39Code : Tout sélectionner
#!/usr/bin/python3
########################################################################################
# Domoticz Tuya Smart Plug Python script #
# #
# #
# #
# Copyright (c) 2022 Wallb35 #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
# copies of the Software, and to permit persons to whom the Software is #
# furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in all #
# copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
# SOFTWARE. #
# #
########################################################################################
#v0.6 - 5 JUL 2022
import sys
import pytuya
import socket #needed for socket.timeout exception
import urllib.request
import base64
UPDATEOK = "success"
UPDATEFAILED = "FAILED"
DOMSERVER = "http://localhost:8084" # domoticz local IP + port
DOMUSER = "domoticzuser" # !!!
DOMPASS = "Domoticzpassword" # !!!
BASE64STR = base64.encodebytes(('%s:%s' % (DOMUSER, DOMPASS)).encode()).decode().replace('\n', '')
def domrequest (url):
request = urllib.request.Request(url)
request.add_header("Authorization", "Basic %s" % BASE64STR)
response = urllib.request.urlopen(request)
return response.read()
if(len(sys.argv)!=8):
print("usage: " + sys.argv[0] + " <IP> <DevID> <DevKey> <butwatid> <butvolid> <butintid> <butkwhid>")
exit(1)
ip = sys.argv[1]
devid = sys.argv[2]
devkey = sys.argv[3]
butwatid = sys.argv[4]
butvolid = sys.argv[5]
butintid = sys.argv[6]
butkwhid = sys.argv[7]
device = pytuya.OutletDevice(devid,ip,devkey)
data = 0 #stub for the try except
try:
device.set_version(3.3)
data = device.status()
except (ConnectionResetError, socket.timeout, OSError) as e:
print("A problem occur please retry...")
exit(1)
values = data["dps"]
amp = int(values["18"])/1000
watt = int(values["19"])/10
volt= int(values["20"])/10
req = domrequest(
DOMSERVER + "/json.htm?type=command¶m=udevice&idx=" + butwatid + "&nvalue=0&svalue="
+ str(watt)
)
if "OK" in str(req):
res = "OK"
else:
res = "FAILED"
req = domrequest(
DOMSERVER + "/json.htm?type=command¶m=udevice&idx=" + butkwhid + "&nvalue=0&svalue="
+ str(watt) + ";0"
)
if "OK" in str(req):
res = "OK"
else:
res = "FAILED"
print("watts : domoticz update =>", (UPDATEOK if "OK" in str(req) else UPDATEFAILED))
req = domrequest(
DOMSERVER + "/json.htm?type=command¶m=udevice&idx=" + butvolid + "&nvalue=0&svalue="
+ str(volt)
)
if "OK" in str(req):
res = "OK"
else:
res = "FAILED"
print("volt : domoticz update =>", (UPDATEOK if "OK" in str(req) else UPDATEFAILED))
req = domrequest(
DOMSERVER + "/json.htm?type=command¶m=udevice&idx=" + butintid + "&nvalue=0&svalue="
+ str(amp)
)
if "OK" in str(req):
res = "OK"
else:
res = "FAILED"
print("amp : domoticz update =>", (UPDATEOK if "OK" in str(req) else UPDATEFAILED))