2. 创建1个dummy硬件代表空调
3. 该硬件下创建5个设备,分别代表 模式(多段)、风速(多段)、扫风(开关)、温度设置(Setpoint)、功率(电量)
4. 各设备名字、idx、多段名称更新至脚本
PS 调试tips
1. 使用前先调试python脚本,命令如下:
代码: 全选
python3 acpartner.py <acp_ip> <power> <mode> <wind> <swing> <temperature>
代码: 全选
python3 acpartner.py 10.0.0.148 on cooler auto off 22
python3 acpartner.py 10.0.0.148 off heater 3 on 25
python3 acpartner.py 10.0.0.148 off
抓码使用miio库,js环境,npm安装
https://github.com/aholstenson/miio (如果你安装了python-miio将会覆盖miio的cli命令)
使用wiresharks和安卓模拟器抓码,输出json文件后用miio命令解码 https://github.com/aholstenson/miio/blo ... rotocol.md
抓码结果显示
https://github.com/takatost/homebridge- ... r/issues/5
抓码后如果分析不来可以贴出来,有空会添加
3. python成功后再设置domoticz内lua或者其他events,上来就全部设置好不能用也不肯调试的概不帮忙
控制程序python控制程序更新已更新在其他楼层
代码: 全选
import mirobo
import urllib.request
import codecs
import sys
presets = {
"default": {
"description": "The Default Replacement of AC Partner",
"defaultMain": "modelpomowiswttli",
"VALUE": ["po", "mo", "wi", "sw", "tt", "li"],
"po": {
"type": "switch",
"on": "1",
"off": "0"
},
"mo": {
"heater": "0",
"cooler": "1",
"auto": "2",
"dehum": "3",
"airSup": "4"
},
"wi": {
"auto": "3",
"1": "0",
"2": "1",
"3": "2"
},
"sw": {
"on": "0",
"off": "1"
},
"tt": "10",
"li": "a0"
},
"0180111111": {
"des": "media_1",
"main": "0180111111pomowiswtt02"
},
"0180222221": {
"des": "gree_1",
"main": "0180222221pomowiswtt02"
},
"0100010727": {
"des": "gree_2",
"main": "0100010727pomowiswtt1100190t0t205002102000t6t0190t0t207002000000t4wt0",
"off": "010001072701011101004000205002112000D04000207002000000A0",
"EXTRA_VALUE": ["t0t", "t6t", "t4wt"],
"t0t": "1",
"t6t": "7",
"t4wt": "4"
},
"0100004795": {
"des": "gree_8",
"main": "0100004795pomowiswtt0100090900005002"
},
"0180333331": {
"des": "haier_1",
"main": "0180333331pomowiswtt12"
},
"0180666661": {
"des": "aux_1",
"main": "0180666661pomowiswtt12"
},
"0180777771": {
"des": "chigo_1",
"main": "0180777771pomowiswtt12"
},
"0100010502": {
"des": "daikin_1",
"main": "0100010502pomowiswttA0000011DA2700C50000D711DA27004200005411DA27000039t0t00A0000006600000C18000cs",
"off": "0100010502013112A0000011DA2700C50000D711DA27004200005411DA270000082000A0000006600000C1800081",
"EXTRA_VALUE": ["t0t", "cs"],
"t0t": "hex(int(cmd[4]) * 2)[2:]",
"cs": "hex(int(cmd[4]) * 2 + 146)[2:]"
}
}
#Domoticz服务器
domoticzserver = "127.0.0.1:8080"
#idx
# mode_idx = "154"
# wind_idx = "155"
# swing_idx = "156"
# set_temp_idx = "157"
acpower_idx = "158"
def domoticzrequest (url):
response = urllib.request.urlopen(url)
return response.read()
def get_current():
power = info[1][2]
mode = info[1][3]
wind = info[1][4]
swing = info[1][5]
set_temp = info[1][7]
acpower = info[2]
return [power, mode, wind, swing, set_temp, acpower]
def get_code(cmd):
if model not in presets:
code = presets['default']['defaultMain']
for i,k in enumerate(presets['default']['VALUE'][0:5]):
locals()[k] = presets['default'][k][cmd[i]]
li = presets['default']['li']
code = code.replace('model', model)
for k in presets['default']['VALUE'][0:5]:
code = code.replace(k, locals()[k])
code = code.replace('li', li)
else:
if cmd[0] == 'off':
if model in presets:
if 'off' in presets[model]:
code = presets[model]['off']
else:
code = presets[model]['main']
else:
code = presets[model]['main']
for i,k in enumerate(presets['default']['VALUE'][0:4]):
locals()[k] = presets['default'][k][cmd[i]]
tt = hex(int(cmd[4]))[2:]
for k in presets['default']['VALUE'][0:5]:
code = code.replace(k, locals()[k])
if 'EXTRA_VALUE' in presets[model]:
for k in presets[model]['EXTRA_VALUE']:
locals()[k] = eval(presets[model][k])
for k in presets[model]['EXTRA_VALUE']:
code = code.replace(k, locals()[k])
return code
ip = sys.argv[1]
Container = mirobo.Device.discover(ip)
token = str(codecs.encode(Container.checksum, 'hex'), 'utf-8')
AC_Parter = mirobo.Device(ip, token)
info = AC_Parter.send('get_model_and_state', [])
model = info[0][0:2] + info[0][8:16]
[current_power, current_mode, current_wind, current_swing, current_set_temp, acpower] = get_current()
if len(sys.argv) == 3:
if str(sys.argv[2]) == 'status':
domoticzrequest ("http://"+domoticzserver+"/json.htm?type=command¶m=udevice&idx="+acpower_idx+"&nvalue=0&svalue="+acpower)
print("Current Status:")
print("Power: "+current_power)
print("Mode: "+current_mode)
print("Wind: "+current_wind)
print("Swing: "+current_swing)
print("Temperature: "+current_set_temp)
print("AC Power: "+acpower+"W")
elif str(sys.argv[2]) == 'off':
power = "off"
cmd = [power,current_mode, current_wind, current_swing, current_set_temp]
else:
print("Wrong Command!")
elif len(sys.argv) == 7:
cmd = sys.argv[2:]
if 'cmd' in dir():
code = get_code(cmd)
if AC_Parter.send('send_cmd', [code]) == ['ok']:
[current_power, current_mode, current_wind, current_swing, current_set_temp, acpower] = get_current()
print("Success!")
else:
print("Wrong Command or Invaild Code!!")
代码: 全选
commandArray = {}
ACPartner_IP = '10.0.0.148'
for key, value in pairs(devicechanged) do
if (key == '卧室空调模式' or key == '卧室空调风速' or key == '卧室空调扫风' or key == '卧室空调温度') then
mode = otherdevices['卧室空调模式']
wind = otherdevices['卧室空调风速']
swing = otherdevices['卧室空调扫风']
temperature = math.floor(otherdevices_svalues['卧室空调温度'])
if (mode == 'Off') then po = 'off' mo = 'auto'
elseif (mode == '制冷') then po = 'on' mo = 'cooler'
elseif (mode == '制热') then po = 'on' mo = 'heater'
elseif (mode == '自动') then po = 'on' mo = 'auto'
elseif (mode == '送风') then po = 'on' mo = 'dehum'
elseif (mode == '除湿') then po = 'on' mo = 'airSup'
end
if (wind == '自动') then wi = 'auto'
elseif (wind == '1档') then wi = '1'
elseif (wind == '2档') then wi = '2'
elseif (wind == '3档') then wi = '3'
end
if (swing == 'Off') then sw = 'off'
elseif (swing == 'On') then sw = 'on'
end
tt = tostring(temperature)
cmd = ACPartner_IP.." "..po.." "..mo.." "..wi.." "..sw.." "..tt
print(cmd)
os.execute ('sudo python3 /home/pi/domoticz/scripts/python/acpartner.py '..cmd)
end
end
return commandArray
代码: 全选
commandArray = {}
ACPartner_IP = '10.0.0.148'
os.execute ('sudo python3 /home/pi/domoticz/scripts/python/acpartner.py '..ACPartner_IP..' status')
return commandArray