I try to make use of the newly introduced availability_template.
This should get rid of errors at startup of hass. I struggle with nesting the value_template in the availability_template.
- platform: template
sensors:
days_gft:
availability_template: >-
{%- if not is_state("sensor.waste_gft", "unavailable") %}
value_template: >-
{% set days = (strptime(states('sensor.waste_gft'), '%Y-%m-%d').strftime('%j') | int) - now().strftime('%j') | int ) %}
{% if days == 0 %}
today
{% elif days == 1 %}
tomorrow
{% elif days >= 2 %}
in {{days}} days
{% else %}
not any time soon
{% endif %}
entity_id: date.time
{% else %}
not available
{% endif %}
Theyâre both options of a Template Sensor so either before or after availability_template: is fine.
sensor:
- platform: template
sensors:
my_sensor:
value_template: "{{ stuff related to the value_template }}"
availability_template: "{{ stuff related to the availability_template }}"
Can anyone help with this? I have been trying to prevent errors at start up for my template sensors. I have an energy monitoring switch that I am keeping stats on. At startup the sensors needed for this sensor are not yet available, so I need this template sensor to be âunavailableâ until they are ready. I donât understand why this isnât working. I get ZeroDivisionError: float division by zero error at startup for this sensor.
Iâve tested the template in the dev tools and if states('sensor.s31_energy_total_days') evaluates to âunknownâ or âunavailableâ then states('sensor.s31_energy_total_days')|int == 0. So this should work. What am I doing wrong here??
Oh, is the value_template still getting processed even if the availability_template returns false? That would make sense. I was assuming that if availability was false then the value_template would be ignored. Seems like an oversight.
I am struggling with exact the same point. I am trying to filter out enger spikes with the availibility template, but its state is simply ignored. (https://community.home-assistant.io/t/help-with-solving-engery-spike-with-availability-template-kindly-requested/509102/2
I wonder wheather a switch or somethings else needs to be implemented in order to make use of the availibilit template. The documentation for that switch is basically useless. As it is the sitch availability_template makes no sense at all to me.
Is it possible to filter the unknow state of a sensor and view all other states of the template? Sometimes the sensor goes unknow for a few seconds, I would like it not to be displayed, perhaps leaving the field blank.