Domoticz 插件开发教程

虽然domoticz官网提供了一个插件开发教程,但是在实际的开发过程中就会发现有很多内容写的不够详细,无法参考。 官网教程链接: https://en.domoticz.cn/wiki/Developing_a_Python_plugin 国内的中文wiki页面比较陈旧,文档也不是最新的,不建议参考。

其实真个插件主要分为两个部分:

  • 插件模板

  • 插件代码

插件模板主要就是插件的定义,以及相关的参数配置选项,格式为xml:


    
        

Baby Weather Plugin


支持从国内的天气服务器获取天气信息

Features

  • 支持和风天气
  • 支持彩云天气
  • 支持今天明天的天气预报信息

Devices

  • Temperature - 当前温度
  • Feeling Temperature - 当前体感温度
  • Humidity - 湿度
  • Pressure - 气压

Configuration

API KEY请自行注册相关的开发者账号,然后获取key。 技术支持:http://www.h4ck.org.cn 彩云天气:https://open.caiyunapp.com/ 和风天气:https://dev.heweather.com/


这里面的定义需要注意的是参数的名称并不能自己随意定义, 仅能使用如下的参数名称:

  • SerialPort – used by ‘serial’ transports
  • Address – used by non-serial transports
  • Port – used by non-serial transports
  • Mode1 – General purpose
  • Mode2 – General purpose
  • Mode3 – General purpose
  • Mode4 – General purpose
  • Mode5 – General purpose
  • Mode6 – General purpose
  • Username – Username for authentication
  • Password – Password for authentication

例如 <param field=”Mode3″ label=”经度” width=”600px” required=”true” default=”116.40″/>修改为 <param field=”GpsLong” label=”经度” width=”600px” required=”true” default=”116.40″/> 然后就挂了,提示找不到属性。
除此之外,定义部分其他的内容文档里写的都比较清楚了。在代码中取参数的数值通过Mode3获取。
在代码部分,需要注意的是Update函数:

 Devices[Unit].Update(nValue=nValue, sValue=str(sValue), SignalLevel=5, Image=8)

对于部分Device的sValue参数文档中给出了说明,要传递的数值: Wind sensor (sValue: “<WindDirDegrees>;<WindDirText>;<WindAveMeterPerSecond10>;<WindGustMeterPerSecond10>;<Temp_c>;<WindChill_c>”) 但是这个文档的数值并不是全部的内容:

Filling is in progress, table doesn’t contain full available list yet

https://github.com/Xorfor/Domoticz-API/wiki/Device 这个页面提供了更详细的说明,在更新sValue的时候需要注意要传的并不是一个字符串,而是多个;分隔的字符串。

Device/Sensor nvalue svalue Example
Alert sensor LEVEL TEXT  
Barometer BAR BAR_FOR dev.update(1020, “3”)
Counter   COUNTER  
Custom sensor 0 VALUE  
Distance 0 DISTANCE  
Electricity (instant and counter) 0 POWER;ENERGY  
Electricity Current/Ampere 3 Phase 0 AMPERE1;AMPERE2;AMPERE3  
Electricity P1 smart meter 0 USAGE1;USAGE2;RETURN1;RETURN2;CONS;PROD  
Gas 0 USAGE  
Humidity HUM HUM_STAT dev.update(45, “2”)
Lux   LUX  
Moisture (Soil) MOISTURE    
Percentage 0 PERCENTAGE  
Pressure 0 BAR  
Rain 0 RAINRATE;RAINCOUNTER  
Temperature 0 TEMP dev.update(0, “20.3″)
Temperature/humidity 0 TEMP;HUM;HUM_STAT  
Temperature/humidity/barometer 0 TEMP;HUM;HUM_STAT;BAR;BAR_FOR  
Temperature/barometer 0 TEMP;BAR;BAR_FOR;ALTITUDE  
Text 0 TEXT  
UV 0 UV;TEMP  
Visibility 0 VISIBILITY  
Voltage 0 VOLTAGE  
Wind 0 BEARING;DIRECTION;WS;WG;TEMP;CHILL  

在线xls 转markdown :https://tableconvert.com

例如更新wind Device需要更新如下参数:

if wind_speed and wind_direction:
            self.update_device_value(8, 0, str(wind_direction)
                                     + ";" + self.getWindDirection(wind_direction)
                                     + ";" + str(round(float(wind_speed) * 10))
                                     + ";" + str(round(float(wind_speed) * 10))
                                     + ";0;0")

<

p class=”md-end-block md-p md-focus”>参考链接: https://github.com/Xorfor/Domoticz-API/wiki/Device#examples https://en.domoticz.cn/wiki/Developing_a_Python_plugin

☆版权☆

* 网站名称:obaby@mars
* 网址:https://h4ck.org.cn/
* 个性:https://oba.by/
* 本文标题: 《Domoticz 插件开发教程》
* 本文链接:https://h4ck.org.cn/2020/06/7238
* 短链接:https://oba.by/?p=7238
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


猜你喜欢:

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注