Help with Date template

Hi, I have a temple that will tell me the time difference since last changed state. It works fine when using it with the last changed attribute of the switch. Example here:

{%- set time = (as_timestamp(now()) - as_timestamp(states.switch.fireplace.last_changed)) | int  %}
{%- set minutes = ((time % 3600) // 60) %}
{%- set minutes = '{}minutes'.format(minutes) if minutes > 0 else '' %}
{%- set hours = ((time % 86400) // 3600) %}
{%- set hours = '{}hours '.format(hours) if hours > 0 else '' %}
{%- set days = (time // 86400) %}
{%- set days = '{}days '.format(days) if days > 0 else '' %}
{{ 'Less than 1 minute' if time < 60 else days + hours + minutes }} ago

However, I want to use an input_datetime rather than the last changed attribute so it will survive a restart. I can not figure out what is wrong, the following will not work:

{%- set time = (as_timestamp(now()) - (states.input_datetime.fireplace_on_timer)) | int  %}
{%- set minutes = ((time % 3600) // 60) %}
{%- set minutes = '{}minutes'.format(minutes) if minutes > 0 else '' %}
{%- set hours = ((time % 86400) // 3600) %}
{%- set hours = '{}hours '.format(hours) if hours > 0 else '' %}
{%- set days = (time // 86400) %}
{%- set days = '{}days '.format(days) if days > 0 else '' %}
{{ 'Less than 1 minute' if time < 60 else days + hours + minutes }} ago

It gives me the following error:
“TypeError: unsupported operand type(s) for -: ‘float’ and ‘TemplateState’”

Thanks

Try this:

{%- set time = (as_timestamp(now()) - (as_timestamp(states('input_datetime.fireplace_on_timer')))) | int  %}

Thank you!! That did it.