Show template-sensor in lovelace entity-card?

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… :thinking:

The name is used for the entity_id, try another one.
Look in Dev Tools/states for the entity_id.

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.

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

You’re right, it makes no difference whether with or without space. :grinning:
Learned something too!

1 Like