Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Add absolute humidity calculation in g/m³

Summary

Adds absolute humidity calculation to Aranet4 sensor readings, exported alongside existing sensor values in both InfluxDB and MQTT outputs. The implementation uses the Magnus-Tetens approximation to calculate absolute humidity in g/m³ from temperature (°C) and relative humidity (%) readings.

Key Changes:

  • Added absolute_humidity_g_m3() function in conv.py using standard meteorological formula
  • Export new humidity_abs field in both InfluxDB and MQTT data streams
  • Updated README with Home Assistant configuration for the new sensor

Review & Testing Checklist for Human

  • Verify mathematical accuracy: Check that the Magnus-Tetens formula implementation is correct: AH = (6.112 × e^[(17.67 × T)/(T+243.5)] × rh × 2.1674)/(273.15+T)
  • Test InfluxDB integration: Confirm humidity_abs field appears correctly in InfluxDB with reasonable values
  • Test MQTT integration: Verify humidity_abs field is present in MQTT messages and matches InfluxDB values
  • Validate calculation results: Spot-check that calculated values are reasonable (e.g., 20°C/60% RH should yield ~10.4 g/m³)
  • Test Home Assistant integration: Verify the new MQTT sensor configuration works correctly in Home Assistant

Recommended test plan: Run the application with --print flag and verify the new absolute humidity values appear reasonable across different temperature/humidity conditions. Check both InfluxDB and MQTT outputs contain the new field.


Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    A["main.py"]:::context --> B["aranet.py"]:::context
    B --> C["conv.py"]:::major-edit
    A --> D["influx.py"]:::major-edit
    A --> E["mqtt.py"]:::major-edit
    F["README.md"]:::minor-edit
    
    C --> |"absolute_humidity_g_m3()"| D
    C --> |"absolute_humidity_g_m3()"| E
    D --> |"humidity_abs field"| G["InfluxDB"]:::context
    E --> |"humidity_abs field"| H["MQTT Broker"]:::context
    H --> I["Home Assistant"]:::context
    
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit
        L3["Context/No Edit"]:::context
    end

classDef major-edit fill:#90EE90
classDef minor-edit fill:#87CEEB
classDef context fill:#FFFFFF
Loading

Notes

  • The Magnus-Tetens approximation is widely used in meteorology and should be accurate for typical indoor temperature ranges
  • Field naming follows existing convention (e.g., humidity_pct, temp_c, pressure_mbar)
  • Implementation is additive - no existing functionality is modified
  • Basic verification showed reasonable results: 20°C/60% RH → 10.37 g/m³ (expected ~10.4 g/m³)

Link to Devin run: https://app.devin.ai/sessions/0efbf12ab70747d2baeff9d5f30717e5
Requested by: Chris Dzombak (@cdzombak)

- Add absolute_humidity_g_m3() function to conv.py using Magnus-Tetens approximation
- Export humidity_abs field in both InfluxDB and MQTT outputs
- Update README Home Assistant integration with absolute humidity sensor
- Calculation uses temperature (°C) and relative humidity (%) from Aranet sensor

Co-Authored-By: Chris Dzombak <chris@dzombak.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Wrap long function calls across multiple lines in influx.py and mqtt.py
- Addresses CI lint failure in PR #7

Co-Authored-By: Chris Dzombak <chris@dzombak.com>
return mbar * 0.02952998751


def absolute_humidity_g_m3(temp_celsius: float, relative_humidity_pct: float) -> float:
Copy link
Owner

Choose a reason for hiding this comment

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

Please add some test cases for this function that are easily human-readable for a quick sanity check.

devin-ai-integration bot and others added 2 commits July 20, 2025 21:36
- Add comprehensive docstring with human-readable test cases
- Include typical room conditions, cold conditions, and warm humid examples
- Addresses GitHub comment requesting sanity check examples

Co-Authored-By: Chris Dzombak <chris@dzombak.com>
- Remove trailing whitespace from docstring
- Addresses CI lint failure after adding test cases

Co-Authored-By: Chris Dzombak <chris@dzombak.com>
Test cases for quick sanity check:
20°C, 60% RH → 10.37 g/m³ (typical room conditions)
0°C, 50% RH → 2.42 g/m³ (cold conditions)
25°C, 80% RH → 18.42 g/m³ (warm, humid conditions)
Copy link
Owner

Choose a reason for hiding this comment

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

Add standard Python unit tests for these cases.

devin-ai-integration bot and others added 2 commits July 20, 2025 21:40
- Create test_conv.py with unittest framework
- Test all three documented test cases with proper assertions
- Addresses GitHub comment requesting standard Python unit tests
- All tests pass locally

Co-Authored-By: Chris Dzombak <chris@dzombak.com>
- Apply Ruff formatting to test_conv.py
- Addresses CI lint failure after adding unit tests
- All tests continue to pass locally

Co-Authored-By: Chris Dzombak <chris@dzombak.com>
@cdzombak cdzombak merged commit 2b74d6d into main Jul 20, 2025
8 checks passed
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.

1 participant