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

Add support for SGP41 #3382

Merged
merged 19 commits into from May 19, 2022
Merged

Add support for SGP41 #3382

merged 19 commits into from May 19, 2022

Conversation

martgras
Copy link
Contributor

@martgras martgras commented Apr 13, 2022

What does this implement/fix?

add support for SPG41 and SPG40. SGP41 supports all features of SGP40 but measures NOx as well.
The sensor type is autodetected.
Algorithm tuning option added.

Because spg41 adds NOx the new component is a multi-sensor component therefore a new configuration schema is required.
Therefore I decided to create a new component SPG4x supporting both sensors and mark the existing SPG40 component deprecated. Just changing the SGP40 component would break existing setups

Instead of copying the sensirion gas library code I'm now adding it as library. (https://github.com/Sensirion/arduino-gas-index-algorithm)
The only "problem" is esp-idf support. Because sensirion doesn't supply library.json the lib is considered arduino only. But actually it is framework agnostic. I submitted Sensirion/arduino-gas-index-algorithm#1 but in the meantime use my own fork at https://github.com/martgras/arduino-gas-index-algorithm .
Works like a charm with esp-idf

All other code is using the codebase from SGP40 by @SenexCrenshaw

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): fixes

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

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266

Example entry for config.yaml:

# Example config.yaml
  - platform: sgp4x
    voc:
      name: "VOC Index"
      id: sgp41_voc_index
      algorithm_tuning:
        index_offset: 100
        learning_time_offset_hours: 12
        learning_time_gain_hours: 12
        gating_max_duration_minutes: 180
        std_initial: 50
        gain_factor: 230
    nox:
      name: "NOx"
      algorithm_tuning:
        index_offset: 100
        learning_time_offset_hours: 12
        learning_time_gain_hours: 12
        gating_max_duration_minutes: 180
        std_initial: 50
        gain_factor: 230
        
    compensation:
      humidity_source: sht40_humidity
      temperature_source: sht40_temperature
    update_interval: ${updates}

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:

add support for SPG41 and SPG40
replaces the sgp40 component. Marked it as deprecated.
Because spg41 adds NOx the new component is a multi-sensor  component therefore a  new configuration schema is required.
The sensor type is autodetected.
Algorithm tuning option added.
@probot-esphome
Copy link

Hey there @SenexCrenshaw, mind taking a look at this pull request as it has been labeled with an integration (sgp40) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

Hey there @martgras,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.
In __init__.py of the integration, please add:

CODEOWNERS = ["@martgras"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@jesserockz
Copy link
Member

They will need to make another release on platformio for this to work. But for now you could point platformio.ini and cg.add_library to their repo.

Copy link
Member

@jesserockz jesserockz left a comment

Choose a reason for hiding this comment

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

Minor changes, otherwise looks fine.

esphome/components/sgp4x/sensor.py Outdated Show resolved Hide resolved
platformio.ini Show resolved Hide resolved
ESPHome Dev automation moved this from Needs Review to Reviewer Approved May 10, 2022
@jesserockz jesserockz merged commit 0ed7db9 into esphome:dev May 19, 2022
ESPHome Dev automation moved this from Reviewer Approved to Done May 19, 2022
Assunto pushed a commit to Assunto/esphome that referenced this pull request May 19, 2022
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2022
ESPHome Dev automation moved this from Done 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

2 participants