i will use a esp32 with Tasmota 13.0.0 flashed and a SR04 distance sensor connected to measure the volume of my oiltank. Tasmota works fine and i already have the distance entity of the sensor. In the developer tools i tested the syntax for the calucation but i am not able to put it in the configuration.yaml and get the new entities to work. I use the latest version of Home Assistant running on a VM on my NAS. This is the test from the developer tools which works:
{% set sensor = {
"oilmeter_sr04_distance": 6,
"oilmeter_100percent": 4050,
"oilmeter_liter": 3915
} %}
sensor.oilmeter_liter
{{ (75*75*(180 - sensor.oilmeter_sr04_distance))/1000*4 }}
sensor.oilmeter_percent
{{ 100 / sensor.oilmeter_100percent * sensor.oilmeter_liter }}
This is my attempt in the configuration.yaml
template:
- sensor:
# Füllstand in Liter
- name: oilmeter_liter
unique_id: oilmeter_liter
unit_of_measurement: "L"
state: >-
{{ (75*75*(180 - states('sensor.oilmeter_sr04_distance')))/1000*4 }}
- sensor:
# Füllstand in Prozent
- name: oilmeter_percent
unique_id: oilmeter_percent
unit_of_measurement: "%"
state: >-
{{ 100 / 4050 * states('sensor.oilmeter_liter') }}
I think its “just” a problem with the syntax but even after hours try to find the correct syntax it wont work. Please give me a tip what is wrong. thx in advance
thx for your fast reply. I try to fix it. I dont thinks there is a space or something else to much or less. I think “states” in front of the sensor cause the problem.
Hopping onto the back of this one, as it seems relevant. I’m trying to create (or modify, don’t mind which) another sensor by adding two days from a sensor containing a date “2023-07-26”.
Is the principle the same, as I don’t think I’m even near being right and don’t understand how I’d apply this to a date.
This is what I’ve currently got in the template too but it fails with TemplateSyntaxError: expected token ‘)’, got ‘string’
{% set tomoz = (states'sensor.tracker_date_tomorrow') + timedelta(days=2) %}