Python Plugin: OpenAQ Topic is solved

Python and python framework

Moderator: leecollings

Xorfor

Python Plugin: OpenAQ

Post by Xorfor »

You want to monitor the air quality at your location?
This plugin uses the api provided by OpenAQ to retrieve data about the current air quality. It uses the location as specified in Domoticz. The plugin is available at:

https://github.com/waltervl/Domoticz-OpenAQ-Plugin
Edit Waltervl: I forked the not maintained plugin of Xorfor and am maintaining it.....

Please read the README.md and read the information on the OpenAQ website. Not all countries and/or areas in a country are supported. Also you will not always get a new measurements each hour.

I also had problems to use the standard Domoticz Connection (TLS errors), so I had to use 'curl'. So can not be used in Windows. Hopefully a standard solution in the future.

OpenAQ.PNG
OpenAQ.PNG (26 KiB) Viewed 4925 times
Slokoavac
Posts: 14
Joined: Monday 20 November 2017 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Balkans
Contact:

Re: Python Plugin: OpenAQ

Post by Slokoavac »

Hi Xorfor,

thanks for making this plugin. I have installed it (direct from github, made .py executable). When i add it in domoticz gui i get a lot of errors in log and all sensors show 0. Seems it can't parse properly parameters from Open AQ? I am using RPi 2, Stretch, stable domoticz v3.8153. Any ideas?

Code: Select all

2018-03-26 19:05:39.718 Error: PROXY: Read failed, code = 335544539. Reconnecting: short read
2018-03-26 19:05:47.403 Error: (CDevice_update) Sarajevo Open AQ - CO: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 19:05:47.403 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 19:05:47.406 Error: (CDevice_update) Sarajevo Open AQ - O3: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 19:05:47.406 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 19:05:47.408 Error: (CDevice_update) Sarajevo Open AQ - SO2: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 19:05:47.408 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 19:05:47.411 Error: (CDevice_update) Sarajevo Open AQ - PM10: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 19:05:47.411 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 19:05:47.413 Error: (CDevice_update) Sarajevo Open AQ - NO2: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 19:05:47.413 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 19:05:47.413 Error: (CDevice_update) Sarajevo Open AQ - Info: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 19:05:47.413 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'. 
when i turn on debug, i see this error i log:

Code: Select all

 2018-03-26 19:21:42.052 Error: (Sarajevo Open AQ) 'onHeartbeat' failed 'TypeError':'attribute of type 'NoneType' is not callable'.
2018-03-26 19:21:42.052 Error: (Sarajevo Open AQ) ----> Line 192 in /home/pi/domoticz/plugins/OAQ/plugin.py, function onHeartbeat
2018-03-26 19:21:42.052 Error: (Sarajevo Open AQ) ----> Line 129 in /home/pi/domoticz/plugins/OAQ/plugin.py, function onHeartbeat 
also i can see it has managed to pull one data from one of the stations in my city:

Code: Select all

 2018-03-26 19:21:42.052 (Sarajevo Open AQ) Locations found: 4
2018-03-26 19:21:42.052 (Sarajevo Open AQ) Location Bjelave - measurements: 5
2018-03-26 19:21:42.052 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... so2: 27 µg/m³ 
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Xorfor

Re: Python Plugin: OpenAQ

Post by Xorfor »

@Slokoavac:

The Domoticz version you are using, does not support the TimedOut parameter in the Python plugins.
You have 2 options:

1. Update to the latest beta version of Domoticz. If you are planning to use more plugins, this is the recommended option.

or

2. Change the OpenAQ plugin:
a. Open the plugin.py in an editor
b. Goto to line 212, the UpdateDevice procedure

Code: Select all

def UpdateDevice(Unit, nValue, sValue, TimedOut=0, AlwaysUpdate=False):
    # 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 or Devices[Unit].TimedOut != TimedOut or AlwaysUpdate:
            Devices[Unit].Update(nValue=nValue, sValue=str(sValue), TimedOut=TimedOut)
            Domoticz.Debug("Update " + Devices[Unit].Name + ": " + str(nValue) + " - '" + str(sValue) + "' - " + str(TimedOut))
c. Change this procedure to:

Code: Select all

def UpdateDevice(Unit, nValue, sValue, TimedOut=0, AlwaysUpdate=False):
    # 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 or AlwaysUpdate:
            Devices[Unit].Update(nValue=nValue, sValue=str(sValue))
            Domoticz.Debug("Update " + Devices[Unit].Name + ": " + str(nValue) + " - '" + str(sValue) + "' - " + str(TimedOut))
The changes are done by removing ' or Devices[Unit].TimedOut != TimedOut' is one line and ', TimedOut=TimedOut' in the next line.
Slokoavac
Posts: 14
Joined: Monday 20 November 2017 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Balkans
Contact:

Re: Python Plugin: OpenAQ

Post by Slokoavac »

Wow, that was fast response! ;)

I had some issues with other stuff i use on beta ver, that is why i am still on stable, but i might update again to beta and check are things better.

I have replaced code on line 212-217. this time there is much more info from stations, but still errors in parsing. I do not want to bug you anymore to fix this, i will update to beta over weekend. Thanks for help anyways!

Code: Select all

 2018-03-26 20:23:26.823 (Sarajevo Open AQ) Calling message handler 'onHeartbeat'.
2018-03-26 20:23:26.824 (Sarajevo Open AQ) onHeartbeat called
2018-03-26 20:23:27.337 (Sarajevo Open AQ) Locations found: 4
2018-03-26 20:23:27.337 (Sarajevo Open AQ) Location Bjelave - measurements: 5
2018-03-26 20:23:27.337 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... no2: 20 µg/m³
2018-03-26 20:23:27.384 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... o3: 89 µg/m³
2018-03-26 20:23:27.385 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... co: 597 µg/m³
2018-03-26 20:23:27.385 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... so2: 27 µg/m³
2018-03-26 20:23:27.386 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... pm10: 30 µg/m³
2018-03-26 20:23:27.386 (Sarajevo Open AQ) Location Vijećnica - measurements: 5
2018-03-26 20:23:27.386 (Sarajevo Open AQ) 2018-03-16T07:00:00.000Z ... no2: 25 µg/m³
2018-03-26 20:23:27.387 (Sarajevo Open AQ) 2018-03-16T07:00:00.000Z ... co: 240 µg/m³
2018-03-26 20:23:27.387 (Sarajevo Open AQ) 2017-02-13T13:00:00.000Z ... o3: 19 µg/m³
2018-03-26 20:23:27.387 (Sarajevo Open AQ) 2018-03-15T18:00:00.000Z ... so2: 2 µg/m³
2018-03-26 20:23:27.388 (Sarajevo Open AQ) 2018-03-16T07:00:00.000Z ... pm10: 9 µg/m³
2018-03-26 20:23:27.388 (Sarajevo Open AQ) Location Otoka - measurements: 5
2018-03-26 20:23:27.388 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... o3: 35 µg/m³
2018-03-26 20:23:27.389 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... so2: 21 µg/m³
2018-03-26 20:23:27.389 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... pm10: 17 µg/m³
2018-03-26 20:23:27.389 (Sarajevo Open AQ) 2016-11-27T11:00:00.000Z ... co: 267 µg/m³
2018-03-26 20:23:27.390 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... no2: 22 µg/m³
2018-03-26 20:23:27.390 (Sarajevo Open AQ) Location mobilna (Ilidža) - measurements: 5
2018-03-26 20:23:27.390 (Sarajevo Open AQ) 2016-11-27T11:00:00.000Z ... co: 316 µg/m³
2018-03-26 20:23:27.390 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... no2: 16 µg/m³
2018-03-26 20:23:27.391 (Sarajevo Open AQ) 2018-03-22T23:00:00.000Z ... pm10: 41 µg/m³
2018-03-26 20:23:27.391 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... o3: 42 µg/m³
2018-03-26 20:23:27.391 (Sarajevo Open AQ) 2018-03-23T00:00:00.000Z ... so2: 55 µg/m³
2018-03-26 20:23:27.392 (Sarajevo Open AQ - NO2) Updating device from 0:'' to have values 0:''.
2018-03-26 20:23:27.395 (Sarajevo Open AQ) Update options Sarajevo Open AQ - NO2: {'Custom': '0;µg/m³'}
2018-03-26 20:23:27.396 Error: (CDevice_update) Sarajevo Open AQ - NO2: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 20:23:27.396 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 20:23:27.396 (Sarajevo Open AQ) Update Sarajevo Open AQ - NO2: 20 - '20' - 0
2018-03-26 20:23:27.396 (Sarajevo Open AQ - CO) Updating device from 0:'' to have values 0:''.
2018-03-26 20:23:27.403 (Sarajevo Open AQ) Update options Sarajevo Open AQ - CO: {'Custom': '0;µg/m³'}
2018-03-26 20:23:27.404 Error: (CDevice_update) Sarajevo Open AQ - CO: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 20:23:27.405 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 20:23:27.405 (Sarajevo Open AQ) Update Sarajevo Open AQ - CO: 597 - '597' - 0
2018-03-26 20:23:27.405 (Sarajevo Open AQ - O3) Updating device from 0:'' to have values 0:''.
2018-03-26 20:23:27.410 (Sarajevo Open AQ) Update options Sarajevo Open AQ - O3: {'Custom': '0;µg/m³'}
2018-03-26 20:23:27.411 Error: (CDevice_update) Sarajevo Open AQ - O3: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 20:23:27.411 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 20:23:27.411 (Sarajevo Open AQ) Update Sarajevo Open AQ - O3: 89 - '89' - 0
2018-03-26 20:23:27.411 (Sarajevo Open AQ - PM10) Updating device from 0:'' to have values 0:''.
2018-03-26 20:23:27.415 (Sarajevo Open AQ) Update options Sarajevo Open AQ - PM10: {'Custom': '0;µg/m³'}
2018-03-26 20:23:27.415 Error: (CDevice_update) Sarajevo Open AQ - PM10: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 20:23:27.415 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 20:23:27.415 (Sarajevo Open AQ) Update Sarajevo Open AQ - PM10: 30 - '30' - 0
2018-03-26 20:23:27.415 (Sarajevo Open AQ - SO2) Updating device from 0:'' to have values 0:''.
2018-03-26 20:23:27.420 (Sarajevo Open AQ) Update options Sarajevo Open AQ - SO2: {'Custom': '0;µg/m³'}
2018-03-26 20:23:27.420 Error: (CDevice_update) Sarajevo Open AQ - SO2: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 20:23:27.420 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 20:23:27.420 (Sarajevo Open AQ) Update Sarajevo Open AQ - SO2: 27 - '27' - 0
2018-03-26 20:23:27.420 Error: (CDevice_update) Sarajevo Open AQ - Info: Failed to parse parameters: 'nValue', 'sValue', 'SignalLevel', 'BatteryLevel' or 'Options' expected.
2018-03-26 20:23:27.421 Error: (Sarajevo Open AQ) 'CDevice_update' failed 'TypeError':''TimedOut' is an invalid keyword argument for this function'.
2018-03-26 20:23:27.421 (Sarajevo Open AQ) Update Sarajevo Open AQ - Info: 0 - 'Number of stations: 4
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: OpenAQ

Post by FireWizard »

For a long period I have used this OpenAQ plugin, without any problem.
However, since approx 5 days the plugin stopped functioning.
The log gives:
2019-04-21 17:55:56.005 Error: (Air Quality) 'onHeartbeat' failed 'TypeError':'attribute of type 'NoneType' is not callable'.
2019-04-21 17:55:56.005 Error: (Air Quality) ----> Line 192 in '/home/pi/domoticz/plugins/Domoticz-OpenAQ-Plugin-master/plugin.py', function onHeartbeat
2019-04-21 17:55:56.006 Error: (Air Quality) ----> Line 129 in '/home/pi/domoticz/plugins/Domoticz-OpenAQ-Plugin-master/plugin.py', function onHeartbeat

Is there anyone, who has an idea what could be wrong or what could have been changed?

Thanks in advance.
Joep123
Posts: 56
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: OpenAQ

Post by Joep123 »

I get the same error (line 129 and 192).
Domoticz 4.10603 and Python 3.5.3
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: OpenAQ

Post by FireWizard »

I'm on the same versions. Domoticz 4.10603 on Raspbian Stretch with Python 3.5.3.
The plugin stopped on the same date (April 15, 2019) as I did the upgrade to 4.10603, so obviously the upgrade broke this plugin.
Xorfor

Re: Python Plugin: OpenAQ

Post by Xorfor »

Hmmm. I have the same Domoticz version, but don't get any errors. I will check the code and keep you informed.
Xorfor

Re: Python Plugin: OpenAQ

Post by Xorfor »

I have tested the plugin on an other Domoticz installation and still no errors. I have seen this message before in an other Python application. This one was related to https://bugs.python.org/issue27400.

@FireWizard and @Joep123
To be sure I like to know the the latitude and longitude you are using in the Domoticz settings. Can you send me these settings?
Please send them by a private message!
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: OpenAQ

Post by FireWizard »

@xorfor
This could very well be the cause of the problem.
After a reboot of the pi I see that the plugin works one time and updates the outputs.
The second time I get the failure as described above.
You will get my lat/lon co-ordinates.

Regards
Xorfor

Re: Python Plugin: OpenAQ

Post by Xorfor »

I have tested with the other locations, but was not able to reproduce this problem. I implemented the bug fix, hopefully this solves the problem. New version is available on https://github.com/Xorfor/Domoticz-OpenAQ-Plugin.

Please let me know the results.
Joep123
Posts: 56
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: OpenAQ

Post by Joep123 »

Xorfor wrote: Tuesday 23 April 2019 20:10 Please let me know the results.
The new version works perfect!
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: OpenAQ

Post by FireWizard »

Thanks for creating a bugfix.
I will test later this week, as I'm travelling at this moment.
Regards.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: OpenAQ

Post by FireWizard »

I have installed the updated plugin and I can confirm that it works with the latest, currently v 4.10619, beta release.
Thanks for the work done.

Regards
psyduck
Posts: 1
Joined: Sunday 07 July 2019 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: OpenAQ

Post by psyduck »

I got it working now.
Do I need to make a cron to run it by a time table?

regards.
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Python Plugin: OpenAQ

Post by Jan Jansen »

raspberry running latest stable
Xorfor wrote: Wednesday 07 February 2018 21:27 You want to monitor the air quality at your location?
@Xorfor,
Today I installed the plugin. The devices appear as expected. After a while I noticed that the devices are updated every minute. Is that normal behavior?

Thanks in advance for your reply.

PS
Xorfor

Re: Python Plugin: OpenAQ

Post by Xorfor »

Yes. the devices are updated every minute. Checking the code, I realize that my original idea was to check every hour, but I never implemented this for testing reasons :) .
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Python Plugin: OpenAQ

Post by Jan Jansen »

Xorfor wrote: Wednesday 26 August 2020 18:54 Yes. the devices are updated every minute. Checking the code, I realize that my original idea was to check every hour, but I never implemented this for testing reasons :) .
@ Xorfor,

Thank you for your quick reply. It's a very nice script but an update of the devices once a hour seems more than enough to me. I am not familiar with python plugins and I am not much of a coder. Are you planning to modify the plugin or can you direct me to do it myself? (I know how to open the plugin)

Thanks in advance
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: OpenAQ

Post by FireWizard »

@Jan Jansen, @Xorfor

Hi all,

I use this plugin as well, and mine does not run once every minute, but once every hour.
That is okay for me.

If you go to github https://github.com/Xorfor/Domoticz-Open ... /plugin.py and you open the file plugin.py, you will find at line 33:
__MINUTES = 60 # 1 hour or use a parameter
I believe it has been implemented.

Or am I wrong?

Regards
Last edited by FireWizard on Monday 24 January 2022 16:11, edited 1 time in total.
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Python Plugin: OpenAQ

Post by Jan Jansen »

@FireWizard and Xorfor,

When I opened the program this morning I also saw that line. I initially thought that the update was every hour. But in practice there is an update every minute. That's why I was amazed and asked for a response / help.
Today I installed the plugin on an rpi 2B (latest stable). Yesterday I installed the plugin on a rpi 3B (latest beta). Same behavior in both cases (once a minute).
I've tried with and without the plugin manager.

Regards
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest