用于与运动百叶窗接口的Python库
motionblinds的Python项目详细描述
活动百叶窗
用于与运动百叶窗接口的Python库
此库允许您从Coulisse B.V.控制运动百叶窗。 此库主要用于与HomeAssistant一起使用,但也可以单独使用。在
有关产品,请参见https://motion-blinds.com或https://coulisse.com/products/motion。在
出售这些百叶窗的商店:
安装
pip使用:
$ pip install motionblinds
或者
$ pip install --use-wheel motionblinds
检索密钥
motionblinds API使用一个16个字符的键,可以从Ios或Android的官方“Motion Blinds”应用程序中检索。 打开应用程序,点击右上角的3个点,进入“设置”,进入“关于运动应用程序”,请快速点击此“关于运动应用程序”页面5次,弹出窗口将弹出,为您提供按键。在
请注意,提供给此库时,密钥中需要包含“-”字符。 密钥需要与“12ab345c-d67e-8f”相同
使用
要创建设备,您可以使用以下代码行(使用正确的网关IP和从应用程序检索的密钥)
from motionblinds import MotionGateway
m = MotionGateway(ip = "192.168.1.100", key = "12ab345c-d67e-8f")
此库没有轮询。因此,您需要使用GetDeviceList方法填充已连接的盲板,并使用update方法更新设备信息。 请注意,可以处理来自网关的多播推送以检索即时状态更新(请参阅多播推送部分)
^{pr2}$注意,在使用Update之前需要运行GetDeviceList,因为设备类型、mac和令牌是使用GetDeviceList方法检索的。 使用GetDeviceList方法发现连接的百叶窗后,可以通过设备列表属性列出它们:
m.device_list
这将返回一个dict,其中键为盲人的mac_地址,值为可用于检索盲人信息和控制盲人的运动盲设备。在
一些示例代码将打印网关和所有连接的百叶窗的信息:
>>> from motionblinds import MotionGateway
>>> m = MotionGateway(ip = "192.168.1.100", key = "12ab345c-d67e-8f")
>>> m.GetDeviceList()
{'abcdefghujkl0001': <MotionBlind mac: abcdefghujkl0001, type: None, status: None, position: None %, angle: None, limit: None, battery: None, RSSI: None dBm>}
>>> m.Update()
>>> print(m)
<MotionGateway ip: 192.168.1.100, mac: abcdefghujkl, protocol: 0.9, N_devices: 1, status: Working, RSSI: -71 dBm>
>>> for blind in m.device_list.values():
>>> blind.Update()
>>> print(blind)
<MotionBlind mac: abcdefghujkl0001, type: RollerBlind, status: Stopped, position: 0 %, angle: 0, limit: Limits, battery: 1195, RSSI: -82 dBm>
要打开盲板,可以使用以下示例代码:
>>> from motionblinds import MotionGateway
>>> m = MotionGateway(ip = "192.168.1.100", key = "12ab345c-d67e-8f")
>>> m.GetDeviceList()
>>> m.Update()
>>> blind_1 = list(m.device_list.values())[0]
>>> blind_1.Update()
>>> blind_1.Open()
您还可以使用blind_1.Close()、blind_1.Stop()、blind_1.Set_位置(50)或blind_1.Set_angle(90)代替blind_1.Open()
多播推送
这个库允许在并行线程中监听来自网关的多播推送,并处理这些推送以获得网关和已连接盲板状态的即时更新。 要使用这种并行推送处理,需要初始化MotionMulticast类对象。 这个MotionMulticast.Start_侦听()和MotionMulticast.Stop_侦听()可用于启动和停止侦听传入推送的并行线程。 MotionMulticast类对象可以提供给MotionGateway类,让它更新该网关及其连接的盲板。 可以为网关设备和盲设备注册外部回调(见下表) 一个示例代码,用于监听推送30秒,并在推送进来时(当盲人完成移动时)打印出网关或盲板信息:
import time
from motionblinds import MotionMulticast, MotionGateway
def callback_func_gateway():
print(m)
def callback_func_blind():
for blind in m.device_list.values():
print(blind)
motion_multicast = MotionMulticast()
motion_multicast.Start_listen()
m = MotionGateway(ip="192.168.1.100", key="12ab345c-d67e-8f", multicast = motion_multicast)
m.GetDeviceList()
m.Update()
m.Register_callback("1", callback_func_gateway)
for blind in m.device_list.values():
blind.Register_callback("1", callback_func_blind)
time.sleep(30)
motion_multicast.Stop_listen()
发现
可以使用MotionDiscovery类在网络上发现运动网关。 下面的示例将尝试在10秒钟内发现网关,然后打印一个包含所发现的网关及其连接的百叶窗的dict。在
>>> from motionblinds import MotionDiscovery
>>> d = MotionDiscovery()
>>> motion_gateways = d.discover()
>>> print(motion_gateways)
{'192.168.1.100': {
'msgType': 'GetDeviceListAck',
'mac': 'abcdefghujkl',
'deviceType': '02000002',
'ProtocolVersion': '0.9',
'token': '12345A678B9CDEFG',
'data': [
{'mac': 'abcdefghujkl', 'deviceType': '02000002'},
{'mac': 'abcdefghujkl0001', 'deviceType': '10000000'},
{'mac': 'abcdefghujkl0002', 'deviceType': '10000000'}
]
}}
网关设备
网关设备(分配给变量“m”)具有以下方法和属性:
method | arguments | argument type | explanation |
---|---|---|---|
"m.GetDeviceList()" | - | - | Get the device list from the Motion Gateway and update the properties listed below |
"m.Update()" | - | - | Get the status of the Motion Gateway and update the properties listed below |
"m.Register_callback("1", func) | id, callback | string, function | Register a external callback function for updates of the gateway |
"m.Remove_callback("1") | id | string | Remove a external callback using its id |
"m.Clear_callbacks() | - | - | Remove all external registered callbacks for updates of the gateway |
盲板装置
盲设备(指定为变量“blind_1”)具有以下方法和属性:
method | arguments | argument type | explanation |
---|---|---|---|
"blind_1.Update_from_cache()" | - | - | Get the status of the blind from the cache of the Motion Gateway, No 433MHz radio communication with the blind takes place |
"blind_1.Update()" | - | - | Get the status of the blind from the blind through the Motion Gateway (WiFi) using 433MHz radio communication between the gateway and the blind |
"blind_1.Stop()" | - | - | Stop the motion of the blind |
"blind_1.Open()" | - | - | Open the blind/move the blind up |
"blind_1.Close()" | - | - | Close the blind/move the blind down |
"blind_1.Set_position(50)" | postion | int (0-100) | Set the position of the blind |
"blind_1.Set_angle(90)" | angle | int (0-180) | Set the angle/rotation of the blind |
"blind_1.Register_callback("1", func) | id, callback | string, function | Register a external callback function for updates of the blind |
"blind_1.Remove_callback("1") | id | string | Remove a external callback using its id |
"blind_1.Clear_callbacks() | - | - | Remove all external registered callbacks for updates of the blind |
property | value type | explanation |
---|---|---|
"blind_1.device_type" | string | Return the device type which is a 8 character number |
"blind_1.blind_type" | string | Return the type of the blind from BlindType enum |
"blind_1.type" | enum | Return the type of the blind as a BlindType enum |
"blind_1.mac" | string | Return the mac address of the blind |
"blind_1.available" | boolean | Return if the blind is available |
"blind_1.status" | string | Return the current status of the blind from BlindStatus enum |
"blind_1.limit_status" | string | Return the current status of the limit detection of the blind from LimitStatus enum |
"blind_1.position" | int | Return the current position of the blind in % (0-100) |
"blind_1.angle" | int | Return the current angle of the blind 0-180 |
"blind_1.battery_voltage" | double | Return the current battery voltage of the blind in V |
"blind_1.battery_level" | double | Return the current battery level of the blind in % |
"blind_1.RSSI" | int | Return the radio connection strength of the blind to the gateway in dBm |
自上而下自下而上(TDBU)设备
TDBU遮阳帘装置有两个电机,分别由“T”=顶部和“B”=底部来控制遮阳帘的两个部分。 使用“C”=组合作为电机,两个部件可以一起控制。 TDBU设备(被指定为变量“blind_1”)具有以下方法和特性:
method | arguments | argument type | explanation |
---|---|---|---|
"blind_1.Update()" | - | - | Get the status of the blind from the Motion Gateway |
"blind_1.Stop(motor = 'B')" | motor | 'B', 'T' or 'C' | Stop the motion of Bottom or Top motor of the blind |
"blind_1.Open(motor = 'B')" | motor | 'B', 'T' or 'C' | Move the Bottom or Top motor of the blind up |
"blind_1.Close(motor = 'B')" | motor | 'B', 'T' or 'C' | Move the Bottom or Top motor of the blind down |
"blind_1.Set_position(50, motor = 'B', width = 20)" | position, motor, width | int (0-100), 'B', 'T' or 'C', int (0-100) | Set the position of the Bottom or Top motor of the blind, optionaly specify width |
"blind_1.Set_scaled_position(50, motor = 'B')" | position, motor | int (0-100), 'B', 'T' or 'C' | Set the position of the motor of the blind within the alowed space in which it can move |
"blind_1.Set_angle(90, motor = 'B')" | angle, motor | int (0-180), 'B', 'T' or 'C' | Set the angle/rotation of the Bottom or Top motor of the blind |
"blind_1.Register_callback("1", func) | id, callback | string, function | Register a external callback function for updates of the blind |
"blind_1.Remove_callback("1") | id | string | Remove a external callback using its id |
"blind_1.Clear_callbacks() | - | - | Remove all external registered callbacks for updates of the blind |
property | value type | explanation |
---|---|---|
"blind_1.device_type" | string | Return the device type which is a 8 character number |
"blind_1.blind_type" | string | Return the type of the blind from BlindType enum |
"blind_1.type" | enum | Return the type of the blind as a BlindType enum |
"blind_1.mac" | string | Return the mac address of the blind |
"blind_1.available" | boolean | Return if the blind is available |
"blind_1.status" | {"T": string, "B": string} | Return the current status of the blind from BlindStatus enum |
"blind_1.limit_status" | {"T": string, "B": string} | Return the current status of the limit detection of the blind from LimitStatus enum |
"blind_1.position" | {"T": int, "B": int, "C": double} | Return the current position of the blind in % (0-100) |
"blind_1.scaled_position" | {"T": double, "B": double, "C": double} | Return the current position of the blind, scaled to the alowed space in which it can move, in % (0-100) |
"blind_1.width" | int | Return the area that is covered by the blind in % (0-100) |
"blind_1.angle" | {"T": int, "B": int} | Return the current angle of the blind 0-180 |
"blind_1.battery_voltage" | {"T": double, "B": double} | Return the current battery voltage of the blind in V |
"blind_1.battery_level" | {"T": double, "B": double} | Return the current battery level of the blind in % |
"blind_1.RSSI" | int | Return the radio connection strength of the blind to the gateway in dBm |
- 项目
标签: