Projected end date template fails

I have this template to predict if I am going to run out of data on my broadband plan:

- platform: template
  sensors:
    projected_end:
      friendly_name: 'Projected End Date'
      value_template: >
        {% set next_start_ts = as_timestamp(state_attr('sensor.abb_usage', 'nextRollover'))  %}
        {% set total_sec = state_attr('sensor.abb_usage', 'daysTotal')|int  * 86400  %}
        {% set sec_left =  86400 * states('sensor.total_days')|int * (states('sensor.total_gb')|float / states('sensor.projected_use')|float) %}
        {{ (next_start_ts - total_sec + sec_left)|timestamp_custom('%A %-d %B %Y at %X', True) }}

In the template editor it resolves perfectly:
Screenshot_2020-09-21 Developer Tools - Home Assistant(1)

However in the Lovelace frontend I get Unknown and in the log, this error:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 469, in async_device_update
    await self.async_update()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 299, in async_update
    self._async_update()
TypeError: 'NoneType' object is not callable

Calling the update entity service does not help.

Any idea why this is happening?

The Entities card has the correct entity:

entities:
  - entity: sensor.myip
  - entity: sensor.last_updated
  - entity: sensor.next_rollover
  - entity: sensor.projected_end

Solution:

value_template: >
  {% if states('sensor.used_days') not in [ '0', 'Unavailable', 'None', 'Unknown' ] %}
    {% set gb_per_day = states('sensor.used_gb')|float / states('sensor.used_days')|float %}
    {% set proj_days_left = states('sensor.remaining_gb')|float / gb_per_day %}
    {% set proj_end_date = ( as_timestamp( states('sensor.date') ) + proj_days_left * 86400 )|timestamp_custom('%-d %b %Y') %}
    {{ proj_end_date }}
  {% else %}
    N/A
  {% endif %}