I have tried to show volume or litres but just get unavailable also errors when trying to use gauge. Dashboard card shows adc and median voltages. Using a Shelly-Uni and is showing adc voltage. Sensor 0-10Volts. Yaml shows no errors. Is there errors in the yaml. Code as follows
- platform: template
sensors:
tank_one_litres_shelly:
value_template: >
state:"{% set voltage = states('sensor.tank_one_level_median_voltage')|float %}"
"{{ ((voltage / 10.0) * 1023)|round(0) }}"
unit_of_measurement: L
unique_id: tank_one_litres
- platform: statistics
name: "tank one level median voltage"
entity_id: sensor.tank_one_adc
state_characteristic: median
max_age:
hours: 2
precision: 2type or paste code here
Hi Troon again many thanks for your time and expertise. In anwser to your question “What do you want to do with the tank_one_adc value” I want a litres output. However I am getting a litres output from the original yaml. I have two tanks both outputting tank volume in litres. Now trying to put a custom canvas card gauge onto dashboard via HACS. Thank you.
Hi Troon
I put the revised code into Developers template all ok and returned number of liters. Put the code into config yaml got the following error (duplicate mapping key, refers to the line unit_of_ measurement). Developer Tools returns error (Invalid config for temlpate) . On a totally different subject can you explain why when I downloaded from HACS custom canvas card I get the error in Developer Tools (Intergration error intergration’cards’ not found, intergration ‘type’ not found).
Your template: needs to be in the first, left-most column — same (non-)indentation as the sensor: that you hopefully have before the config you posted.
Then you need to move your statistics sensor config up to sit under sensor: not under template:.
Your upper two legacy-format template sensors (tank_one_litres_shelly and tank_two_litres_shelly) are still wrong and need fixing or removing.
Hi Troon
I tried what you suggested with regard to the change of indentation and (tank_one_litres_shelly and tank_two_litres__shelly) and returns errors in
Developer Tools. I do not understand what you mean by Then you need to move your statistics sensor config up to sit under sensor: not under template: . The following is my config ymal in full.
sensor:
[ things that belong under "sensor"
like legacy template sensors and
statistics sensors ]
template:
[ modern format template sensors]
Here’s the relevant bit of your config, re-written (obviously, without any sort of checking or testing as this is just a forum post and not my system). Notes:
no friendly_name in modern format config: always check against the docs.
Look at the start of the template: section: it’s template: then a YAML list of sensors (and others if needed), not the legacy-format sensors:.
You had two unit_of_measurement: lines in your commented-out modern-format template sensor, which was the cause of that error.
You also had a tab character in name: "Tank One" — don’t do that
I’ve added a random unique_id to your template sensor: it’s good to have one but it doesn’t need to mean anything. I use this to generate them.
sensor:
- platform: template
sensors:
temperature_difference:
unit_of_measurement: '°C'
value_template: >
{{ states('sensor.panel')|float - states('sensor.tank')|float }}
- platform: template
sensors:
tank_one_litres_shelly:
value_template: >
{% set voltage = states('sensor.tank_one_level_median_voltage')|float %}
{{ ((voltage / 10.0) * 1000)|round(0) }}
unit_of_measurement: L
unique_id: tank_one_litres
- platform: template
sensors:
tank_two_litres_shelly:
value_template: >
{% set voltage = states('sensor.tank_two_level_median_voltage')|float %}
{{ ((voltage / 10.0) * 900)|round(0) }}
unit_of_measurement: L
unique_id: tank_two_litres
- platform: statistics
name: "tank two level median voltage"
entity_id: sensor.tank_two_adc
state_characteristic: median
max_age:
hours: 2
precision: 2
- platform: statistics
name: "tank one level median voltage"
entity_id: sensor.tank_one_adc
state_characteristic: median
max_age:
hours: 2
precision: 2
template:
- sensor:
- name: "Tank One litres"
unit_of_measurement: L
device_class: volume_storage
unique_id: f755d953-3744-4c5b-9d7c-ee1542e44b8a
state: >
{% set voltage = states('sensor.tank_one_level_median_voltage') | float %}
{{ ((voltage / 10.0) * 1000) | round (0) }}