I am guilty of not paying attention for at least 6 months (because life gets in the way sometimes) and therefore have been caught out - the hard way.
I have installed the hacs legacy template tool and read through the documentation and this post in it’s entirety. However, as you can guess I can’t get past whatever syntax issue is breaking my install and so I am wondering if some kindly soul can put me out of my misery !
I use packages - because of the advantages. Maybe that is why the legacy template fixing tool generated nothing, I don’t know.
I define packages like this:
homeassistant:
packages: !include_dir_named packages
in batteries.yaml in the packages directory I have 10 batteries defined which worked fine until Thursday. The first two of the repeating syntax for all 10 is below.
The relative time stamp is working fine, it is only the actual voltage which is showing “unavailable” but it is present, read on.
## Batteries ##
template:
# Garden Relay Battery Volts
- trigger:
- platform: state
entity_id: sensor.garden_battery_volts_mqtt
sensor:
- name: garden_battery_volts_calc
unique_id: 48a18864-99df-473e-841e-4faad4267333
device_class: voltage
state_class: measurement
unit_of_measurement: "V"
state: >-
{% set status = states('sensor.garden_battery_volts_mqtt') %}
{% if status is not none and status != 'unknown' and status != 'unavailable' %}
{{ ((status |float -0.005) * 5) | round(3) }}
{% else %}
unavailable
{% endif %}
- sensor:
- name: "Garden Battery Relative Timestamp"
state: >
{% set ts = states('sensor.garden_battery_volts_timestamp') %}
{% if ts != 'unknown' and ts != 'unavailable' %}
{{ relative_time(ts | as_datetime) }}
{% else %}
n/a
{% endif %}
# Tractor Battery Volts
- trigger:
- platform: state
entity_id: sensor.tractor_battery_volts_mqtt
sensor:
- name: tractor_battery_volts_calc
unique_id: b42551ec-e9c8-4a44-b01b-82d9f5275824
device_class: voltage
state_class: measurement
unit_of_measurement: "V"
state: >-
{% set status = states('sensor.tractor_battery_volts_mqtt') %}
{% if status is not none and status != 'unknown' and status != 'unavailable' %}
{{ ((status |float -0.005) * 5) | round(3) }}
{% else %}
unavailable
{% endif %}
- sensor:
- name: "Tractor Battery Relative Timestamp "
state: >
{% set ts = states('sensor.tractor_battery_volts_timestamp') %}
{% if ts not in ['unknown', 'unavailable', 'none'] %}
{{ relative_time(ts | as_datetime) }}
{% else %}
unknown
{% endif %}
In the same batteries file are all the sensors which read the values from MQTT so that I can use force_update: true. This stale update logic is not possible elsewhere in HA for clear and good reasons, but I need it hence the design employed.
I have tried syntax changes with templates: template keyword changed to fix this and while all of these pass the YAML configuration test before the restart and appear to conform, they do not actually generate a state value for the entity.
These state jinja code blocks return fine in template test tool - so I KNOW its my template syntax and not my jinja syntax which is now broken.
{% set status = states('sensor.tractor_battery_volts_mqtt') %}
{% if status is not none and status != 'unknown' and status != 'unavailable' %}
{{ ((status |float -0.005) * 5) | round(3) }}
{% else %}
unavailable
{% endif %}
I am asking for help because my packages format with the relevant helper keyword type defined in each package file adds just enough dissimilarity from the examples and docs to generate these types of issue.
Thanks in advance and apologies for what will doubtless be irritatingly obvious to you.