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: Add a cutoff hour for first upcoming sensor #522

Open
TASSDevon opened this issue Nov 7, 2024 · 1 comment
Open

Feature request: Add a cutoff hour for first upcoming sensor #522

TASSDevon opened this issue Nov 7, 2024 · 1 comment

Comments

@TASSDevon
Copy link

TASSDevon commented Nov 7, 2024

Situation:

Today there is a cardboard pickup, the first upcoming sensor will display this until 23:59:59.
Usually the garbage collection truck comes around by 13h, I'd like to be able to set a cutoff time so that the first upcoming sensor starts displaying the next pickup after this cutoff hour as the cardboard collection event has passed.
This is very useful if there is another collection the day after, as currently the cardboard collection would "hide" the collection event for the day after.

Hope this makes sense.

Thanks

@Simanias
Copy link

Simanias commented Dec 22, 2024

Okey you can do this via this template sensor:

sensor:
  - platform: template
    sensors:
      upcoming_waste:
        friendly_name: "Upcoming Waste"
        value_template: >
          {% set tomorrow = (now() + timedelta(days=1)).strftime('%Y%m%d') %}
          {% set current_hour = now().hour %}
          
          {% set waste_tomorrow = "No waste tomorrow" %}
          
          {# Only check for tomorrow's waste if it's 13 PM or later #}
          {% if current_hour >= 13 %}
            {% for sensor in states.sensor if sensor.entity_id.startswith('sensor.gad_') %}
              {% set sort_date = state_attr(sensor.entity_id, 'Sort_date') %}
              {% if sort_date == tomorrow %}
                {% set friendly_name = state_attr(sensor.entity_id, 'friendly_name') %}
                {% set waste_type = 'GFT' if 'gft' in friendly_name.lower() else
                                    'Papier' if 'papier' in friendly_name.lower() else
                                    'PMD' if 'pmd' in friendly_name.lower() else
                                    'Restafval' %}
                {% set waste_tomorrow = "Tomorrow: " ~ waste_type %}
              {% endif %}
            {% endfor %}
          {% endif %}
          
          {# If it's 13 PM or later and waste for tomorrow is found, show it #}
          {% if current_hour >= 13 and waste_tomorrow != "No waste tomorrow" %}
            {{ waste_tomorrow }}
          
          {# If there's no waste for tomorrow, show the value of sensor.gad_upcoming #}
          {% else %}
            {{ states('sensor.gad_upcoming') }}
          {% endif %}

Please make sure to change this code to match the name of your garbage collection sensors. My all start with 'gad', because that is my garbage collector.

  • Change sensor.gad_ in: {% for sensor in states.sensor if sensor.entity_id.startswith('sensor.gad_') %} to match the name of your collector
  • Check which waste types you have and change, add, or remove in: {% set waste_type = 'GFT' if 'gft' in friendly_name.lower() else 'Papier' if 'papier' in friendly_name.lower() else 'PMD' if 'pmd' in friendly_name.lower() else 'Restafval' %}. It checks for the lowercase value, e.g. 'gft' and changes this into 'GFT', because before this reformatting, the garbage collector is also shown in this value, e.g. 'Gad gft' and we don't want the first part to show.
  • Change {# Only check for tomorrow's waste if it's 13 PM or later #} {% if current_hour >= 13 %}and {% if current_hour >= 13 and waste_tomorrow != "No waste tomorrow" % to your cut-off time.
  • Change sensor.gad_upcoming in {{ states('sensor.gad_upcoming') }} to match the name of your sensor for the first upcoming collection.

Good luck!

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

No branches or pull requests

2 participants