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?
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.
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
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?