Code Monkey home page Code Monkey logo

prometheus-dyson's People

Contributors

dependabot[bot] avatar hvtuananh avatar nickrw avatar oggust avatar seanrees avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

prometheus-dyson's Issues

Feature Request: If possible add the Air Quality Index (AQI) metric

Not sure if this is a request for here, or maybe the libpurecool maintainers as well. The native dyson app displays the Air Quality Index alongside the other metrics (Not sure if this existed on V1 devices as well). Would be great to be able to bring that in as well, ideally as a metric, or at least as the qualitative value (Good, Fair, Poor, Very Poor, Extremely Poor, Severe). Screengrabs below:

2021-01-09 17-51-15-1

2021-01-09 17-54-18-1

Found device but is not active

I'm seeing this in the log file when I try to run this:

Found device "Living room" (serial=XXX-AU-XXXXXXXX) but is not active; skipping

Model is a Dyson Pure Heat + Cool. It's turned on and working. Discoverable and controllable via the mobile app.

My credentials are linked in the config.ini, when I leave them out or have them incorrect the service fails to start (as expected)

When browsing the prometheus metrics for this service, I see metrics only for the prometheus process eg. python_gc_objects_collected_total{generation="0"} 705.0 but none for the dyson metrics:

# HELP dyson_humidity_percent Relative humidity (percentage)
# TYPE dyson_humidity_percent gauge
# HELP dyson_temperature_celsius Ambient temperature (celsius)
# TYPE dyson_temperature_celsius gauge
# HELP dyson_volatile_organic_compounds_units Level of Volatile organic compounds
# TYPE dyson_volatile_organic_compounds_units gauge
# HELP dyson_dust_units Level of Dust
# TYPE dyson_dust_units gauge
# HELP dyson_fan_mode Current mode of the fan
# TYPE dyson_fan_mode gauge
# HELP dyson_fan_state Current running state of the fan
# TYPE dyson_fan_state gauge
# HELP dyson_fan_speed_units Current speed of fan (-1 = AUTO)
# TYPE dyson_fan_speed_units gauge
# HELP dyson_oscillation_mode Current oscillation mode
# TYPE dyson_oscillation_mode gauge
# HELP dyson_focus_mode Current focus mode
# TYPE dyson_focus_mode gauge
# HELP dyson_heat_mode Current heat mode
# TYPE dyson_heat_mode gauge
# HELP dyson_heat_state Current heat state
# TYPE dyson_heat_state gauge
# HELP dyson_heat_target_celsius Heat target temperature (celsius)
# TYPE dyson_heat_target_celsius gauge
# HELP dyson_quality_target_units Quality target for fan
# TYPE dyson_quality_target_units gauge
# HELP dyson_filter_life_seconds Remaining filter life (seconds)
# TYPE dyson_filter_life_seconds gauge

Am I missing a step in the setup?

config_builder SSL issues with dyson API

Hi There,

This is a heads-up, I don't believe the issue I'm facing is your code, but thought I'd report it.

When running the config builder I currently get errors relating to ssl validation failures.

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)

However, this is because dyson has incorrectly applied their certificate which can be verified with curl and openssl:

~$ curl https://appapi.cp.dyson.com
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
~$ openssl s_client -servername appapi.cp.dyson.com -connect appapi.cp.dyson.com:443
CONNECTED(00000003)
depth=0 C = GB, L = Malmesbury, O = Dyson Limited, CN = *.dyson.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = GB, L = Malmesbury, O = Dyson Limited, CN = *.dyson.com
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
 0 s:C = GB, L = Malmesbury, O = Dyson Limited, CN = *.dyson.com
   i:C = US, O = DigiCert Inc, CN = DigiCert TLS RSA SHA256 2020 CA1
---

This can be further validated using ssllabs which reports the same:
image

ValueError: 'IDLE' is not in list

Me Again :-)

Noticed an issue that present at a repeatable time of day, relating to the schedule feature of the V2 device.

Error:

Jan 11 08:00:11 ubuntuvm python3[1096]: Exception in thread Thread-2:
Jan 11 08:00:11 ubuntuvm python3[1096]: Traceback (most recent call last):
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.run()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/lib/python3.8/threading.py", line 870, in run
Jan 11 08:00:11 ubuntuvm python3[1096]:     self._target(*self._args, **self._kwargs)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.loop_forever(retry_first_connection=True)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self.loop(timeout, max_packets)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1181, in loop
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self.loop_read(max_packets)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self._packet_read()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self._packet_handle()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
Jan 11 08:00:11 ubuntuvm python3[1096]:     return self._handle_publish()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
Jan 11 08:00:11 ubuntuvm python3[1096]:     self._handle_on_message(message)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3444, in _handle_on_message
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.on_message(self, self._userdata, message)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/libpurecool/dyson_pure_cool_link.py", line 100, in on_message
Jan 11 08:00:11 ubuntuvm python3[1096]:     function(device_msg)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/opt/prometheus-dyson/bin/main.py", line 125, in update
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.updateFanStateV2(name, serial, message)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/opt/prometheus-dyson/bin/main.py", line 205, in updateFanStateV2
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.oscillation.labels(name=name, serial=serial).state(message.oscillation_status)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/prometheus_client/metrics.py", line 661, in state
Jan 11 08:00:11 ubuntuvm python3[1096]:     self._value = self._states.index(state)
Jan 11 08:00:11 ubuntuvm python3[1096]: ValueError: 'IDLE' is not in list

AttributeError: 'DysonPureHotCoolV2State' object has no attribute 'fan_mode'

Hey there, seeing a new crash from time to time in my logs:

Main error appears:

AttributeError: 'DysonPureHotCoolV2State' object has no attribute 'fan_mode'

Jan 26 13:21:36 nuc systemd[1]: Started Prometheus metrics exporter for Dyson Hot+Cool fans.
Jan 26 13:21:37 nuc python3[131116]: 2021/01/26 13:21:37       INFO Starting up on port=8091
Jan 26 13:21:37 nuc python3[131116]: 2021/01/26 13:21:37       INFO Including devices marked "inactive" from the Dyson API
Jan 26 13:21:37 nuc python3[131116]: 2021/01/26 13:21:37       INFO Reading "/etc/prometheus-dyson/config.ini"
Jan 26 13:21:39 nuc python3[131116]: 2021/01/26 13:21:39       INFO Attempting to discover device "Living room" (serial=A1F-AU-MKA1196A) via zeroconf
Jan 26 13:21:40 nuc python3[131116]: 2021/01/26 13:21:40       INFO Monitoring "Living room" (serial=A1F-AU-MKA1196A)
Jan 26 15:21:49 nuc python3[131116]: Exception in thread Thread-2:
Jan 26 15:21:49 nuc python3[131116]: Traceback (most recent call last):
Jan 26 15:21:49 nuc python3[131116]:   File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Jan 26 15:21:49 nuc python3[131116]:     self.run()
Jan 26 15:21:49 nuc python3[131116]:   File "/usr/lib/python3.8/threading.py", line 870, in run
Jan 26 15:21:49 nuc python3[131116]:     self._target(*self._args, **self._kwargs)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 3452, in _thread_main
Jan 26 15:21:49 nuc python3[131116]:     self.loop_forever(retry_first_connection=True)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 1779, in loop_forever
Jan 26 15:21:49 nuc python3[131116]:     rc = self.loop(timeout, max_packets)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 1181, in loop
Jan 26 15:21:49 nuc python3[131116]:     rc = self.loop_read(max_packets)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 1572, in loop_read
Jan 26 15:21:49 nuc python3[131116]:     rc = self._packet_read()
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 2310, in _packet_read
Jan 26 15:21:49 nuc python3[131116]:     rc = self._packet_handle()
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 2936, in _packet_handle
Jan 26 15:21:49 nuc python3[131116]:     return self._handle_publish()
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 3216, in _handle_publish
Jan 26 15:21:49 nuc python3[131116]:     self._handle_on_message(message)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__paho_mqtt_1_5_1/paho/mqtt/client.py", line 3444, in _handle_on_message
Jan 26 15:21:49 nuc python3[131116]:     self.on_message(self, self._userdata, message)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/pip_deps_pypi__libpurecool_0_6_4/libpurecool/dyson_pure_cool_link.py", line 100, in on_message
Jan 26 15:21:49 nuc python3[131116]:     function(device_msg)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/__main__/metrics.py", line 142, in update
Jan 26 15:21:49 nuc python3[131116]:     self.updatePureCoolV2State(name, serial, message)
Jan 26 15:21:49 nuc python3[131116]:   File "/tmp/Bazel.runfiles_d946inax/runfiles/__main__/metrics.py", line 285, in updatePureCoolV2State
Jan 26 15:21:49 nuc python3[131116]:     name, serial, message.fan_mode, fan_mode)
Jan 26 15:21:49 nuc python3[131116]: AttributeError: 'DysonPureHotCoolV2State' object has no attribute 'fan_mode'

AttributeError: 'NoneType' object has no attribute 'publish'

Hello and thanks for this project!

I ran into an issue the other night:

[aug@ogg prometheus-dyson]./main.py  --config=aug-config
2022/02/20 18:56:51 [139731927258944]       INFO Starting up on port=8091
2022/02/20 18:56:51 [139731927258944]       INFO Reading "aug-config"
2022/02/20 18:56:51 [139731927258944]       INFO Starting discovery...
2022/02/20 18:56:51 [139731927258944]       INFO Attempting to discover device "Kitchen" (serial=VS9-EU-NBK1300A) via zeroconf
2022/02/20 18:56:51 [139731927258944]       INFO Attempting to discover device "Bedroom" (serial=VS9-EU-MHA5873A) via zeroconf
2022/02/20 18:56:52 [139731775612480]       INFO Discovered VS9-EU-NBK1300A on 192.168.1.240
2022/02/20 18:56:53 [139731775612480]       INFO Connected to device VS9-EU-NBK1300A
2022/02/23 21:07:00 [139731767219776]       INFO Device VS9-EU-NBK1300A is now disconnected, clearing it and re-adding
2022/02/23 21:07:00 [139731767219776]       INFO Attempting to discover device "Kitchen" (serial=VS9-EU-NBK1300A) via zeroconf
2022/02/23 21:07:00 [139731767219776]       INFO Discovered VS9-EU-NBK1300A on 192.168.1.240
2022/02/23 21:07:00 [139731767219776]       INFO Connected to device VS9-EU-NBK1300A
2022/02/23 21:07:00 [139731767219776]       INFO Device VS9-EU-NBK1300A is now disconnected, clearing it and re-adding
2022/02/23 21:07:00 [139731750434368]       INFO Device VS9-EU-NBK1300A is now disconnected, clearing it and re-adding
2022/02/23 21:07:00 [139731750434368]       INFO Attempting to discover device "Kitchen" (serial=VS9-EU-NBK1300A) via zeroconf
2022/02/23 21:07:00 [139731750434368]       INFO Discovered VS9-EU-NBK1300A on 192.168.1.240
2022/02/23 21:07:01 [139731750434368]       INFO Connected to device VS9-EU-NBK1300A
2022/02/23 21:07:01 [139731767219776]       INFO Attempting to discover device "Kitchen" (serial=VS9-EU-NBK1300A) via zeroconf
2022/02/23 21:07:01 [139731767219776]       INFO Discovered VS9-EU-NBK1300A on 192.168.1.240
2022/02/23 21:07:01 [139731767219776]       INFO Already connected to 192.168.1.240 (VS9-EU-NBK1300A); no need to reconnect.
Exception in thread Thread-26704:
Traceback (most recent call last):
  File "/usr/lib64/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.10/threading.py", line 1371, in run
    self.function(*self.args, **self.kwargs)
  File "/home/aug/src/prometheus-dyson/./main.py", line 88, in _timer_callback
    self.libdyson.request_environmental_data()
  File "/home/aug/.local/lib/python3.10/site-packages/libdyson/dyson_device.py", line 339, in request_environmental_data
    self._mqtt_client.publish(self._command_topic, json.dumps(payload))
AttributeError: 'NoneType' object has no attribute 'publish'
Exception in thread Thread-26708:
Traceback (most recent call last):
  File "/usr/lib64/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.10/threading.py", line 1371, in run
    self.function(*self.args, **self.kwargs)
  File "/home/aug/src/prometheus-dyson/./main.py", line 88, in _timer_callback
    self.libdyson.request_environmental_data()
  File "/home/aug/.local/lib/python3.10/site-packages/libdyson/dyson_device.py", line 339, in request_environmental_data
    self._mqtt_client.publish(self._command_topic, json.dumps(payload))
AttributeError: 'NoneType' object has no attribute 'publish'
Exception in thread Thread-26712:
Traceback (most recent call last):
  File "/usr/lib64/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.10/threading.py", line 1371, in run
    self.function(*self.args, **self.kwargs)
  File "/home/aug/src/prometheus-dyson/./main.py", line 88, in _timer_callback
    self.libdyson.request_environmental_data()
  File "/home/aug/.local/lib/python3.10/site-packages/libdyson/dyson_device.py", line 339, in request_environmental_data
    self._mqtt_client.publish(self._command_topic, json.dumps(payload))
AttributeError: 'NoneType' object has no attribute 'publish'
^C[aug@ogg prometheus-dyson]$ ./main.py  --config=aug-config
2022/02/26 20:08:30 [140364008355648]       INFO Starting up on port=8091
[...]

It hangs there, publishing no new data, but not dying. (Makes sense, the timer doesn't get reset)

I demoed the Dyson device (a TP04) a bit to someone, and ramped up the fan speeds etc, probably restarted it too, at about that time.
I have not been able to reproduce it. (The other device, Bedroom was down with mechanical issues throughout.)

I had a quick look at the code, and while this seems like something that should be handled on the libdyson side (it's it's internal _mqtt_client that's None) but I figured it wouldn't hurt to paper it over on this side as well.

I'm running locally now with

$ git diff 
diff --git a/main.py b/main.py
index 332281e..3310b4d 100755
--- a/main.py
+++ b/main.py
@@ -85,7 +85,10 @@ class DeviceWrapper:
         if self.is_connected:
             logging.debug(
                 'Requesting updated environmental data from %s', self.serial)
-            self.libdyson.request_environmental_data()
+            try:
+                self.libdyson.request_environmental_data()
+            except AttributeError:
+                logging.error('Race with a disconnect? Skipping  an iteration.')
             self._refresh_timer()
         else:
             logging.debug('Device %s is disconnected.', self.serial)

to see if that fixes the symptom.

--create_device_cache doesn't facilitate startup.

I did both the basel build and the debian package build. The builds seemed to complete without error. I installed the debian package, I also installed python3-zeroconf, and installed prometheus_client and libdyson via pip. I cannot start the application no matter the contents of the /etc/prometheus-dyson/ directory. I have tried removing all files, I have also tried a minimal config.ini with just the IP and serial number. I've also tried with the config.ini in a different location and that has not helped. This is what I see whenever I try to start:

/opt/prometheus-dyson/bin/main --create_device_cache
2021/03/29 20:09:16 [140529554765632] INFO Starting up on port=8091
2021/03/29 20:09:16 [140529554765632] INFO Reading "config.ini"
2021/03/29 20:09:16 [140529554765632] CRITICAL No devices configured; please re-run this program with --create_device_cache.

Value reported for Volatile Organic Compounds (VOC) appears to be ~10x that of the native dyson app

Basically as per the title. I suspect the value returned should be a value 1 10th of what it is reporting (possibly a decimal?) so instead of 12, perhaps it should be 1.2

This correlates to the (rough) position on the graph in the native dyson app which describes 0-3 as "Good" (green) when the api was returning a value of 12.

By way of example I've converted Grafana to use a 1-100 scale for VOC instead of 1-10

2021-01-09 17-41-46-1

Screenshot 2021-01-09 174448

Unable to verify OTP in config_builder in version 0.3.3

Hi there, as per my comment in a previous issue I can now run the config_builder but it's failing when verifying the OTP.

Steps to repro:

  • Upgraded 0.3.2 to 0.3.3 using dpkg -i
  • Confirmed prometheus_client up to date with PIP
  • run config_builder
  • Enter user
  • Enter password
  • receive OTP to email
  • Enter OTP in terminal

Error:
Enter OTP: 221443 Traceback (most recent call last): File "/tmp/Bazel.runfiles_1xfvuosz/runfiles/__main__/config_builder.py", line 181, in <module> main(sys.argv) File "/tmp/Bazel.runfiles_1xfvuosz/runfiles/__main__/config_builder.py", line 170, in main devices = _query_dyson(creds) File "/tmp/Bazel.runfiles_1xfvuosz/runfiles/__main__/config_builder.py", line 73, in _query_dyson verify_fn(otp, creds.password) File "/tmp/Bazel.runfiles_1xfvuosz/runfiles/pip/pypi__libdyson/libdyson/cloud/account.py", line 145, in _verify response = self.request( File "/tmp/Bazel.runfiles_1xfvuosz/runfiles/pip/pypi__libdyson/libdyson/cloud/account.py", line 113, in request raise DysonInvalidAuth libdyson.exceptions.DysonInvalidAuth

Formaldehyd metric

Hi, is there a way to add formaldehyd sensor?
it should be hcho and hchr

I started main.py with debug and i get values.
DEBUG New environmental state: {'msg': 'ENVIRONMENTAL-CURRENT-SENSOR-DATA', 'time': '2021-06-17T06:25:40.000Z', 'data': {'tact': '2950', 'hact': '0050', 'pm25': '0005', 'pm10': '0003', 'va10': '0004', 'noxl': '0002', 'p25r': '0007', 'p10r': '0007', 'hcho': '0000', 'hchr': '0000', 'sltm': 'OFF'}}

Sorry I'm not used to python

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.