Scrape sensor value_template not working

Hi, I’m using scrape sensor to get the date and time of a soccer match from a web page.
I have a sensor that returns the date as “01 novembre 2020” and the time as “21:00”
I’ve tried

value_template: {{ strptime(states("sensor.sensor_name") %R") }} 

for the time but when i reboot instead of 21:00 i get unknown. Same thing for the date. Plus File Editor sometimes gives me some strange syntax error asking me to put a comma beetween % and d, like “%,d”.
What am i doing wrong? Thanks.

This might convert your scraped sensor to a datetime object but it’s hard to say, because you did not say how the date and time were combined or if the 24 hour was zero padded. Or if they are two sensors or one.

Assuming one sensor:

The first filter converts the month to title case ( novembre -> Novembre ).

The second line of the template assumed that your date and time sensor state looks like this:

01 novembre 2020 07:56

If it does not then this won’t work.

value_template: >
  {% set datetime = states('sensor.sensor_name')|title %}
  {{ strptime(datetime, '%d %B %Y %H:%M' ) }} 

If it does work you can then convert this datetime object to any format you want using timestamp_custom

If you have separate sensors for the time and date then try this:

value_template: >
  {% set date = states('sensor.sensor_scraped_date')|title %}
  {% set time = states('sensor.sensor_scraped_time') %}
  {{ strptime(date ~ ' ' ~ time, '%d %B %Y %H:%M' ) }} 

But again this wont work if your hours are not zero padded. For that you should use %-H instead of %H

Sorry, I should have been more specific, so i have two sensors, the first match_time, the second match_date. The first is:

- platform: scrape
  resource: https://www.livescore.it/calcio/italia/squadre/napoli/
  select: .match-time
  name: match_time
  value_template: >
    {% set time = states('sensor.match_time')|title %}
    {{ strptime(time, '%H:%M' ) }} 

that before adding “value_template” was returning me 21:00 and now returns unknown. I sincerly don’t know if it is zero padded since it’s 24 hour format and there are no upcoming matches before 12:00 PM.
The second is:

- platform: scrape
  resource: https://www.livescore.it/calcio/italia/squadre/napoli/
  select: .match-date
  name: match_date
  value_template: >
    {% set date = states('sensor.match_date')|title %}
    {{ strptime(date, '%d %B %Y' ) }} 

That before returned me 01 novembre 2020 and it is now returning unknown.

I’ve tried to adapt the code of your first response to them but with no success.

Ok, try this:

- platform: scrape
  resource: https://www.livescore.it/calcio/italia/squadre/napoli/
  select: .match-time
  name: match_time
  value_template: >
    {{ strptime(value, '%H:%M' ) }}
- platform: scrape
  resource: https://www.livescore.it/calcio/italia/squadre/napoli/
  select: .match-date
  name: match_date
  value_template: >
    {{ strptime(value|title, '%d %B %Y' ) }}

Thanks, now it works perfect. It shows the right time and date.
Do you know if i can make an automations that runs on that specific day something like 10 minutes before the time that the sensor gets from the page?
For example an automation that runs on 01 november 10/15 minutes before 21:00