hass-opensprinkler icon indicating copy to clipboard operation
hass-opensprinkler copied to clipboard

Feature request - next program runtime

Open BrettWa opened this issue 4 years ago • 4 comments

Not sure if possible - but it'd be great to have each Program's next runtime?

BrettWa avatar Nov 13 '20 14:11 BrettWa

By run time you mean the next time it will run not the duration right? or both?

For duration I think it may be difficult.

vinteo avatar May 30 '21 00:05 vinteo

By run time you mean the next time it will run not the duration right? or both?

For duration I think it may be difficult.

Just the next time a program will run - not too concerned over duration, in my case, that's static.

BrettWa avatar May 31 '21 05:05 BrettWa

I checked the API, it doesn't provide this info, we would have to calculate it ourselves which can be come quite complicated as we have to take into account sunset/sunrise, days of the week and offsets.

vinteo avatar May 31 '21 05:05 vinteo

Here's how I do it. It's not pretty, but it works. Note that this depends on PRs #235 and #236, which should be in the next release.

Also note that it works only for a single schedule, in my case named Standard Schedule, and that it assumes a Program Type of Interval. Also, there are no Restrictions or Additional Start Times and I don't know what else. Like @vinteo said, it's complicated, but in my case, it works.

From configuration.yaml:

template:
  - sensor:
      - name: OpenSprinkler Next Run
        state: >
          {% set remaining_days = states("number.standard_schedule_starting_in_days") | int %}
          {% set interval_days = states("number.standard_schedule_interval_days") | int %}
          {% set start_time = strptime(states("time.standard_schedule_start_time"), "%H:%M:%S") %}
          {% set start_minutes = start_time.hour * 60 + start_time.minute %}
          {% set midnight_today = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
          {% set start_timedelta = timedelta(minutes = start_minutes) %}
          {% if remaining_days == 0 and now() > midnight_today + start_timedelta %}
            {% set next_run = midnight_today + timedelta(days = interval_days, minutes = start_minutes) %}
          {% else %}
            {% set next_run = midnight_today + timedelta(days = remaining_days, minutes = start_minutes) %}
          {% endif %}
          {{ next_run }}

      - name: "OpenSprinkler Next Run Time"
        state: >
          {{ as_timestamp(states("sensor.opensprinkler_next_run")) | timestamp_custom('%a, %b %-d %-I:%M %p', local=True) }}

NextRun

And the card:

              - type: custom:mushroom-entity-card
                entity: sensor.opensprinkler_next_run_time
                icon: mdi:calendar-start
                name: Next Run

EdLeckert avatar Sep 15 '23 21:09 EdLeckert