bruxy70 / Garbage-Collection

🗑 Custom Home Assistant sensor for scheduling garbage collection (or other regularly re-occurring events - weekly on given days, semi-weekly or monthly)
MIT License
387 stars 90 forks source link

Extending the Collection Day #424

Closed teamRibcage closed 2 years ago

teamRibcage commented 2 years ago

Before you submit a new bug report, please check that

Write your question here

I have a bit of a unique situation in which I would like to track a collection that occurs sometime during the first full week of the month. I have no issue scheduling collection for the 1st Monday of the month (and therefore the 1st full business week), however I would like the entity to retain the "Today" (or 0) status through Friday. I have so far been unsuccessful in configuring such a scheme - any help would be greatly appreciated!

Thanks! 🙂

bruxy70 commented 2 years ago

I suggest creating another sensor, a template, checking whether the difference between current date and the last collection date (this is attribute of the collection) is less or equal than 5. And you can make it either a sensor, a binary sensor (yes or no), or even evaluate this as a condition in your automation and not create any new sensor, just use the last collection date and check whether it was less than 5 days ago.

teamRibcage commented 2 years ago

I was actually just thinking of a Template Sensor as well! I will explore a few different options in that direction.....

Thanks for your quick response and all your hard work on this Integration/Helper!! 🙂

teamRibcage commented 2 years ago

Well, I'm happy to report that I have it working exactly as I had hoped it would!

I ended up creating two sensors that run behind the scenes to define the Start and End dates - this allows me to make parameters specific to each sensor, as well as easily change them later if needed. The Start sensor resets when the day changes, the End sensor resets at noon of its collection day. I then created a template sensor combining the two to use in the front end of HomeAssistant. End result, Heavy Pickup Week begins on Monday of the second full week of the month and lasts through noon on Friday.

heavy_pickup

template:
  - sensor
    - name: Heavy Pickup Week
      icon: mdi:dump-truck
      unique_id: heavypickupweek
      state: |
        {% if state_attr('sensor.heavy_pickup_start', 'days') == 1 %}
          Tomorrow
        {% elif state_attr('sensor.heavy_pickup_end', 'days') <= 4 %}
          This Week
        {% elif state_attr('sensor.heavy_pickup_start', 'days') >= 2 %}
          {{ states('sensor.heavy_pickup_start') }}
        {% else %}
          Calculating
        {% endif %}

Thanks again for your help!! 🙂