-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Added support for particulate matters sensors #2571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Please have a look at the source. It is for sensors like this: If this is ok in general, I will add the documentation. |
I'm confused by the name. the name particulate matter is what it is measuring right? The platforms should focus on a specific brand/model and be named after that. What would that be here ? We also have a policy to not include device specific protocol code in our repo but instead depend on 3rd party lib for that. That way other people can use it too while not having to use Home Assistant. So could you move the interact with device code to an external lib? |
thread.daemon = True | ||
thread.start() | ||
|
||
def refresh(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use this. Instead, Home Assistant will call update(…)
on your device every 15 seconds, by throttling this call (using util.Throttle()
) you can get to the required interval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see now that this is not an entity. In that case you can have the entities call update()
on this from entity.update()
and still have apply the throttle to the PMDataCollector.update()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Letting each sensor call the update method is a bit problematic as they would read different data frames. This would result in inconsistent states (e.g. PM10 could be lower than PM2.5 when read from different data blocks). What is the recommended way to synchronise updates on multiple sensors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Throttle
, it will take care of this for you. It will ensure that there is a cooldown of specified period in which calls to the method will not go through.
There are different sensors like this on the market. They all share a similar serial protocol (basically a block of data), but the start bytes, length of frame and position of the data are different. The idea was to have a generic driver that can be used for all these devices. |
What about calling it Here in It imports Rpi.GPio, but With this library you might be able to cover rpi and a normal serial implementation? |
@kellerza If you like, we can call it dust, but basically dust is particulate matter ;-) @balloob @kellerza I'm not sure if it would be better to create a generic "serial_sensor"? But the configuration for the user will become even more complicated than it already is. |
What about "serial_pm_sensor"? |
|
I like adding About the config, would it be possible to name the models so that you put in your model and the platform knows which config settings it needs ? |
ok, then I go for "serial_pm_sensor". Adding configurations for a few sensors I can test is possible. I would recommend to have the option to configure everything by the user or use a pre-defined configuration (like "oneair" for the Oneair sensor I'm using right now). I will look into this in the next days. |
Okay, so there is a brand: oneair. I suggest we rename the platform Since you will have to extract the logic for communication into a standalone lib, it will be possible to have multiple platforms (one for each brand/product) reference the same lib. The code will still be shared but we follow the Home Assistant naming pattern. |
Even with extracting the logic into a separate lib, supporting these sensors from different vendors would mean duplicating a lot of code. |
I see your point, but in that case I would love to see the platform named after the name of the protocol. If that's not available, I guess With all the logic be put in a standalone lib (including brand specific configs), the final config could look something like this: sensor:
platform: serial_pm # <- or whatever is decided
brand: oneair |
Ok, makes sense. I will go this route. As I'm still waiting for 2 other sensors to arrive, it will take some time until I will finish this. |
Alright. No problem. You could create a standalone lib that just supports the oneair sensor 👍 |
Ok, all sensor functionality including definition of the data formats have been moved to the pmsensor library. |
Any comments on this? The code should be ready now. |
pm.SUPPORTED_SENSORS[config.get(CONF_BRAND)]) | ||
except KeyError: | ||
_LOGGER.error("Brand %s not supported", config.get(CONF_BRAND)) | ||
_LOGGER.error(" supported brands: %s", pm.SUPPORTED_SENSORS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe combine this into a single .error()
and remember to return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can do this.
- Additional exception handling
The SCAN_INTERVAL code has been removed now. The code should be ready now. |
Almost. Are you sure you can still add a You might have to change your schema to: PLATFORM_SCHEMA = homeassistant.components.sensor.PLATFORM_SCHEMA.extend({ |
Derived config from sensor.PLATFORM_SCHEMA |
Looks good & thanks for you patience! 🐬 |
Thanks you for the support. |
Description: Adds support for serial-connected particulate matter sensors. See http://www.open-homeautomation.com/2016/07/19/measuring-air-quality/ on a bit more information about these sensors.
Related issue (if applicable): -
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#765
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If code communicates with devices, web services, or a:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass