I’m still very much learning HA, and need some advice on my first manual template sensor.
Rather than editing configuration.yaml, I’ve tried to follow the guides to support individual sensor and template files.
In configuration.yaml:
sensor: !include_dir_list sensors/
template: !include_dir_list templates/
I created a folder for sensors and templates off \homeassistant\ and its parsing the files.
The first file I have created is a template sensor to record my daily oil usage:
state:
sensor:
name: 'Daily oil used'
entity_id: 'sensor.daily_oil_used'
unit_of_measurement: L
device_class: volume
state_class: measurement
state: >-
{% set current_oil_level = states('number.oil_oil_remaining_litres') | float(0) %}
{% set daily_oil_used = input_number.oil_tank_capacity - current_oil_level | float(0) %}
{{ '{:.2f}'.format(daily_oil_used) }}
I have tried multiple different versions of this file and I am clearly missing something. Error message is currently:
Logger: homeassistant.config
Source: config.py:357
First occurred: 13:24:25 (27 occurrences)
Last logged: 14:05:20
* Invalid config for 'template' at templates/oil_daily_oil_used.yaml, line 1: expected a dictionary '', got [{'sensor': [{'name': 'Daily oil used', 'entity_id': 'sensor.daily_oil_used', 'unit_of_measurement': 'L', 'device_class': 'volume', 'state_class': 'measurement', 'state': "{% set current_oil_level = states('number.oil_oil_remaining_litres') | float(0) %} {% set daily_oil_used = input_number.oil_tank_capacity - current_oil_level | float(0) %} {{ '{:.2f}'.format(daily_oil_used) }}"}]}]
* Invalid config for 'template' at templates/oil_daily_oil_use.yaml, line 1: 'entity_id' is an invalid option for 'template', check: sensor->0->entity_id
* Invalid config for 'template' at templates/oil_daily_oil_used.yaml, line 1: 'entity_id' is an invalid option for 'template', check: sensor->0->entity_id
* Invalid config for 'template' at templates/oil_daily_oil_used.yaml, line 1: 'state' is an invalid option for 'template', check: state Invalid config for 'template' at templates/oil_daily_oil_used.yaml, line 2: 'entity_id' is an invalid option for 'template', check: sensor->0->entity_id
* Invalid config for 'template' at templates/oil_daily_oil_used.yaml, line 1: 'state' is an invalid option for 'template', check: state
I was also hoping to add some more to the sensor, to check availability of the input value. I can’t do that until I get this working.
Part of the issue may be that I have been reading other posts, some a few years old, and they may not be correct any more.