[Domoticz插件]空气指数AQI插件 2017年7月4日更新 修复报错

skycastle
帖子: 1
注册时间: 周五 7月 14, 2017 00:38

Re: [Domoticz插件]空气指数AQI插件

帖子 skycastle »

binai 写了: 周三 6月 28, 2017 20:46 插件怎么调试啊,有简单的介绍说明吗?
请问一下你怎么调试的啊,我在硬件里面看不到,我也是用群晖套件安装domoticz的,版本是3.8005,你是把DT27-AQI文件夹(里面只有plugin.py一个文件)放在/var/packages/domoticz/plugins里面么?重启后就可以看到硬件了么?
kqwkn
帖子: 5
注册时间: 周一 7月 10, 2017 15:03

Re: [Domoticz插件]空气指数AQI插件

帖子 kqwkn »

Zackr 写了: 周一 6月 05, 2017 17:07
pizixiaotian 写了: 周一 6月 05, 2017 00:07 我也是群晖安装的Domoticz套件,我插件上传了后,重启Domoticz,为什么看不到插件啊。
有可能是你的Domoticz版本过高了,降到3.75x版本再试一下。 新版本针对插件部分做了修改导致之前的插件都无法兼容。
群晖的DOCKER呀,是不是跟PI的不一样,大神上面说的是不是以PI的标准来说的,群晖上装的DOCKER确实找不到所说的路径,本人小白,还望指教!
kqwkn
帖子: 5
注册时间: 周一 7月 10, 2017 15:03

Re: [Domoticz插件]空气指数AQI插件

帖子 kqwkn »

liuyr 写了: 周日 6月 04, 2017 11:33 谢谢Zackr楼主,在群晖root目录下通过查找功能都没有找到这个文件夹。
兄弟搞定了没有,大神说的地址我估计是树莓派DOCKER的地址,群晖的我也是没有找到
binai
帖子: 22
注册时间: 周一 6月 26, 2017 14:59

Re: [Domoticz插件]空气指数AQI插件

帖子 binai »

skycastle 写了: 周五 7月 14, 2017 00:42
binai 写了: 周三 6月 28, 2017 20:46 插件怎么调试啊,有简单的介绍说明吗?
请问一下你怎么调试的啊,我在硬件里面看不到,我也是用群晖套件安装domoticz的,版本是3.8005,你是把DT27-AQI文件夹(里面只有plugin.py一个文件)放在/var/packages/domoticz/plugins里面么?重启后就可以看到硬件了么?

我是放在 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
binai
帖子: 22
注册时间: 周一 6月 26, 2017 14:59

Re: [Domoticz插件]空气指数AQI插件 2017年7月4日更新 修复报错

帖子 binai »

在网上做个备份

代码: 全选

#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

xjlgo
帖子: 6
注册时间: 周五 7月 07, 2017 14:22

Re: [Domoticz插件]空气指数AQI插件

帖子 xjlgo »

Zackr 写了: 周六 6月 03, 2017 23:23
liuyr 写了: 周六 6月 03, 2017 17:33 楼主,我是群晖docker版本的domoticz,现在找不到domoticz/plugins/这个文件夹,你知道群晖docker版本的domoticz的domoticz/plugins/这个文件夹在群晖的什么位置吗,这个插件应该安装在群晖的什么地方。盼告诉知晓。


docker版在/src/domoticz/plugins/
套件中心的目录是/volume1/@appstore/domoticz/var/plugins 我也找了好久
lixy
帖子: 2
注册时间: 周四 1月 11, 2018 09:35

Re: [Domoticz插件]空气指数AQI插件 2017年7月4日更新 修复报错

帖子 lixy »

不能用,最新版的Domoticz配置上后都启动不了了。
回复