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 a usermod for AHT10, AHT15 and AHT20 temperature/humidity sensors #3977

Merged
merged 10 commits into from
May 21, 2024

Conversation

LordMike
Copy link

@LordMike LordMike commented May 13, 2024

This pull request introduces a new usermod for integrating the AHT10, AHT15, and AHT20 humidity and temperature sensors into WLED. It uses the enjoyneering/AHT10 library to handle the wire stuff, and implements settings like:

  • I2CAddress: The i2c address in decimal. Set it to either 56 (0x38, the default) or 57 (0x39).
  • SensorType: Numeric 0-2 for each of the valid sensor chips
  • CheckInterval: Number of seconds between readings
  • Decimals: Number of decimals to put in the output

Info view.
image

Settings view.
image

@LordMike LordMike changed the base branch from main to 0_15 May 13, 2024 21:18
Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

There are a couple of indentation errors as well as the in-line commented issues.

You might also want to add build flags and libraries to platformio_override.sample.ini

usermods/AHT10_v2/README.md Show resolved Hide resolved
usermods/AHT10_v2/usermod_aht10.h Show resolved Hide resolved
usermods/AHT10_v2/usermod_aht10.h Outdated Show resolved Hide resolved
@blazoncek
Copy link
Collaborator

VSC AFAIK detects it and uses appropriate indentation by default. You can enter anything, though.

@LordMike
Copy link
Author

LordMike commented May 14, 2024

I belive I've handled the issues. I used format document in vscode based on an editorconfig it came up with.

Quick note - the CI isn't building my usermod, right?.. If you want, I could add a sample override file directly in the usermod folder, which could be referenced by a CI job for usermods. Something like the below.

[env:sample]
extends = env:esp32dev
build_flags =
  ${common.build_flags} ${esp32.build_flags}
  -D USERMOD_AHT10
  ; -D USERMOD_AHT10_DEBUG ; -- add a debug status to the info modal
lib_deps = 
  ${esp32.lib_deps}
  enjoyneering/AHT10@~1.1.0
  Wire

@LordMike
Copy link
Author

Should I implement MQTT publishing, guarded by the "if mqtt compiled in" ifdefs?

@blazoncek
Copy link
Collaborator

Quick note - the CI isn't building my usermod, right?.. If you want, I could add a sample override file directly in the usermod folder, which could be referenced by a CI job for usermods. Something like the below.

Indeed. That would be nice as currently none of the usermods go through compilation process.

One more observation: Is it necessary to have "AHT Temperature" and "AHT Humidity"? There is no reason for "AHT" IMO.

@blazoncek
Copy link
Collaborator

Should I implement MQTT publishing, guarded by the "if mqtt compiled in" ifdefs?

That would be welcome by many users. Including HA autodiscovery broadcast.

@LordMike
Copy link
Author

LordMike commented May 14, 2024

Re. naming of info things

I was not sure what to put there. In my setup, I'll have both the BME280, AHT20 and an INA226 (tbd). As the BME280 will provide "Temperature", I wasn't sure if also providing Temperature through the AHT was going to be an issue.

@LordMike
Copy link
Author

As I read it, the two usermods would both be creating the u dictionary in json and adding named keys to it. If both add "Temperature" .. as I read the JSON code now, the second caller would get a reference to the same array that the first one made. So in the end, the two usermods would put in 4 values - [Temp 1, "C", Temp 2, "C"]..

@blazoncek
Copy link
Collaborator

Why on earth would you want two temperature sensors on one, LED driving, device?

@LordMike
Copy link
Author

Well. The device I got from china had both in it to provide me with 3 values (temp, humidity and pressure).. So yay me .. :D

Hilarious part is that a BMxxxx chip variant has all three values, but ... 🤷

@blazoncek
Copy link
Collaborator

You can always disable one of them...

@LordMike
Copy link
Author

You can always disable one of them...

Entirely true. Either code it so that temp isn't read from one of them, either a checkbox or "255" decimals meaning "don't". Or discard pressure and keep temp+humidity. :P

I'll have a look at the mqtt stuff. As for the naming of the ui json .. I can name it without AHT, but if the two usermods are run at the same time it's .. undefined..

@LordMike
Copy link
Author

So I:

  • Added MQTT publishing
  • HASS MQTT discovery publishing (stole code from BME280)
  • Added settings that mimic that of BME280
  • If MQTT is disabled, all of the above disappear
  • I removed 5 instance bools in favor of a flags bitfield which is controlled through two macros

@LordMike LordMike requested a review from blazoncek May 14, 2024 21:25
Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

I'll neither approve nor request changes as technically the code looks correct (as far as logical analysis goes), but IMO it could be made clearer by using unnamed struct bitfields.

Also reexamine all strings, please. There are advantages and disadvantages when using F() macro.

You could also avoid inlining (reduced code size) by moving function definitions outside of class definition. See other usermods.

usermods/AHT10_v2/usermod_aht10.h Outdated Show resolved Hide resolved
usermods/AHT10_v2/usermod_aht10.h Outdated Show resolved Hide resolved
usermods/AHT10_v2/usermod_aht10.h Outdated Show resolved Hide resolved
usermods/AHT10_v2/usermod_aht10.h Outdated Show resolved Hide resolved
usermods/AHT10_v2/usermod_aht10.h Outdated Show resolved Hide resolved
- Reduce some strings
- Use an unnamed struct to pack the bitfield instead
@LordMike LordMike requested a review from blazoncek May 15, 2024 19:33
@blazoncek blazoncek merged commit 31b232d into Aircoookie:0_15 May 21, 2024
18 checks passed
@LordMike LordMike deleted the feature/aht10_usermod branch May 27, 2024 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants