Problem with template sensor

I have a template sensor wich returns a date like 27-2-2019. The problem is that my date sensor returns 27-02-2019. One extra zero. I want a automation that gives me a notification when the date (pickup of paper) is today. Has somone a solution for me.

  • platform: template
    sensors:
    ophaaldag_papier:
    value_template: >-
    {% set strtext = states.sensor.papier.state.replace(‘Papier en Karton’,’ ') %} {{ strptime(strtext, ‘%a, %d %b %Y %H:%M:%S%z’) }}

  • condition: template
    value_template: >
    {% if is_state(‘sensor.ophaaldag_papier’,now().strftime("%d-%m-%Y")) %} True
    {% else %} False
    {% endif %}

please format your code snippets correctly when posting:

that said you should be able to change the %m in the template to %-m to remove the leading 0 from the month.

    condition: template
    value_template: >
      {% if is_state(‘sensor.ophaaldag_papier’,now().strftime("%d-%-m-%Y")) %} True
        {% else %} False
      {% endif %}

I can’t test it since I don’t have your sensor but i think it should work.

It was so simple. Thx for sharing this.

I now have these sensor and automation. I’ve test it with replacing the “sensor.ophaaldag_papier” for a custom time sensor in te same format (without zero). That works. So now I will wait until the next pickup on 27-02-2019. Then I’ll know for sure or my automation will work. :slight_smile:

  - platform: scrape
    resource: https://www.xxxxxx
    name: Papier
    select: "#CphContent_upPickUpDates > ul > li.papier"
    #value_template: "{{ value.split(':')[1]|replace('div', ' ')|trim }}"
    scan_interval: 21600  #6u
  - platform: template
    sensors:
      ophaaldag_papier:
        value_template: >-
         {% set strtext = states.sensor.papier.state.replace('Papier en Karton',' ') %} {{ strptime(strtext, '%a, %d %b %Y %H:%M:%S%z') }}


- id: papieraandewegzetten
  alias: 'Papier ophaaldag'
  initial_state: 'on' #on reboot HA or reloading of automations, automation is ON
  trigger:
    - platform: time
      at: 06:50:10
  condition:
    condition: and # all conditions need to be True before action is executed.
    conditions:    
      - condition: template # When dates are the same action is executed. 
        value_template: >
         {% if is_state('sensor.ophaaldag_papier',now().strftime("%d-%m-%Y")) %} True
         {% else %} False
         {% endif %}
  action:  
    - service: notify.pushallphones
      data:
        message: 'Het is vandaag {{ now().strftime("%d %B") }}. Zet de Papier Klikko aan de weg!'
        data:  
         push:
         attachment:
          url: https://hassiorxxxx.duckdns.org:8123/local/icons/ophaaldagklikko/papier1.png

Another question related to scraoe sensors. Is it possible to make a time window within the scrape sensor is working. I use more scrape sensors and some websites are not accessible during the night. And then I have a lot of errors in my log.

Regards. R.

Sorry I don’t use any scrape sensors so I have no idea.

Maybe someone who knows will pop in and help.

I have another challenge. I want also a trigger the day before mij garbage will be pickup. I’n struggling a few hours, and can’t figure it out. Can someone help me?

I’ve tried this:

value_template: '{{ now().strftime("%Y-%m-%d") == 
                         (as_timestamp(states.sensor.ophaaldag_gft.state) - 
                         (24*3600)) | timestamp_custom("%-d-%-m-%Y") }}'

But that doesn’t work unfortunately
Below my working example for the day my garbage will be pickup.

- condition: template # When dates are the same action is executed. 
        value_template: >
         {% if is_state('sensor.ophaaldag_papier',now().strftime("%d-%m-%Y")) %} True
         {% else %} False
         {% endif %}