Cangoou
November 24, 2023, 4:00pm
1
Hello!
I created a templates.yaml file and I include it like this in my configuration.yaml:
template: !include templates.yaml
Inside templates.yaml, I’m creating a sensor like this:
- sensor:
- unique_id: gasmeter_m3
name: Gasmeter m³
state: "{{ states ('counter.gas_counter') | float * 0.01 }}"
unit_of_measurement: m³
icon: mdi:meter-gas
device_class: gas
state_class: total_increasing
In my ui-lovelace.yaml, I added:
views:
- title: Gasmeter
path: gasmeter
cards:
- type: entities
entities:
- sensor.gasmeter_m3
But in my Dashboard, I only get an error:
Entity not available: sensor.gasmeter_m3
There are no errors or warnings in the log. Can’t figure out how to use the template to display a value in ui-lovelace…
VDRainer
(🍻)
November 24, 2023, 4:17pm
2
Cangoou:
name: Gasmeter m³
The name is used for the entity_id, try another one.
Look in Dev Tools/states for the entity_id.
VDRainer
(🍻)
November 24, 2023, 4:27pm
3
This is also wrong, remove the space after states.
state: "{{ states('counter.gas_counter') | float * 0.01 }}"
You can test your templates in Dev Tools/Templates
Just copy the part {{ states('counter.gas_counter') | float * 0.01 }}
in there and you will see what you get.
Cangoou
November 24, 2023, 4:42pm
4
Thanks for your help! The trick was that the name (not the unique id) becomes the entity_id.
The template works for me with our without space in the Dev Tools/Templates, but I removed it to be save.
1 Like
VDRainer
(🍻)
November 24, 2023, 5:16pm
5
You’re right, it makes no difference whether with or without space.
Learned something too!
1 Like