The New Default Values

I know, I am outdated :stuck_out_tongue:

But I am seeing a lot of errors in the Log files about missing default value (new HA version)

Error initializing 'template' trigger for 'Printer - HP OfficeJet Alert X Pages Remain': ValueError: Template error: int got invalid input 'unknown' when rendering template '{% if states('sensor.hp_officejet_8022_total_free_pages_remaining')|int == states('sensor.hp_officejet_8022_free_pages_remaining_notification')|int %} true {% endif %}' but no default was specified

And

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:356
First occurred: 23:51:27 (2 occurrences)
Last logged: 23:51:27

TemplateError('ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ states('sensor.hp_officejet_8022_pages_allowance_remaining')|int + states('sensor.hp_officejet_8022_pages_rollover_remaining')|int }}' but no default was specified') while processing template 'Template("{{ states('sensor.hp_officejet_8022_pages_allowance_remaining')|int + states('sensor.hp_officejet_8022_pages_rollover_remaining')|int }}")' for attribute '_attr_native_value' in entity 'sensor.hp_officejet_8022_total_free_pages_remaining'
TemplateError('ValueError: Template error: strptime got invalid input 'unknown' when rendering template '{{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d'))|int - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d'))|int ) / 86400)|int }}' but no default was specified') while processing template 'Template("{{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d'))|int - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d'))|int ) / 86400)|int }}")' for attribute '_attr_native_value' in entity 'sensor.hp_officejet_8022_allowance_days_remaining'

I do not know where (and what) I must place the default values in here, can someone please help me with this?

Thanks!

This may help:

1 Like

No default value specified:

int

Default value of zero:

int(0)
1 Like

Hi

I tried, but gives the same error ā€œno defaultā€

TemplateError('ValueError: Template error: strptime got invalid input 'unknown' when rendering template '{{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d'))|int(0) - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d'))|int(0) ) / 86400)|int(0) }}' but no default was specified') while processing template 'Template("{{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d'))|int(0) - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d'))|int(0) ) / 86400)|int(0) }}")' for attribute '_attr_native_value' in entity 'sensor.hp_officejet_8022_allowance_days_remaining'

need a default for that too

1 Like

Still an error

 {{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d', 0))|int(0) - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d', 0))|int(0) ) / 86400)|int(0) }}
TemplateError('ValueError: Template error: as_timestamp got invalid input '0' when rendering template '{{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d', 0))|int(0) - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d', 0))|int(0) ) / 86400)|int(0) }}' but no default was specified') while processing template 'Template("{{ ((as_timestamp(strptime(states('sensor.hp_officejet_8022_next_renewal_date'), '%Y-%m-%d', 0))|int(0) - as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d', 0))|int(0) ) / 86400)|int(0) }}")' for attribute '_attr_native_value' in entity 'sensor.hp_officejet_8022_allowance_days_remaining'

take a look and read your error

itā€™s probably best to just not use that template, many conversions.

{% set dt = states('sensor.hp_officejet_8022_next_renewal_date') | as_datetime or today_at() %}
{{ (dt | as_local - today_at()).days }}
1 Like

ā€œ0ā€ is not a correct timestamp it meens?

same as all the other errorsā€¦ youā€™ve made this change twice now. Take a second to read the full message:

TemplateError(ā€˜ValueError: Template error: as_timestamp got invalid input ā€˜0ā€™ when rendering template ā€˜{{ ((as_timestamp(strptime(states(ā€˜sensor.hp_officejet_8022_next_renewal_dateā€™), ā€˜%Y-%m-%dā€™, 0))|int(0) - as_timestamp(strptime(states(ā€˜sensor.dateā€™), ā€˜%Y-%m-%dā€™, 0))|int(0) ) / 86400)|int(0) }}ā€™ but no default was specifiedā€™) while processing template ā€˜Template("{{ ((as_timestamp(strptime(states(ā€˜sensor.hp_officejet_8022_next_renewal_dateā€™), ā€˜%Y-%m-%dā€™, 0))|int(0) - as_timestamp(strptime(states(ā€˜sensor.dateā€™), ā€˜%Y-%m-%dā€™, 0))|int(0) ) / 86400)|int(0) }}")ā€™ for attribute ā€˜_attr_native_valueā€™ in entity ā€˜sensor.hp_officejet_8022_allowance_days_remainingā€™

Your template appears to be trying to calculate the number of days remaining until a renewal date. The renewal date is the value of sensor.hp_officejet_8022_next_renewal_date. However, it seems like the value isnā€™t a date (thereby causing a problem for the calculation).

Go to Developer Tools > States, find sensor.hp_officejet_8022_next_renewal_date and tell us its value as shown in the States column.

Or just use the improved version of the template that Petro provided for you.

Status with error message:
2022-10-08

Status is correct correctā€¦

(I will do, but i try to understand it)

This is working, thanks!

Im afraid the whole template is to ā€˜oldā€™ or not good than.

Lots of no default values

# The number of allowance pages remaining for this period
# Calculated when each page is printed, and at the start of each new Instant Ink period
# "{% (if states('input_datetime.hp_officejet_8022_this_period_start_date') %}" is a workaround to set a listener)
    hp_officejet_8022_pages_allowance_remaining:
      friendly_name: "Allowance Pages Remaining"
      value_template: >-
        {% if states('input_datetime.hp_officejet_8022_this_period_start_date') %}
          {% if states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int - states('sensor.hp_officejet_8022_total_pages_printed')|int >= 0 %}
            {{ states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int - states('sensor.hp_officejet_8022_total_pages_printed')|int }}
          {% else %}
            0
          {% endif %}
        {% endif %}
#
# The number of rollover pages remaining for this period.
# Calculated when each page is printed, when the Rollover Allowance is reset, and at the start of each new Instant Ink period
    hp_officejet_8022_pages_rollover_remaining:
      friendly_name: "Rollover Pages Remaining"
      value_template: >-
        {% if states('input_datetime.hp_officejet_8022_this_period_start_date') %}
          {% if states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int - states('sensor.hp_officejet_8022_total_pages_printed')|int < 0 and states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int + states('input_number.hp_officejet_8022_pages_rollover_allowance')|int - states('sensor.hp_officejet_8022_total_pages_printed')|int >= 0 %}
            {{ states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int + states('input_number.hp_officejet_8022_pages_rollover_allowance')|int - states('sensor.hp_officejet_8022_total_pages_printed')|int }}
          {% elif states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int - states('sensor.hp_officejet_8022_total_pages_printed')|int < 0 and states('input_number.hp_officejet_8022_pages_at_month_start')|int + states('input_number.hp_officejet_8022_pages_monthly_allowance')|int + states('input_number.hp_officejet_8022_pages_rollover_allowance')|int -   states('sensor.hp_officejet_8022_total_pages_printed')|int < 0 %}
            0
          {% else %}
            {{ states('input_number.hp_officejet_8022_pages_rollover_allowance')|int }}
          {% endif %}
        {% endif %}

those are only single conversions. Your nested conversion was excessive is all I was saying. It was as_timestamp(strptime()) with an int. Thatā€™s 3 conversions with 3 required defaults. Where as the template I provided above was zero defaults and 1 conversion

1 Like

Thank you :slight_smile:

Last question, All those other templates, i have not set a default there, but it is not showing an error in the logs for themā€¦
Do i still need to set default? Or do i not need a default there?

youā€™ll need defaults on all the sensors, not the helpers

1 Like