分页: 1 / 1

博联A1脚本

发表于 : 周三 5月 24, 2017 19:36
gliders
可以获取A1的的数据,只需要建立几个虚拟开关就可以了。

代码: 全选

#!/usr/bin/python
# -*- encoding: utf-8 -*-
import broadlink
import time
import sys
import requests
import urllib
import urllib2

device = broadlink.a1(host=("A1的IP地址",80), mac=bytearray.fromhex("A1的MAC地址"))
device.auth()
data = device.check_sensors_raw()

air_quality = data['air_quality']  
temperature = data['temperature']  
light = data['light']  
noise = data['noise']   
humidity = data ['humidity'] 


domoticzserver   = "127.0.0.1:8084"
domoticzusername = ""
domoticzpassword = ""
AIR_IDX="25"
TEMP_IDX="18"
LIGHT_IDX="23"
NOISE_IDX="24"
HUMIDITY_IDX="19"

############





#update temperature
val_temp = "{}".format(temperature)
#print temperature
#print val_temp
url = "http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx="+ TEMP_IDX + "&nvalue=0&svalue=" + val_temp
#print url
response = urllib2.urlopen(url)
#html=response.read()
#print html

#update humidity
val_temp = "{}".format(humidity)
url = "http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx="+ HUMIDITY_IDX + "&nvalue=" + val_temp
response = urllib2.urlopen(url)

# update light
lux = '未知'
if light == 0:
  lux = '黑'
elif light == 1:
  lux = '昏暗'
elif light == 2:
  lux = '正常'
elif light == 3:
  lux = '亮'
lux = urllib.quote(lux)
url = "http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx="+ LIGHT_IDX + "&svalue=" + lux
response = urllib2.urlopen(url)


# update noise
db = '未知'
if noise == 0:
  db = '寂静'
elif noise == 1:
  db = '正常'
elif noise == 2:
  db = '吵闹'
db = urllib.quote(db)

print noise
print db
url = "http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx="+ NOISE_IDX + "&nvalue=0&svalue=" + db
print url
response = urllib2.urlopen(url)
html=response.read()
print html

# update air_quality
air = '未知'
if air_quality == 0:
  air = '优'
elif air_quality == 1:
  air = '良'
elif air_quality == 2:
  air = '正常'
elif air_quality == 3:
  air = '差'
air = urllib.quote(air)
url = "http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx="+ AIR_IDX + "&svalue=" + air
response = urllib2.urlopen(url)




Re: 博联A1脚本

发表于 : 周三 5月 24, 2017 20:26
Admin
感谢分享 ;)

Re: 博联A1脚本

发表于 : 周六 5月 27, 2017 10:18
sxren1
感谢🙏分享

Re: 博联A1脚本

发表于 : 周一 5月 29, 2017 09:56
sxren1
楼主大神,能否出个教程,我等小白折腾不明白啊,非常感谢🙏

Re: 博联A1脚本

发表于 : 周三 5月 31, 2017 08:21
DT27
sxren1 写了: 周一 5月 29, 2017 09:56 楼主大神,能否出个教程,我等小白折腾不明白啊,非常感谢🙏
先看这篇Domoticz&BroadLink(博联)连接及控制教程:(一)安装python-broadlink

Re: 博联A1脚本

发表于 : 周三 5月 31, 2017 09:26
sxren1
DT27 写了: 周三 5月 31, 2017 08:21
sxren1 写了: 周一 5月 29, 2017 09:56 楼主大神,能否出个教程,我等小白折腾不明白啊,非常感谢🙏
先看这篇Domoticz&BroadLink(博联)连接及控制教程:(一)安装python-broadlink
这些都安装了,脚本里的哪些数据需要修改的,可以详细说一下吗🙏

Re: 博联A1脚本

发表于 : 周三 5月 31, 2017 09:30
DT27
sxren1 写了: 周三 5月 31, 2017 09:26
DT27 写了: 周三 5月 31, 2017 08:21
sxren1 写了: 周一 5月 29, 2017 09:56 楼主大神,能否出个教程,我等小白折腾不明白啊,非常感谢🙏
先看这篇Domoticz&BroadLink(博联)连接及控制教程:(一)安装python-broadlink
这些都安装了,脚本里的哪些数据需要修改的,可以详细说一下吗🙏

代码: 全选

device = broadlink.a1(host=("A1的IP地址",80), mac=bytearray.fromhex("A1的MAC地址"))
A1的ip跟mac

代码: 全选

domoticzserver   = "127.0.0.1:8084"
domoticzusername = ""
domoticzpassword = ""
AIR_IDX="25"
TEMP_IDX="18"
LIGHT_IDX="23"
NOISE_IDX="24"
HUMIDITY_IDX="19"
domoticz的端口号
空气、温度、光照、噪音、湿度各设备的idx

Re: 博联A1脚本

发表于 : 周三 5月 31, 2017 09:36
sxren1
DT27 写了: 周三 5月 31, 2017 09:30
sxren1 写了: 周三 5月 31, 2017 09:26
这些都安装了,脚本里的哪些数据需要修改的,可以详细说一下吗🙏

代码: 全选

device = broadlink.a1(host=("A1的IP地址",80), mac=bytearray.fromhex("A1的MAC地址"))
A1的ip跟mac

代码: 全选

domoticzserver   = "127.0.0.1:8084"
domoticzusername = ""
domoticzpassword = ""
AIR_IDX="25"
TEMP_IDX="18"
LIGHT_IDX="23"
NOISE_IDX="24"
HUMIDITY_IDX="19"
domoticz的端口号
空气、温度、光照、噪音、湿度各设备的idx
这个也需要改自己对应的吧

Re: 博联A1脚本

发表于 : 周三 5月 31, 2017 09:39
sxren1
楼主mac地址的格式是怎么样的,大小写有关系吗,中间是用冒号还是空格

Re: 博联A1脚本

发表于 : 周三 5月 31, 2017 11:08
DT27
sxren1 写了: 周三 5月 31, 2017 09:39 楼主mac地址的格式是怎么样的,大小写有关系吗,中间是用冒号还是空格
这里的mac地址格式

代码: 全选

b4 43 xx xx 39 ec
大小写随意。

Re: 博联A1脚本

发表于 : 周一 8月 21, 2017 20:32
sxren1
SyntaxError: Non-ASCII character '\xe4' in file A1.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
百度了一下是什么字符不对,大神帮忙看看吧

Re: 博联A1脚本

发表于 : 周一 8月 21, 2017 20:57
sxren1
sxren1 写了: 周一 8月 21, 2017 20:32 SyntaxError: Non-ASCII character '\xe4' in file A1.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
百度了一下是什么字符不对,大神帮忙看看吧
#!/usr/bin/python
# -*- encoding: utf-8 -*-

A1_IP = '192.168.0.8' # 修改为 BroadLink A1 IP
A1_MAC = 'b4:43:0d:c3:f9:ac' # 修改为 BroadLink A1 MAC 地址
DOMOTICZ_IP = '192.168.0.2' # 修改为 Domoticz 服务器 IP
DOMOTICZ_PORT = 8080 # 修改为 Domoticz 服务端口

DEV_HUM_TEMP_IDX = 54 # 修改为“温度+湿度”虚拟传感器Idx
DEV_NOISE_IDX = 56 # 修改为“声音”虚拟传感器Idx
DEV_LIGHT_IDX = 55 #修改为“光照”虚拟传感器Idx

import broadlink
import requests
import urllib

a1 = broadlink.a1((A1_IP, 80), A1_MAC)
a1.auth()
data = a1.check_sensors_raw()

hum = data['humidity']
hum_stat = 0
if 45 < = hum <= 60:
hum_stat = 1
elif hum < 40:
hum_stat = 2
elif hum > 70:
hum_stat = 3

# update temp and hum
url = "http://%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=0&svalue=%0.1f;%0.1f;%d" % (DOMOTICZ_IP, DOMOTICZ_PORT, DEV_HUM_TEMP_IDX, data['temperature'], hum, hum_stat)
requests.get(url)

# update noise
db = '未知'
noise = data['noise']
if noise == 0:
db = '寂静'
elif noise == 1:
db = '正常'
elif noise == 2:
db = '吵闹'
db = urllib.quote(db)
url = "http://%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=0&svalue=%s" % (DOMOTICZ_IP, DOMOTICZ_PORT, DEV_NOISE_IDX, db)
requests.get(url)

# update light
light = data['light']
lux = '未知'
if light == 0:
lux = '黑暗'
elif light == 1:
lux = '昏暗'
elif light == 2:
lux = '正常'
elif light == 3:
lux = '明亮'
lux = urllib.quote(lux)
url = "http://%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=0&svalue=%s" % (DOMOTICZ_IP, DOMOTICZ_PORT, DEV_LIGHT_IDX, lux)
requests.get(url)

请大神帮我看一下是怎么回事 ,谢谢了

Re: 博联A1脚本

发表于 : 周二 8月 22, 2017 08:43
DT27
sxren1 写了: 周一 8月 21, 2017 20:57
sxren1 写了: 周一 8月 21, 2017 20:32 SyntaxError: Non-ASCII character '\xe4' in file A1.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
百度了一下是什么字符不对,大神帮忙看看吧
#!/usr/bin/python
# -*- encoding: utf-8 -*-

A1_IP = '192.168.0.8' # 修改为 BroadLink A1 IP
A1_MAC = 'b4:43:0d:c3:f9:ac' # 修改为 BroadLink A1 MAC 地址
DOMOTICZ_IP = '192.168.0.2' # 修改为 Domoticz 服务器 IP
DOMOTICZ_PORT = 8080 # 修改为 Domoticz 服务端口

DEV_HUM_TEMP_IDX = 54 # 修改为“温度+湿度”虚拟传感器Idx
DEV_NOISE_IDX = 56 # 修改为“声音”虚拟传感器Idx
DEV_LIGHT_IDX = 55 #修改为“光照”虚拟传感器Idx

import broadlink
import requests
import urllib

a1 = broadlink.a1((A1_IP, 80), A1_MAC)
a1.auth()
data = a1.check_sensors_raw()

hum = data['humidity']
hum_stat = 0
if 45 < = hum <= 60:
hum_stat = 1
elif hum < 40:
hum_stat = 2
elif hum > 70:
hum_stat = 3

# update temp and hum
url = "http://%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=0&svalue=%0.1f;%0.1f;%d" % (DOMOTICZ_IP, DOMOTICZ_PORT, DEV_HUM_TEMP_IDX, data['temperature'], hum, hum_stat)
requests.get(url)

# update noise
db = '未知'
noise = data['noise']
if noise == 0:
db = '寂静'
elif noise == 1:
db = '正常'
elif noise == 2:
db = '吵闹'
db = urllib.quote(db)
url = "http://%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=0&svalue=%s" % (DOMOTICZ_IP, DOMOTICZ_PORT, DEV_NOISE_IDX, db)
requests.get(url)

# update light
light = data['light']
lux = '未知'
if light == 0:
lux = '黑暗'
elif light == 1:
lux = '昏暗'
elif light == 2:
lux = '正常'
elif light == 3:
lux = '明亮'
lux = urllib.quote(lux)
url = "http://%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=0&svalue=%s" % (DOMOTICZ_IP, DOMOTICZ_PORT, DEV_LIGHT_IDX, lux)
requests.get(url)

请大神帮我看一下是怎么回事 ,谢谢了
A1_MAC = 'b4:43:0d:c3:f9:ac' # 修改为 BroadLink A1 MAC 地址
冒号改成空格试试?

Re: 博联A1脚本

发表于 : 周六 11月 18, 2017 02:52
xjlgo
为什么都没有获取到状态呢

Re: 博联A1脚本

发表于 : 周六 11月 18, 2017 08:53
sxren1
xjlgo 写了: 周六 11月 18, 2017 02:52 为什么都没有获取到状态呢
我也没能成功,一直放着没弄了
你有没有出现错误什么的

Re: 博联A1脚本

发表于 : 周日 11月 19, 2017 00:22
xjlgo
做成py文件可以正常显示,但是不知道如何自动运行