Add configurable update interval for LTR390 sensor#56
Conversation
WalkthroughAdded a public global timestamp and a user-configurable template number for the LTR390 update interval, set the sensor to Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User as User (UI/Config)
participant Num as Number Entity\n`ltr390_update_interval`
participant Timer as 1s Interval Timer
participant Globals as Global Storage\n`ltr390_last_update`
participant Sensor as LTR390 Sensor
User->>Num: set interval (seconds)
Note right of Num: stored as entity state
Timer->>Globals: read `ltr390_last_update`
Timer->>Num: read `.state` (interval)
Timer->>Timer: compute current_time = millis()/1000
alt current_time - last_update >= interval
Timer->>Sensor: call `update()`
Sensor-->>Timer: update complete
Timer->>Globals: write `ltr390_last_update = current_time`
else not yet elapsed
Timer-->>Timer: wait next tick
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
83db9fd to
0c067fa
Compare
Allows users to adjust the LTR390 sensor update frequency from the default 60 seconds to any value between 1-300 seconds through the web interface, eliminating the need for YAML edits and firmware recompilation. Uses ESPHome's interval component to manually poll the sensor at the configured rate, as sensor platform update_interval is not templatable. The setting is exposed as a number input under the CONFIG entity category with values persisted across device reboots. Resolves #54 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
0c067fa to
9dd9982
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@Integrations/ESPHome/Core.yaml`:
- Around line 164-176: Add a new template number sensor named ltr390_lux_offset
(same pattern as DPS310 temperature offset: restore_value true, initial_value 0,
wide min/max, unit "lx", entity_category "CONFIG", optimistic true,
update_interval never, step 1, mode box) right after the existing template
numbers block; then update the LTR390 light filter lambda so the filter uses the
offset by changing the current_value assignment from the hardcoded value to
incorporate the offset (replace the current_value assignment with one that adds
id(ltr390_lux_offset).state), ensuring you reference the id ltr390_lux_offset in
the lambda.
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>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Integrations/ESPHome/Core.yaml (1)
164-177: Consider settingdisabled_by_default: falsefor better UX discovery.In Home Assistant, entities with
disabled_by_default: trueare discovered but remain disabled until manually enabled. If the intent is for users to easily configure this interval, requiring the extra step of enabling it first adds friction to the workflow.Suggested change
- platform: template name: LTR390 Update Interval id: ltr390_update_interval - disabled_by_default: true + disabled_by_default: false restore_value: true🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Integrations/ESPHome/Core.yaml` around lines 164 - 177, The template sensor "LTR390 Update Interval" (id ltr390_update_interval) is marked disabled_by_default: true which hides it from users; change disabled_by_default to false in the entity definition so the update-interval entity is enabled by default and easier for users to discover and configure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 164-177: The template sensor "LTR390 Update Interval" (id
ltr390_update_interval) is marked disabled_by_default: true which hides it from
users; change disabled_by_default to false in the entity definition so the
update-interval entity is enabled by default and easier for users to discover
and configure.
Summary
This PR implements the configurable update interval requested in #54 for the LTR390 light sensor.
Changes
Number Input Added
LTR390 Update Interval- Configurable sensor polling rate (1-300 seconds, default: 60s)Sensor Configuration Updates
update_intervaltonever(disables automatic polling)ltr390_last_updateto track last sensor update timeintervalcomponent that runs every 1 second to check if configured interval has elapsedcomponent.update()when neededTechnical Details
Why use interval component?
ESPHome sensor platforms don't support templatable
update_intervalparameters. Attempting to use a lambda forupdate_intervalresults in compilation error: "This option is not templatable!"How it works:
update_interval: never)id(ltr_390).update()The setting:
restore_value: true)Benefits
Users can now adjust the LTR390 sensor update frequency without:
Simply adjust the value through the web interface and the sensor will update at the new interval.
Testing
Resolves
Closes #54
🤖 Generated with Claude Code
Summary by CodeRabbit