jazzyisj / unavailable-entities-sensor

Unavailable entities template sensor for Home Assistant.
GNU General Public License v3.0
160 stars 21 forks source link

Sensor sensor.unavailable_entities has device class None, state class None #25

Closed edu24x closed 1 year ago

edu24x commented 1 year ago

Logger: homeassistant.components.sensor Source: components/sensor/init.py:605 Integration: Sensor (documentation, issues) First occurred: 17:36:18 (1 occurrences) Last logged: 17:36:18

Sensor sensor.unavailable_entities has device class None, state class None and unit entities thus indicating it has a numeric value; however, it has the non-numeric value: (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22

Home Assistant 2023.2.0 Supervisor 2023.01.1 Operating System 9.5 Frontend 20230201.0 - latest

jazzyisj commented 1 year ago

Thanks for the report. A lot of templates are throwing this warning during startup since updating to 2022.2. Not sure how to deal with it yet. I will update when I get it figured out.

knwpsk commented 1 year ago

I'm also seeing this in the Core logs. Maybe it's related to the same issue?

Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.unavailable_entities, old_state=<state sensor.unavailable_entities=unavailable; restored=True, icon=mdi:check-circle, friendly_name=Unavailable Entities, supported_features=0, unit_of_measurement=entities @ 2023-02-11T11:09:36.591734-05:00>, new_state=<state sensor.unavailable_entities=; entity_id=[], unit_of_measurement=entities, icon=mdi:check-circle, friendly_name=Unavailable Entities @ 2023-02-11T11:09:36.802754-05:00>>, **skipping template render for Template[{% if state_attr('sensor.unavailable_entities','entity_id') != none %} {{ state_attr('sensor.unavailable_entities','entity_id')|count }} {% endif %}]**

(FYI I have tinkered with the code since installing it; AND I have copied the code, modified, into a second template that monitors my various Pingtrackers. So, it's possible that somehow my 2nd copy is interfering with the original.... although I haven't been able to discern that this is true, nor why.)

jazzyisj commented 1 year ago

@edu24x I posted an updated template that should eliminate the error.

@knwpsk The template loop warning is unrelated. It also does not seem to affect the sensor function. Are you using the most recent version of the sensor template? How often are you seeing it in your logs? It doesn't come up in my logs very often any longer.

Did you see this?

A value for 'ignore_seconds' less than 5 seconds may cause template loop warnings in your home assistant log, particularly when template sensors are reloaded.

edu24x commented 1 year ago

@jazzyisj Thank you so much. The warning is fixed and the log is clean.

All the best.

knwpsk commented 1 year ago

@edu24x I posted an updated template that should eliminate the error.

@knwpsk The template loop warning is unrelated. It also does not seem to affect the sensor function. Are you using the most recent version of the sensor template? How often are you seeing it in your logs? It doesn't come up in my logs very often any longer.

Did you see this?

A value for 'ignore_seconds' less than 5 seconds may cause template loop warnings in your home assistant log, particularly when template sensors are reloaded.

Hey @jazzyisj , Thanks for your reply!

I don't see any more loop warnings. I deleted the other template that I had going (a mod'd copy of this one), and I think that did it. I think the two were interfering with each other b/c I was sloppy configuring the second one.

Bytelink5616 commented 1 year ago

Jazzy

I love this sensor and have used it for years. I have never bothered to update it but I thought with the advent of the deprecation of the platform: template etc I would download the latest version. I did this and now for some reason I cannot get it to work. I copied the code for the template into my configuration.yaml even though the old code was in a separate file. My old light one is still working as I have not updated it.

This is the only error I am getting in the log file

Logger: homeassistant.components.sensor Source: components/sensor/init.py:608 Integration: Sensor (documentation, issues) First occurred: 6:54:20 PM (1 occurrences) Last logged: 6:54:20 PM

Sensor sensor.unavailable_lights has device class None, state class None and unit lights thus indicating it has a numeric value; however, it has the non-numeric value: (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22

I am sorry to bother you as I am sure It is my error as the sensor has worked flawlessly for years well since I first installed it in 2021

Ian Robson Bytelink LLC. 5616 Devon Street Port Orange, FL 32127 (386) 235-9563 Cell

This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. The integrity and security of this message cannot be guaranteed on the Internet.

jazzyisj commented 1 year ago

@Bytelink5616 The simplest fix (and what was done in the latest update) is delete the unit of measurement parameter on your unavailable_lights sensor. HA core is getting picky about how you use it which is probably a good thing. Alternatively you can add a state_class: measurement to the template config if you really need the unit_of_measurement parameter for the UI or graphing. Either should fix the warning.

Bytelink5616 commented 1 year ago

Thankyou very much. I am so sorry to bother you again but I copied the sensor into my unavailable light sensor and renamed it etc but in the old sensor I was using I had the unit of measurement as light and that made it so I only showed the missing lights but I see it is not in the new one and was wondering where I needed to specify lights only.

Bytelink5616 commented 1 year ago

I thought it best if I sent you a copy of the old sensor I was using as it also had a line for the ignored light entities which I will also need to address

#######################################################################################################################

Unavailable Lights Sensor

Count and list entities with a state of unavailable

state: number of unavailable entities

attribute - entities: list object of unavailable entity ids

See README for customization options. https://github.com/jazzyisj/unavailable-entities-sensor/blob/main/README.md

#######################################################################################################################

platform: template sensors: unavailable_lights: unique_id: unavailable_lights friendly_name: 'Unavailable Lights' icon_template: "{{ 'mdi:alert-circle' if states('sensor.unavailable_lights')|int(0) > 0 else 'mdi:check-circle' }}" unit_of_measurement: lights value_template: > {% if state_attr('sensor.unavailable_lights','entities') != none %} {{ state_attr('sensor.unavailable_lights','entities')|count }} {% endif %} attribute_templates: entities: > {% set ignore_seconds = 60 %} {% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %} {{ states.light |rejectattr('entity_id','in',state_attr('group.ignored_light_entities','entity_id')) |rejectattr('last_changed','ge',ignore_ts) |rejectattr('entityid','search','group') |selectattr('state','in',['unavailable'])|map(attribute='entity_id')|list }}

Bytelink5616 commented 1 year ago

Do not worry I fixed it. I had not added the .light to the states and I had also rejected all the lights. Anyway it is up and running again. Once again thanks for a great product. It may also be worth noting in the documentation that you can change the states to add a particular domain such as lights.