Template sensor : sensor entity not available

Hi Everyone,
I’ve entered in my sensors.yaml the following code :

- platform: template
  sensors:
    solar_angle:
      friendly_name: "Sun angle"
      unit_of_measurement: 'degrees'
      value_template: "{{ state_attr('sun.sun', 'elevation') }}"tate_attr('sun.sun', 'elevation') }}"

And in my ui-lovelace.yaml

views:
  - title: ACCUEIL
    cards:
      - type: sensor
        entity: sensor.solar_angle

when loading, I get the error : sensor entity not available
and when I look to the list of entities in the UI, this sensor is unknown.

Any suggestion?

You repeated part of the code at the end of the value template, remove everything after the double quotes.

Should be like this:

value_template: "{{ state_attr('sun.sun', 'elevation') }}"

You should also have an error under Configuration -> Logs

Sorry, it was an error in pasting the code, the effective code is

- platform: template
  sensors:
    solar_angle:
      friendly_name: "Sun angle"
      unit_of_measurement: 'degrees'
      value_template: "{{ state_attr('sun.sun', 'elevation') }}"

And there is no error in Configuration -> Logs

Do you have default_config or sun loaded?

2 Likes

Under Developer Tools -> States, is there an entity called sun.sun?

yes, I fave this entity sun.sun with the attributes :

next_dawn: 2021-01-08T07:04:51+00:00
next_dusk: 2021-01-07T16:52:21+00:00
next_midnight: 2021-01-07T23:59:22+00:00
next_noon: 2021-01-07T11:58:43+00:00
next_rising: 2021-01-08T07:40:23+00:00
next_setting: 2021-01-07T16:16:44+00:00
elevation: 14.48
azimuth: 149.97
rising: true
friendly_name: Sun

Hmm, can you try this:

value_template: "{{ state_attr('sun.sun', 'elevation') | float }}"

And you said you see the entity sensor.solar_angle under Developer Tools -> States?
You could also try commenting out the code, reload template entities and see if the entity disappears, if it doesn’t the entity has been condigured somewhere else as well.

I’ve changed the code but when loading, I still get the error : sensor entity not available
the sensor DID NOT appear under Developer Tools -> States, and it does not yet.

I have also tried several value_template, it does not any matter.

Ok, then the value template is not the problem.
Can you please show the include section for sensors in your configuration.yaml. And the sensors.yaml file as well.

Did other sensors work that you configured there or is this your first sensor setup in YAML?

It is the first time I try to define a template sensor
Here is the line for inclusion:

sensor: !include sensors.yaml

and the content of sensors.yaml

- platform: template
  sensors:
    solar_angle:
      friendly_name: "Sun angle"
      unit_of_measurement: 'degrees'
      value_template: "{{ state_attr('sun.sun', 'elevation') | float }}"

What’s that strange sign at the end of the include, is this a copy/past error?

sensor: !include sensors.yaml

Is sensors.yaml in the same directory as configuration.yaml and is the content you showed everything that you have in sensors.yaml?

I’m sorry, but I cannot see any strange character et the end of

sensor: !include sensors.yaml

Is sensors.yaml in the same directory as configuration.yaml
yes
and is the content you showed everything that you have in sensors.yaml?
yes

I have also tried to insert the content of sensors.yaml in ui-lovelace.yaml: the result is the same message.

Do you have more than 1 sensor section?

1 Like

No, this one is the only one.

did you save sensors.yaml? Is sensors.yaml actually named sensor.yaml? There’s not much else that can be wrong other than spelling errors on your end.

No, sensors.yaml is actually named sensors.yaml

I have other inclusions in ui-lovelace.yaml

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
switch: !include switches.yaml
light: !include lights.yaml
sensor: !include sensors.yaml

All others work fine!

Did you mean to say configuration.yaml?

Whelp, there’s a piece of information that you’re not providing because it should be working.

1 Like