请问一下你怎么调试的啊,我在硬件里面看不到,我也是用群晖套件安装domoticz的,版本是3.8005,你是把DT27-AQI文件夹(里面只有plugin.py一个文件)放在/var/packages/domoticz/plugins里面么?重启后就可以看到硬件了么?
[Domoticz插件]空气指数AQI插件 2017年7月4日更新 修复报错
Re: [Domoticz插件]空气指数AQI插件
Re: [Domoticz插件]空气指数AQI插件
我是放在 domoticz/plugins/DT27-AQI/ 目录下面的。
pi@raspberrypi:/python_pi/domoticz/plugins/DT27-AQI $ tree
.
├── plugin.py
├── __pycache__ [error opening dir]
└── rpdb
├── __init__.py
└── __pycache__
└── __init__.cpython-34.pyc
3 directories, 3 files
Re: [Domoticz插件]空气指数AQI插件 2017年7月4日更新 修复报错
在网上做个备份
代码: 全选
#sic Python Plugin Example
#
# Author: GizMoCuz
#
"""
<plugin key="DT27-AQI" name="DT27-AQI" author="Zack" version="1.0.0" externallink="http://www.pm25.com/">
<params>
<param field="Address" label="城市" width="80px" required="true" default="上海"/>
<param field="Mode1" label="监测点" width="120px" required="true" default="浦东张江"/>
<param field="Mode2" label="API标准" width="100px">
<options>
<option label="中国标准" value="中国标准"/>
<option label="美国标准" value="美国标准" default="中国标准" />
</options>
</param>
<param field="Mode3" label="更新频率(分钟)" width="30px" required="true" default="60"/>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="True" value="Debug"/>
<option label="False" value="Normal" default="False" />
</options>
</param>
</params>
</plugin>
"""
import Domoticz
import urllib.parse
import urllib.request
import re
import time
import sys
sys.path.append('/usr/local/lib/python3.4/dist-packages')
class plugin:
def __init__(self):
self.AQI_URI = "http://www.pm25.com/city/mon/aqi/{}/{}.html"
self.PM25_URI = "http://www.pm25.com/city/mon/pm2_5/{}/{}.html"
self.PM10_URI = "http://www.pm25.com/city/mon/pm10/{}/{}.html"
self.SO2_URI = "http://www.pm25.com/city/mon/so2/{}/{}.html"
self.NO2_URI = "http://www.pm25.com/city/mon/no2/{}/{}.html"
self.CO_URI = "http://www.pm25.com/city/mon/co/{}/{}.html"
self.O3_URI = "http://www.pm25.com/city/mon/o3/{}/{}.html"
return
def onStart(self):
if Parameters["Mode6"] == "Debug":
Domoticz.Debugging(1)
Domoticz.Debug("Debugger started, use 'telnet 0.0.0.0 4444' to c onnect")
import rpdb
rpdb.set_trace()
Domoticz.Debug("Debugger start failed, Please Check the [rpdb] m odel")
self.repeatTime = int(Parameters["Mode3"])
if ( 1 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "空气指数", Unit=1, TypeName="Custom", Options={"Custom":"1;AQI"}, Used=1).Create()
if ( 2 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "PM2.5浓度", Unit=2, TypeName="Custom", Options={"Custom":"1;μg/m³"}, Used=1).Create()
if ( 3 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "PM10浓度", Unit=3, TypeName="Custom", Options={"Custom":"1;μg/m³"}, Used=1).Create()
if ( 4 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "SO2浓度", Unit=4, TypeName="Custom", Options={"Custom":"1;μg/m³"}, Used=1).Create()
if ( 5 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "NO2浓度", Unit=5, TypeName="Custom", Options={"Custom":"1;μg/m³"}, Used=1).Create()
if ( 6 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "CO浓度", Unit=6, TypeName="Custom", Options={"Custom":"1;μg/m³"}, Used=1).Create()
if ( 7 not in Devices):
Domoticz.Device(Name=Parameters["Address"] + "O3浓度", Unit=7, TypeName="Custom", Options={"Custom":"1;μg/m³"}, Used=1).Create()
Domoticz.Heartbeat(60)
def onStop(self):
Domoticz.Log("onStop called")
def onConnect(self, Connection, Status, Description):
Domoticz.Log("onConnect called")
def onMessage(self, Connection, Data, Status, Extra):
Domoticz.Log("onMessage called")
def onCommand(self, Unit, Command, Level, Hue):
Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile):
Domoticz.Log("Notification: " + Name + "," + Subject + "," + Text + "," + Status + "," + str(Priority) + "," + Sound + "," + ImageFile)
def onDisconnect(self, Connection):
Domoticz.Log("onDisconnect called")
def onHeartbeat(self):
if int(time.time()/60)%self.repeatTime==0:
Domoticz.Log("onHeartbeat called")
aqi = self.getAirQuality(self.AQI_URI)
if aqi != '':
self.UpdateDevice(1,0,aqi)
pm25 = self.getAirQuality(self.PM25_URI)
if pm25 != '':
self.UpdateDevice(2,0,pm25)
pm10 = self.getAirQuality(self.PM10_URI)
if pm10 != '':
self.UpdateDevice(3,0,pm10)
so2 = self.getAirQuality(self.SO2_URI)
if so2 != '':
self.UpdateDevice(4,0,so2)
no2 = self.getAirQuality(self.NO2_URI)
if no2 != '':
self.UpdateDevice(5,0,no2)
co = self.getAirQuality(self.CO_URI)
if co != '':
self.UpdateDevice(6,0,co)
o3 = self.getAirQuality(self.O3_URI)
if o2 != '':
self.UpdateDevice(7,0,o3)
# Update Device into DB
def UpdateDevice(self, Unit, nValue, sValue):
# Make sure that the Domoticz device still exists (they can be deleted) before updating it
if (Unit in Devices):
if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue):
Devices[Unit].Update(nValue=nValue, sValue=str(sValue))
Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
def getAirQuality(self,url):
try:
num=0
if 'pm25.com/city/mon/aqi/' in url:
if Parameters["Mode2"] == "中国标准":
num=1
else:
num=0
url = urllib.parse.quote_plus(url.format(Parameters["Address"], Parameters["Mode1"]),safe='http://')
results=urllib.request.urlopen(url,timeout=5).read().decode('utf-8')
data = re.findall(r"data:\[([\d+,]+)\]", results)
data = data[num]
l24 = data.split(',')
# airquality=self.onlyNum(l24[23],oth='')
if l24:
airquality=l24[-1]
# else:
# airquality=0
return airquality
except BaseException:
return ''
global _plugin
_plugin = plugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onConnect(Connection, Status, Description):
global _plugin
_plugin.onConnect(Connection, Status, Description)
def onMessage(Connection, Data, Status, Extra):
global _plugin
_plugin.onMessage(Connection, Data, Status, Extra)
def onCommand(Unit, Command, Level, Hue):
global _plugin
_plugin.onCommand(Unit, Command, Level, Hue)
def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
global _plugin
_plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)
def onDisconnect(Connection):
global _plugin
_plugin.onDisconnect(Connection)
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()
# Generic helper functions
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
return
Re: [Domoticz插件]空气指数AQI插件 2017年7月4日更新 修复报错
不能用,最新版的Domoticz配置上后都启动不了了。