bob1de / hass-apps

Some useful apps and snippets to empower Home Assistant and AppDaemon even more.
Apache License 2.0
85 stars 23 forks source link

static schedule : start_time ignored for weeks ? #72

Open aschor opened 2 years ago

aschor commented 2 years ago

Hi, I'm having difficulties setting a schedule that could be expressed like so : "thursday, every 6 weeks, starting from december 30, 2021, and going on forever over following monthes/years"

(It's for my glass garbage pickup).

I have tried :

schedy_calendrier_poubelles:  # This is our app instance name.
  module: hass_apps_loader
  class: SchedyApp

  actor_type: generic2
  actor_templates:
    une_date:
      send_retries: 0
      attributes:
      - attribute: state
      values:
      - value: ["*"]
        calls:
        - service: input_datetime.set_datetime
          data:
            date: "{attr1}"
      ignore_case: true

  schedule_snippets:
    ordures_verres:
      - v : '2021-09-01'  #la valeur ne sera jamais utilisée, juste la prochaine date d'itération
        weekdays: 4
        weeks: "*/6"
        start_date: { year: 2021, month: 12, day: 27}

  rooms:
    exterieur_verres:
      actors:
        input_datetime.date_next_ordures_verres:
          template: une_date
      schedule:
        - x: |
            results = schedule.next_results(
                schedule_snippets["ordures_verres"],
                end=now+datetime.timedelta(days=90),
            )
            result="2020-01-01"
            for when, (value, markers, rule) in results:
              if (when.month==12 and when.day==25) or (when.month==1 and when.day==1):
                continue
              result=when.strftime("%Y-%m-%d")
              break

and ... whatever date I set in "start_date" in the snipet ...... every time the next schedule is 2022-01-06 and not 2021-12-30. So that Is what I suppose could be a bug ? or a design choice ? I had hopes that setting the "start_time" would shift the weeks numbers, and so change the result.

I have for now set up a datetime.timedelta(weeks=1) in the code, But I have the feeling that the rule will not work correctly next year, because it is based on week number, and not on the (start_date week + xxx weeks ) modulo 6 (is such a contraint achievable ?)

bonus question : do I need a "sensor.time" (or sensor.wod) in the watched entities for the schedule to work ?