Skip to content
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

pm1006: add rx-only support #2038

Merged
merged 8 commits into from
Jul 28, 2021
Merged

pm1006: add rx-only support #2038

merged 8 commits into from
Jul 28, 2021

Conversation

Habbie
Copy link
Contributor

@Habbie Habbie commented Jul 19, 2021

What does this implement/fix?

This adds ESPHome support for the IKEA VINDRIKTNING. Some inspiration taken from https://github.com/Hypfer/esp8266-vindriktning-particle-sensor

The implementation is heavily based on the existing SDS011 implementation - mostly the parser is different.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): none

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#1315

Test Environment

  • ESP32
  • ESP8266

Example entry for config.yaml:

uart:
  rx_pin: D2
  baud_rate: 9600

sensor:
  - platform: pm1006
    pm_2_5:
      name: "Particulate Matter <2.5µm"

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

Copy link
Member

@oxan oxan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds ESPHome support for the IKEA VINDRIKTNING.

Ikea keeps coming up with more and more unpronouncable names 😆

esphome/components/pm1006/pm1006.cpp Outdated Show resolved Hide resolved
esphome/components/pm1006/pm1006.cpp Outdated Show resolved Hide resolved
esphome/components/pm1006/pm1006.cpp Show resolved Hide resolved
esphome/components/pm1006/pm1006.cpp Outdated Show resolved Hide resolved
esphome/components/pm1006/pm1006.h Outdated Show resolved Hide resolved
ESPHome Dev automation moved this from Needs Review to In Review Jul 19, 2021
@Habbie
Copy link
Contributor Author

Habbie commented Jul 19, 2021

Ikea keeps coming up with more and more unpronouncable names laughing

I was going to say that as a European I can mostly cope - but you and I live in the same country :D

Thank you for your comments - I believe I have addressed them all (except possibly CI complaining about formatting, but we'll see).

@Habbie
Copy link
Contributor Author

Habbie commented Jul 19, 2021

I believe I have addressed them all

and now I actually pushed this.

Copy link
Member

@oxan oxan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_byte_() has a somewhat peculiar convention for the return value, but it's fine I guess.

@Habbie
Copy link
Contributor Author

Habbie commented Jul 20, 2021

check_byte_() has a somewhat peculiar convention for the return value, but it's fine I guess.

I was just answering a question about that from somebody else. I agree it's peculiar - as I said earlier, I stole most of the code from sds011. I'm now tempted to redo some things -less- in the style of sds011, as I suspect that will improve the code quality.

@Habbie
Copy link
Contributor Author

Habbie commented Jul 20, 2021

I'm now tempted to redo some things -less- in the style of sds011, as I suspect that will improve the code quality.

I've pondered this some more, and I think it makes sense to me to merge this as-is (assuming a maintainer agrees), and then later I can go over this one, and SDS011, and any others with the same weird code patterns, in one go.

@AbeltjeNL
Copy link

Keep up the good work @Habbie!! Just bought one of these s*ckers today at IKEA and mounted it to my ESP8266. Would very much like to get this working. If I can help out testing, please mention me :)

@Habbie
Copy link
Contributor Author

Habbie commented Jul 21, 2021

Keep up the good work @Habbie!! Just bought one of these s*ckers today at IKEA and mounted it to my ESP8266. Would very much like to get this working. If I can help out testing, please mention me :)

Hi Abeltje, testing would be very welcome, of course. Functionally, this PR is done. Perhaps the question is what I can do to help you test? I'm on the ESPHome Discord at https://discord.gg/KhAMKrd

@GSzabados
Copy link

Functionally, this PR is done.

The question is really, when is this PR going to be merged?! ;)

@lassebm
Copy link

lassebm commented Jul 22, 2021

I've tested this driver/component with an IKEA Vindriktning air quality monitor and ESP8266, works like a charm, thanks! 🎉 Fetched just the pm1006 component from the PR branch with external_components.

@AbeltjeNL
Copy link

Same here. Works like a charm! 👌🏻

@lassebm
Copy link

lassebm commented Jul 22, 2021

As inspiration for others considering this driver for the awesome IKEA Vindriktning hack. I used an old ESP8266 NodeMCU v2 from the drawer and connected it all up as listed below.

IKEA Vindriktning NodeMCU pin Note
PCB +5V pad VIN NodeMCU v2 support 5-10V
PCB GND pad GND
PCB REST pad D2 UART TX from PM1006 sensor
Fan +5V (red wire) 3V3 Fan will run constantly and quietly
Fan GND (black wire) GND

Example YAML (ESPHome >= 2021.8.0 required):

uart:
  rx_pin: D2
  baud_rate: 9600

sensor:
  - platform: pm1006
    pm_2_5:
      name: "IKEA Vindriktning PM2.5 sensor"

A few potato photos taken just before final assembly:

IMG_2577
IMG_2574

@GSzabados
Copy link

@lassebm, thanks for sharing. I've just finished the soldering and realised that the possible 4 pin connector at the end of the board would make things far more easier, but unfortunately IKEA hasn't fitted that.

@Habbie
Copy link
Contributor Author

Habbie commented Jul 22, 2021

I have now also tested this with ESP32, and it works there too.

@AbeltjeNL
Copy link

@lassebm, thanks for sharing. I've just finished the soldering and realised that the possible 4 pin connector at the end of the board would make things far more easier, but unfortunately IKEA hasn't fitted that.

I soldered my connections to these connector pins. Works fine 👌🏻

@AbeltjeNL
Copy link

AbeltjeNL commented Jul 22, 2021

image

image

image

image

I'll try to make some less potatoe pictures this weekend.

@sermayoral
Copy link
Contributor

I have now also tested this with ESP32, and it works there too.

I wanted to test this, but you did first 😃.

Can you use any esp32 gpio, or it should be the rx esp32 gpio?

Thanks for everything

@sermayoral
Copy link
Contributor

sermayoral commented Jul 22, 2021

I wanna test if i can use the output fan of the Ikea pcb applying 2 resistors to reduce the 5V to 3.3V. In that way the fan wouldn't work all the time

https://i1.wp.com/randomnerdtutorials.com/wp-content/uploads/2015/09/voltage-divider-circuit.png?resize=408%2C151&quality=100&strip=all&ssl=1

@AbeltjeNL
Copy link

AbeltjeNL commented Jul 22, 2021

I wanna test if i can use the output fan applying 2 resistors to reduce the 5V to 3.3V. In that way the fan wouldn't work all the time

https://i1.wp.com/randomnerdtutorials.com/wp-content/uploads/2015/09/voltage-divider-circuit.png?resize=408%2C151&quality=100&strip=all&ssl=1

The fan @ 5V is hardly noticeable. It doesn't spin all day and frankly, i didn't modify it but I don't hear it either..

@sermayoral
Copy link
Contributor

I wanna test if i can use the output fan applying 2 resistors to reduce the 5V to 3.3V. In that way the fan wouldn't work all the time
https://i1.wp.com/randomnerdtutorials.com/wp-content/uploads/2015/09/voltage-divider-circuit.png?resize=408%2C151&quality=100&strip=all&ssl=1

The fan @ 5V is hardly noticeable. It doesn't spin all day and frankly, i didn't modify it but I don't hear it either..

Mmm. Does it not disturb you? Its a bit annoying

@GSzabados
Copy link

Mmm. Does it not disturb you? Its a bit annoying

My notebook's fan louder than the one inside the device. Where are you using that you can notice the fan?

@sermayoral
Copy link
Contributor

Is there a bug with the last icon uploaded? I have tried to compile a firmware using esphome release branch and the pm1006 as external component, but i get this error:

INFO Reading configuration /config/esphome/aire.yaml...
ERROR Unable to import component pm1006.sensor:
Traceback (most recent call last):
  File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/esphome/.esphome/external_components/d4f73862/esphome/components/pm1006/sensor.py", line 4, in <module>
    from esphome.const import (
ImportError: cannot import name 'ICON_BLUR' from 'esphome.const' (/opt/esphome/esphome/const.py)
Failed config

sensor.pm1006: [source /config/esphome/aire.yaml:44]
  
  Platform not found: 'sensor.pm1006'.
  platform: pm1006
  pm_2_5: 
    name: IKEA Vindriktning PM2.5 sensor

@oxan
Copy link
Member

oxan commented Jul 24, 2021

@sermayoral This happens because this PR also adds the icon to the ESPHome core, so the PR branch can't be used as an external component.

@sermayoral
Copy link
Contributor

sermayoral commented Jul 24, 2021

@sermayoral This happens because this PR also adds the icon to the ESPHome core, so the PR branch can't be used as an external component.

Thanks @oxan. I have forked the PR branch changing the missing icon in order to use the pm1006 component as external component until it can be merged:

external_components:
  - source: github://sermayoral/esphome@pm1006
    components: [ pm1006 ]

@Habbie
Copy link
Contributor Author

Habbie commented Jul 24, 2021 via email

@sermayoral
Copy link
Contributor

Oops, sorry about that!

On Sat, Jul 24, 2021, at 14:59, Oxan van Leeuwen wrote: @sermayoral https://github.com/sermayoral This happens because this PR also adds the icon to the ESPHome core, so the PR branch can't be used as an external component. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2038 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEAMDUS6UATYSHM2VGIYPTTZK2LBANCNFSM5AUKJPSA.
-- Peter van Dijk @.***

Don't worry, minor solved problem, and thanks for your work!!

@GSzabados
Copy link

or the HA forums

I've created a topic in the HA forum referencing this PR.

https://community.home-assistant.io/t/ikea-vindriktning-air-quality-sensor/324599

@Habbie - if you do have a HA forum account, can you please just post there a comment and I will update the tag?
@lassebm - the same for you as for Habbie, but can you please share your your pictures and instructions as well?
@sermayoral, @AbeltjeNL - can you share your project pictures in the topic please?

ESPHome Dev automation moved this from In Review to Reviewer Approved Jul 26, 2021
Copy link
Member

@OttoWinter OttoWinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 I haven't read through the entire thread, but this integration is ready to go right?

@sermayoral
Copy link
Contributor

LGTM 👍 I haven't read through the entire thread, but this integration is ready to go right?

Hi @OttoWinter, this PR ir ready to merge, but the Doc PR should change the IMG to avoid using the IKEA one due to copyrights

@nohn
Copy link

nohn commented Jul 26, 2021

Hi @OttoWinter, this PR ir ready to merge, but the Doc PR should change the IMG to avoid using the IKEA one due to copyrights

Habbie/esphome-docs#1 should fix that issue.

@Habbie
Copy link
Contributor Author

Habbie commented Jul 26, 2021

Habbie/esphome-docs#1 should fix that issue.

merged, thanks!

@nohn
Copy link

nohn commented Jul 27, 2021

Anything else that needs to be done to get this merged?

@nohn
Copy link

nohn commented Jul 27, 2021

Example YAML using the pm1006 driver from the PR feature branch until merged upstream:

ImportError: cannot import name 'ICON_BLUR' from 'esphome.const' (/opt/esphome/esphome/const.py)

I can confirm this.

@sermayoral
Copy link
Contributor

sermayoral commented Jul 27, 2021

@sermayoral This happens because this PR also adds the icon to the ESPHome core, so the PR branch can't be used as an external component.

Thanks @oxan. I have forked the PR branch changing the missing icon in order to use the pm1006 component as external component until it can be merged:

external_components:
  - source: github://sermayoral/esphome@pm1006
    components: [ pm1006 ]

@nohn use my branch until this PR is merged

@OttoWinter OttoWinter merged commit f97cfe9 into esphome:dev Jul 28, 2021
ESPHome Dev automation moved this from Reviewer Approved to Done Jul 28, 2021
@Habbie Habbie deleted the pm1006 branch July 28, 2021 11:07
@marcos-acpc
Copy link

Hi, quick question I seen online that this sensor can read more than 2.5 PM and can at least read 1PM and 10 PM. Are you guys integrating the later 2 readings or just staying with single 2.5 PM? Found this in case it helps for anything: https://github.com/bertrik/pm1006k.

@GSzabados
Copy link

Hi, quick question I seen online that this sensor can read more than 2.5 PM

It is a PM1006 sensor and NOT the PM1006K.

http://www.jdscompany.co.kr/download.asp?gubun=07&filename=PM1006_LED_PARTICLE_SENSOR_MODULE_SPECIFICATIONS.pdf

@marcos-acpc
Copy link

@GSzabados Hi I got it but on the pdf you sent it states sizes between 0.3μm to 10μm. But yeh.. I might look for a different and more complete. sensor. Thanks anyway.

@juha63
Copy link

juha63 commented Aug 4, 2021

@Habbie I think you shouldn't name this hack PM1006. Your implementation only works if you connect the ESP to the VENDRIKTNING pcb. If you connect it to the PM1006 directly, which has RX/TX UART, you won't get any measurements without first sending the right command. See: http://www.jdscompany.co.kr/download.asp?gubun=07&filename=PM1006_LED_PARTICLE_SENSOR_MODULE_SPECIFICATIONS.pdf

@Habbie
Copy link
Contributor Author

Habbie commented Aug 4, 2021

That's correct. I modeled it like the SDS011 driver, which can operate on RX/TX mode, or in RX-only mode. As I was unable to test RX/TX mode, I only implemented RX-only mode, and for now we don't have a flag to choose - as there is no code RX/TX mode. I fully trust that somebody, perhaps me, will contribute TX/RX support soon, to the same component. It seemed pointless to me to -not- call this one pm1006 if it's going to mostly have the same code as a full pm1006 component.

(Also, it's a bit late, it's already merged).

This was referenced Aug 11, 2021
@jesserockz jesserockz mentioned this pull request Aug 18, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 14, 2021
ESPHome Dev automation moved this from Done to In Review Sep 23, 2023
ESPHome Dev automation moved this from In Review to Reviewer Approved Sep 23, 2023
ESPHome Dev automation moved this from Reviewer Approved to Done Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

10 participants