Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - next program runtime #142

Open
BrettWa opened this issue Nov 13, 2020 · 4 comments
Open

Feature request - next program runtime #142

BrettWa opened this issue Nov 13, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@BrettWa
Copy link

BrettWa commented Nov 13, 2020

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

@vinteo vinteo added the enhancement New feature or request label Nov 13, 2020
@vinteo
Copy link
Owner

vinteo commented May 30, 2021

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.

@BrettWa
Copy link
Author

BrettWa commented May 31, 2021

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.

@vinteo
Copy link
Owner

vinteo commented May 31, 2021

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.

@EdLeckert
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants