Skip to content

Add configurable update interval for LTR390 sensor#76

Merged
TrevorSchirmer merged 2 commits intobetafrom
feature/ltr390-configurable-interval
Feb 13, 2026
Merged

Add configurable update interval for LTR390 sensor#76
TrevorSchirmer merged 2 commits intobetafrom
feature/ltr390-configurable-interval

Conversation

@bharvey88
Copy link
Contributor

@bharvey88 bharvey88 commented Feb 2, 2026

Summary

This PR implements a configurable update interval for the LTR390 light sensor, matching the functionality added to MSR-2 in ApolloAutomation/MSR-2#56.

  • LTR390 Update Interval: Allows users to adjust the sensor update frequency from the default 60 seconds to any value between 1-300 seconds

Changes

Number Input Added

  • LTR390 Update Interval - Configurable sensor polling rate (1-300 seconds, default: 60s)

Sensor Configuration Updates

  • Set LTR390 update_interval to never (disables automatic polling)
  • Added global variable ltr390_last_update to track last sensor update time
  • Added interval component that runs every 1 second to check if configured interval has elapsed
  • Manually triggers sensor update via component.update() when needed

Technical Details

Why use interval component?
ESPHome sensor platforms don't support templatable update_interval parameters. Attempting to use a lambda for update_interval results in compilation error: "This option is not templatable!"

How it works:

  1. LTR390 sensor automatic updates are disabled (update_interval: never)
  2. A 1-second interval checks elapsed time since last update
  3. When configured interval is reached, manually triggers id(ltr_390).update()
  4. Tracks update time in global variable for next interval calculation

The setting:

  • Uses ESPHome template number platform
  • Is categorized as CONFIG entity for proper grouping in the web UI
  • Persists values across device reboots (restore_value: true)
  • Is immediately accessible through the device's web interface on port 80
  • Updates take effect immediately without reboot

Benefits

Users can now adjust the LTR390 sensor update frequency without:

  • Editing YAML configuration files
  • Recompiling firmware
  • Reflashing the device
  • Rebooting the device

Simply adjust the value through the web interface and the sensor will update at the new interval.

Testing

  • YAML syntax validated
  • Configuration follows existing patterns (similar to DPS Temperature Offset)
  • Backward compatible (default value of 60s)
  • Interval component approach is standard ESPHome pattern for dynamic timing

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • LTR390 sensor now uses configurable interval-driven updates (1–300 s, default 60 s) instead of the previous fixed 5 s cadence.
  • Chores

    • Version updated to 26.2.2.1

- Add global variable ltr390_last_update to track last sensor update time
- Add LTR390 Update Interval template number (1-300s, default: 60s)
- Set LTR390 update_interval to never (disables automatic polling)
- Add interval component to manually trigger updates based on configured interval

Users can now adjust the LTR390 sensor update frequency through the web
interface without editing YAML, recompiling, or reflashing firmware.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

Walkthrough

Version bumped to 26.2.2.1; LTR390 sensor moved from fixed 5s updates to manual/update_interval never driven by two new interval automations and a new configurable template sensor that sets the update frequency (1–300 s). A global timestamp tracks last update.

Changes

Cohort / File(s) Summary
LTR390 update mechanism
Integrations/ESPHome/Core.yaml
Bumped substitutions.version to 26.2.2.1. Added global ltr390_last_update (uint32_t). Added template sensor LTR390 Update Interval (ltr390_update_interval, 1–300 s, default 60). Changed ltr_390 sensor update_interval from 5s to never. Added two top-level interval blocks that conditionally call id(ltr_390).update() and store the timestamp when elapsed >= configured interval.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped at dawn to check the light,
Now updates wait for intervals right.
A counter keeps the time so fine,
You pick the beat — I press the line.
Tiny paws, precise delight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the primary change: adding a configurable update interval for the LTR390 sensor, which matches the core objective of implementing a templatable update interval (1–300 seconds, default 60s) via an ESPHome template entity.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/ltr390-configurable-interval

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@Integrations/ESPHome/Core.yaml`:
- Around line 410-422: The first LTR390 reading is delayed because
ltr390_last_update initializes to 0 and the interval lambda only triggers after
the configured interval; modify the lambda in the interval block so that if
id(ltr390_last_update) == 0 it calls id(ltr_390).update() and sets
id(ltr390_last_update) to current_time immediately (in addition to the existing
periodic check against id(ltr390_update_interval).state), ensuring an immediate
sensor read at boot.

Add check for first boot condition (last_update == 0 && current_time > 0)
to trigger an immediate sensor update instead of waiting for the full
configured interval to elapse.

The current_time > 0 guard prevents edge case where both values are 0
in the first second after boot.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@TrevorSchirmer TrevorSchirmer merged commit a0258ed into beta Feb 13, 2026
11 checks passed
@TrevorSchirmer TrevorSchirmer deleted the feature/ltr390-configurable-interval branch February 13, 2026 21:07
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.

2 participants

Comments