Skip to content

Instantly share code, notes, and snippets.

@stboch
Last active February 2, 2022 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stboch/c93befde7a8699f90b8180e60283be40 to your computer and use it in GitHub Desktop.
Save stboch/c93befde7a8699f90b8180e60283be40 to your computer and use it in GitHub Desktop.
Garbage Collection Intergration - Blueprint script - For days of inclimate weather or otherwise canceled service where collection slide by offset
blueprint:
name: Slide Schedule in Affect
description: >-
Will slide the affected entities the variable number of days. Best used during inclimate weather.
domain: script
source_url: https://gist.github.com/stboch/c93befde7a8699f90b8180e60283be40
input:
garbage_collection_entity:
name: Garbage Collection Entity
description: Which entity to update.
selector:
entity:
integration: garbage_collection
offset:
name: Offset (number of days)
description: >-
Offset the collection by given number of days. This can be used
for example to schedule an event for the last Wednesday each month.
To do that, configuring it for first Wednesday each month and then offset by -7 days.
selector:
number:
min: -7
max: 7
mode: box
mode: parallel
variables:
garbage_entity: !input garbage_collection_entity
offset: !input offset
sequence:
- condition: template
value_template: |
{%- set collection_date = state_attr(garbage_entity,"next_date") %}
{%- set ns = namespace(found=false) %}
{%- for i in range(collection_date.weekday()+1) %}
{%- set d = ( collection_date + timedelta( days=-i) ) | as_timestamp | timestamp_custom("%Y-%m-%d") %}
{%- if d in now().strftime("%Y-%m-%d") %}
{%- set ns.found = true %}
{%- endif %}
{%- endfor %}
{{ ns.found }}
- service: garbage_collection.offset_date
data:
entity_id: '{{ garbage_entity }}'
date: '{{ state_attr(garbage_entity,"next_date").strftime("%Y-%m-%d") }}'
offset: |
{%- set collection_date = state_attr(garbage_entity,"next_date") %}
{%- set ns = namespace(offset=offset, found=false) %}
{%- for _ in range(7) if not ns.found %}
{%- set d = ( collection_date + timedelta( days=ns.offset) ) | as_timestamp | timestamp_custom("%Y-%m-%d") %}
{%- if d in now().strftime("%Y-%m-%d") %}
{%- set ns.offset = ns.offset + 1 %}
{% else %}
{%- set ns.found = true %}
{%- endif %}
{% endfor %}
{{ ns.offset }}
- service: garbage_collection.update_state
data:
entity_id: '{{ garbage_entity }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment