Separate Waste Collection

Good morning everyone,
I used this project
[Garbage card for home assistant]
(GitHub - Simonz82/ha_garbage: Garbage card for home assistant)

- platform: template
  sensors:
    raccoltadifferenziata:
      entity_id: sensor.date
      friendly_name: "Dalle ore 20 alle 07" #Orario di conferimento
      value_template: >-
        {% if now().weekday() == 6 -%}
          Nulla
        {%- elif now().weekday() == 0 -%}
          Organico
        {%- elif now().weekday() == 1 -%}
          Plastica
        {%- elif now().weekday() == 2 -%}
          Carta
        {%- elif now().weekday() == 3 -%}
          Organico e resto
        {%- elif now().weekday() == 4 -%}
          Vetro
        {%- elif now().weekday() == 5 -%}
          Nulla
        {%- endif %}

I added the first edit to exclude some months and it works.

sensor:
- platform: template
  sensors:
    raccoltadifferenziata:
      entity_id: sensor.date
      friendly_name: "Dalle ore 20 alle 24" #Orario di conferimento
      value_template: >-
        {% if now().weekday() == 6 -%}
          Nulla
        {%- elif now().weekday() == 0 -%}
          Organico
        {%- elif now().weekday() == 1 -%}
          Nulla
        {%- elif now().weekday() == 2 -%}
          Secco
        {%- elif now().weekday() == 3 -%}
          Nulla
        {%- elif now().weekday() == 4 -%}
          {% if now().month in [1,2,12] -%}
            Nulla
          {% else -%}
            Organico
          {%- endif %}
        {%- elif now().weekday() == 5 -%}
          Nulla
        {%- endif %}

As an answer he must give:
Nulla
Organico

Then I tried to put a helper to disable the warning, but it doesn’t work well because it doubles the names:
Organico Organico
Organico Nulla

sensor:
- platform: template
  sensors:
    raccoltadifferenziata:
      entity_id: sensor.date
      friendly_name: "Dalle ore 20 alle 24" #Orario di conferimento
      value_template: >-
        {% if now().weekday() == 6 -%}
          Nulla
        {%- elif now().weekday() == 0 -%}
          Organico
        {%- elif now().weekday() == 1 -%}
          Nulla
        {%- elif now().weekday() == 2 -%}
          Secco
        {%- elif now().weekday() == 3 -%}
          Nulla
        {%- elif now().weekday() == 4 -%}
          {% if now().month in [1,2,12] -%}
            Nulla
          {% else -%}
            Organico
          {%- endif %}
          {% if is_state('input_boolean.reset_raccolta_differenziata', 'on') -%}
            Nulla
          {% else -%}
            Organico
          {%- endif %}
        {%- elif now().weekday() == 5 -%}
          Nulla  
        {%- endif %}
    

Let me start by saying that I am a beginner, can someone explain to me where I am going wrong?
Thanks

Can you explain how the helper’s state is supposed to relate to the other conditions?

I try to explain better,
as a final it must give:
Nulla
or
Organico

if it falls in months 1-2-12
it must give Nulla, in the other months Organico

the assistant is used to manually force Nulla if necessary

the problem that adds the 2 words

Should it override all other conditions (weekday, month, etc) or only the extra conditions for Fridays?

only for friday

sensor:
- platform: template
  sensors:
    raccoltadifferenziata:
      friendly_name: "Dalle ore 20 alle 24" #Orario di conferimento
      value_template: >-
        {% set wd = now().weekday() %}
        {% set flag_on = is_state('input_boolean.reset_raccolta_differenziata', 'on') %}
        {% if wd in [1,3,5,6] -%}
          Nulla
        {%- elif wd == 0 -%}
          Organico
        {%- elif wd == 2 -%}
          Secco
        {%- elif wd == 4 and flag_on -%}
          Nulla
        {% else %}
          {{ 'Nulla' if now().month in [1,2,12] else 'Organico'-}}
        {%- endif %}

Seems to work fine
thanks

Excuse me
Works fine with wd == 4,
but I made a mistake.
input_boolean.reset_raccolta_differenziata
it also has to work
wd == 0
wd == 2
Without time constraints

Thank


I tried this trick and it seems to work.
I will try it for a week and let you know.
Thanks

sensor:
- platform: template
  sensors:
    raccoltadifferenziata:
      entity_id: sensor.date
      friendly_name: "Dalle ore 20 alle 24" #Orario di conferimento
      value_template: >-
        {% set wd = now().weekday() %}
        {% set flag_on = is_state('input_boolean.reset_raccolta_differenziata', 'on') %}
        {% if wd in [1,3,5,6] -%}
          Nulla
        {%- elif wd == 0 and flag_on -%}
          Nulla
        {%- elif wd == 0 -%}
          Organico
        {%- elif wd == 2 and flag_on -%}
          Nulla
        {%- elif wd == 2 -%}
          Secco
        {%- elif wd == 4 and flag_on -%}
          Nulla
        {% else %}
          {{ 'Nulla' if now().month in [1,2,12] else 'Organico'-}}
        {%- endif %}