Template Variable Error but it actually works

I have the below template for BINs putting out and it states the number of days to the next time I have to put the bins out unless its less than 7 days and it says the day then.

Why does Home Assistant keep throwing this up as an error in my logs ?

Thanks Martyn

Template variable error: 'str object' has no attribute 'strftime' when rendering '{% set daystogo = strptime(states('sensor.green_bin_2'), "%Y-%m-%d %H:%M:%S").strftime("%A") %} {% set daystogo2 = strptime(states('sensor.green_bin_2'), "%Y-%m-%d %H:%M:%S").strftime("%b %d, %Y") %} {% if as_timestamp(states('sensor.green_bin_2')) / 86400 - as_timestamp(as_timestamp(states.sensor.time.last_updated) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 < 1.0 %} TODAY {% elif as_timestamp(states('sensor.green_bin_2')) / 86400 - as_timestamp(as_timestamp(states.sensor.time.last_updated) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 1.0 %} TOMORROW {% elif as_timestamp(states('sensor.green_bin_2')) / 86400 - as_timestamp(as_timestamp(states.sensor.time.last_updated) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 >= 7.0 %} {{ (as_timestamp(states('sensor.green_bin_2')) / 86400 + 1 - as_timestamp(states.sensor.time.last_updated) / 86400) | int }} days {% else %} {{ daystogo }} {% endif %}'```

Check the history of sensor.green_bin_2.
It is likely not a date sometimes (“unavailable”?)