Skip to content

Add next_watering timestamp sensor per device#414

Merged
sebr merged 3 commits intosebr:mainfrom
DAB-LABS:feature/next-watering-sensor
Apr 29, 2026
Merged

Add next_watering timestamp sensor per device#414
sebr merged 3 commits intosebr:mainfrom
DAB-LABS:feature/next-watering-sensor

Conversation

@DAB-LABS
Copy link
Copy Markdown
Contributor

Closes #410

Promotes the existing next_start_time valve attribute to a first-class per-zone SensorDeviceClass.TIMESTAMP sensor, as discussed in #410.

What this adds

A sensor.{zone_name}_next_watering entity is created for each zone on a sprinkler_timer device. It reports the next scheduled watering time as a proper timestamp, enabling relative-time rendering ("in 14 hours"), long-term statistics, history graphs, and direct use in automations and dashboard cards without a template wrapper.

The existing next_start_time valve attribute is preserved for backward compatibility.

Design decisions

  • Per-zone scope, matching how next_start_time is already keyed in the data model
  • Schedule-type-agnostic — reads whatever Orbit provides, no branching on program type
  • programs extra state attribute exposes next_start_programs for visibility into which schedule is responsible
  • Disabled by default (entity_registry_enabled_default=False) to avoid cluttering the UI on install — users opt in per zone. Happy to discuss if you prefer enabled by default.
  • Reuses existing coordinator data and orbit_time_to_local_time helper — no new API calls

Testing

  • Tested against a 6-zone Timer on HA
  • Unit tests added covering populated, null, and missing next_start_time cases
  • ruff check clean
  • All 14 sensor tests passing

Comment thread custom_components/bhyve/sensor.py Outdated
Comment on lines +243 to +253
# Add per-zone sensors (next watering, etc.)
for base_description in SENSOR_TYPES_ZONE:
sensors.append( # noqa: PERF401
BHyveZoneSensor(
coordinator,
device,
zone,
zone_name,
base_description,
)
)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@DAB-LABS for devices with multiple zones, then each zone will receive a next watering sensor with the same data, as status.next_start_time is a property on the device, not the zone.

Therefore, a 6-zone timer creates 6 sensors that all return the identical timestamp. For a user, it is both confusing: "Front Lawn next watering" and "Back Lawn next watering" will show the same value, but also potentially incorrect, as the next_start_programs value may not actually run on all the zones.

Let's move this into SENSOR_TYPES_SPRINKLER instead

Comment thread custom_components/bhyve/sensor.py Outdated
data.get("status", {}).get("next_start_time")
),
attributes_fn=lambda data: {
ATTR_NEXT_START_PROGRAMS: data.get("status", {}).get("next_start_programs"),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The programs attribute should only be included if it exists.

Comment thread custom_components/bhyve/sensor.py Outdated

entity_description: BHyveSensorEntityDescription
_attr_has_entity_name = True
_attr_entity_registry_enabled_default = False
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think it should be enabled by default

@DAB-LABS
Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @sebr!

Here's what we addressed:

Moved next_watering from per-zone to device-level. You were right, the data is device-level and this is the cleaner approach. programs attribute is now conditional, only included when next_start_programs is present. Enabled by default, opt-in removed.

Bonus bug fix:

While wiring next_watering into SENSOR_TYPES_SPRINKLER we noticed device_class was being silently dropped when constructing sensor descriptions in async_setup_entry. Never mattered for the state sensor since it's a string, but TIMESTAMP rendering absolutely depends on it. Without it HA treated the timestamp as a plain string instead of "in 2 days". Made sure device_class now travels with the description all the way through to HA.

Thanks for having us take another look. 🙂

Tested on:

HA Test (core-2026.3.4, fresh install). Sensor appears in Sensors section, renders "in 2 days", enabled by default. ruff clean, pytest passing.

~DAB

DAB added 2 commits April 28, 2026 15:22
Promotes the existing next_start_time valve attribute to a first-class
per-zone SensorDeviceClass.TIMESTAMP sensor. Non-breaking, additive.

- Adds BHyveZoneSensor class and SENSOR_TYPES_ZONE descriptor
- Exposes next_start_programs as a 'programs' extra state attribute
- Preserves existing valve attribute for backward compatibility
- Disabled by default to avoid cluttering UI on install
- Adds translation strings and README documentation
- Adds unit tests covering populated, null, and missing cases

Closes sebr#410
Per review feedback:
- Move next_watering from per-zone (BHyveZoneSensor) to device-level
  (SENSOR_TYPES_SPRINKLER), using the existing BHyveSensor class
- Remove SENSOR_TYPES_ZONE tuple and BHyveZoneSensor class
- Make programs attribute conditional: only set when next_start_programs
  is present in device status
- Enable by default (drop entity_registry_enabled_default=False)
- Fix missing device_class passthrough in sprinkler sensor description
  copy (pre-existing bug, exposed by TIMESTAMP rendering requirement)
- Update tests and README to reflect device-level scope
@DAB-LABS DAB-LABS force-pushed the feature/next-watering-sensor branch from 47e920e to a510303 Compare April 28, 2026 22:23
name=base_description.name,
icon=base_description.icon,
unique_id_suffix=base_description.unique_id_suffix,
device_class=base_description.device_class,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good pickup

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was human ~ Claude wanted to give you a string. Kept telling me it was correct... 🤦‍♂️😂

~DAB

@sebr
Copy link
Copy Markdown
Owner

sebr commented Apr 28, 2026

Thanks for the contribution, @DAB-LABS 👍

@sebr sebr merged commit 35f4296 into sebr:main Apr 29, 2026
4 checks passed
@sebr sebr mentioned this pull request Apr 29, 2026
@sebr sebr changed the title Add next_watering timestamp sensor per zone Add next_watering timestamp sensor per device Apr 29, 2026
@DAB-LABS DAB-LABS mentioned this pull request May 2, 2026
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.

Promote next_start_time valve attribute to a first-class timestamp sensor

2 participants