Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A specific case creates ValueError #46

Open
r-jean-pierre opened this issue Apr 15, 2024 · 1 comment
Open

A specific case creates ValueError #46

r-jean-pierre opened this issue Apr 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@r-jean-pierre
Copy link

Hi,

I have for several month a sensor constructed such as:

- platform: attributes
  friendly_name: "Last Month"
  attribute: "Last month"
  device_class: energy
  unit_of_measurement: "kWh"
  round_to: 1
  entities:
    - sensor.myenedis_xxx

and some other with the same philosophy

Recently, in the log, I receive a lot of:

2024-04-14 11:31:57.457 ERROR (MainThread) [custom_components.attributes.sensor] Could not attribute sensor for sensor.myenedis_xxx: ValueError: Template error: float got invalid input 'None' when rendering template '{% if states('sensor.myenedis_xxx') != 'unknown' and states('sensor.myenedis_xxx') != 'unavailable' %}{{ (state_attr('sensor.myenedis_xxx', 'Last month') | float) | round(1) }}{% else %} unknown {% endif %}' but no default was specified

which is quite understandable, the sensor sometimes outputs None

Is there a way to avoid it?

@pilotak
Copy link
Owner

pilotak commented Apr 26, 2024

Yes, there is. The code needs adjustments

@pilotak pilotak added the bug Something isn't working label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants