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

[BUG] utility_meter shows to much decimals #41234

Closed
vistalba opened this issue Oct 4, 2020 · 7 comments
Closed

[BUG] utility_meter shows to much decimals #41234

vistalba opened this issue Oct 4, 2020 · 7 comments

Comments

@vistalba
Copy link

vistalba commented Oct 4, 2020

The problem

Utility_meter does show too much decimals (5 in my case). This wasn't the case before.
The input sensor the utility_mater's are based on does have onle 1 decimal as the smalles amount of rain it can detect is 0.3mm.

This doesn't make sense and it wasn't the case as I configured lovelace some weeks ago. The issue began this week.

image

utility_meter is based on this sensor:
image

Environment

  • Home Assistant Core release with the issue: 0.115.6
  • Last working Home Assistant Core release (if known): -
  • Operating environment (OS/Container/Supervised/Core): OS
  • Integration causing this issue: utility_meter
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/utility_meter/

Problem-relevant configuration.yaml

# utility_meter.yaml
  hourly_regen_garten:
    source: sensor.garten_regenmenge
    cycle: hourly
  daily_regen_garten:
    source: sensor.garten_regenmenge
    cycle: daily
  weekly_regen_garten:
    source: sensor.garten_regenmenge
    cycle: weekly
  monthly_regen_garten:
    source: sensor.garten_regenmenge
    cycle: monthly
  quarterly_regen_garten:
    source: sensor.garten_regenmenge
    cycle: quarterly
  yearly_regen_garten:
    source: sensor.garten_regenmenge
    cycle: yearly
### sensor.yaml
  - platform: mqtt
    state_topic: "rtl_433/5/rain_mm"
    name: "Garten Regenmenge"
    unit_of_measurement: "mm"
    expire_after: 600
### lovelace config
type: entities
entities:
  - entity: sensor.hourly_regen_garten
    name: letzte Stunde
  - entity: sensor.daily_regen_garten
    name: Heute
  - entity: sensor.weekly_regen_garten
    name: diese Woche
  - entity: sensor.monthly_regen_garten
    name: laufender Monat
  - entity: sensor.quarterly_regen_garten
    name: laufendes Quartal
  - entity: sensor.yearly_regen_garten
    name: laufendes Jahr
title: Niederschlagsmengen
state_color: false

Traceback/Error logs

I don't know if this error has to do with this as I use utility_meter for other measurements/sensors too (e.g. power meters).

Logger: homeassistant.components.utility_meter.sensor
Source: components/utility_meter/sensor.py:165
Integration: Utility Meter (documentation, issues)
First occurred: 19:53:27 (12 occurrences)
Last logged: 19:53:32

Invalid state ( > ): [<class 'decimal.ConversionSyntax'>]
Invalid state ( > 13.1): [<class 'decimal.ConversionSyntax'>]

Additional information

@probot-home-assistant
Copy link

Hey there @dgomes, mind taking a look at this issue as its been labeled with an integration (utility_meter) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@dgomes
Copy link
Contributor

dgomes commented Oct 4, 2020

Well that error is not normal (Invalid state) and it is caused by the source sensor (sensor.garten_regenmenge) that has an empty string in the topic, your should fix that in the sensor.

About the decimals, python is very tricky about this... you probably received a value in that mqtt topic with a very high precision (or simply an error that was poorly interpreted by python when converting to a decimal), the system will propagate that precision indefinitely...

@vistalba
Copy link
Author

vistalba commented Oct 4, 2020

The source sensor only can increase by 0.3.

So possible values are always like:

0.0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1, ... and so on.
There is never more than 1 decimal in the source sensor. Otherwise I would just use the round(1) function as value_template on the source sensor.

@dgomes
Copy link
Contributor

dgomes commented Oct 4, 2020

I understand your viewpoint, and you expect that to happen. But the errors:

Invalid state ( > ): [<class 'decimal.ConversionSyntax'>]
Invalid state ( > 13.1): [<class 'decimal.ConversionSyntax'>]

tell me otherwise... even if sporadically, there is something strange with your sensor.

From the MQTT topic "rtl_433" I take it you are receiving this from a weather station over a 433Mhz radio link. These links are prone to errors, usually besides the weather readings there is usually also a checksum field that can be used to validate that the received information is correct (well at least with my Chinese no brand weather station :) )

@vistalba
Copy link
Author

vistalba commented Oct 5, 2020

@dgomes

Yes, I use rtl_433 with a rtl-sdr dongle to receive weather station (rtl433 type -R 32).
There is a CRC value looks like this: mic = CRC
I don't know how it will look like if CRC fails. Until know I thought that rtl_433 will already sort out stuff that didn't pass CRC check. Is that not the case?

Could you show me your mqtt sensor conf as an example?

Also I think about make utility_meter more robust. Why this happens at all? I think utility_meter shouldn't do anything if the source sensor is reporting wrong/strange values or is unknown/unavailable?

In addition i tried now the following:

  - platform: mqtt
    state_topic: "rtl_433/5/rain_mm"
    name: "Garten Regenmenge"
    unit_of_measurement: "mm"
    expire_after: 600
    value_template: "{{ value | float }}"

I think with this value_template the sensor shouldn't report anything if there is no valid digit in the value received from rtl_433.
Unfortunatly this doens't help at all. May I should change to value_template: "{{ value | float | round(1) }}" to also make sure input is always with max 1 decimal?

Edit:
This is how it looks in mqtt explorer:
image

As you can see there is only the value mic = CRC so I think this value means that the received stuff passes the CRC check of rtl_433. Is this correct?

@dgomes
Copy link
Contributor

dgomes commented Oct 5, 2020

I'm not so sure about rtl-433, I use a diy decoder based on an Arduino (https://github.com/dgomes/homeGW) in my code I do handle the CRC before publishing into the MQTT broker. So my configuration is very similar to yours.

I also have a issues with values that are properly transmitted but make no sense! for that I use the filter integration https://www.home-assistant.io/integrations/filter/

Here's my configuration to filter bad values from my weather station:

- platform: filter
  name: "Temperatura Exterior"
  entity_id: sensor.temp_out
  filters:
    - filter: outlier
      window_size: 4
      radius: 5

- platform: filter
  name: "Humidade Exterior"
  entity_id: sensor.humidity_out
  filters:
    - filter: outlier
      window_size: 4
      radius: 20

Your template will fix some errors, but not those outliers that happen not too often.

@vistalba
Copy link
Author

vistalba commented Oct 5, 2020

I investigated this issue again and added a history to the source sensor sensor.garten_regenmenge and I can see that sometimes HA really receives results with much decimals. Really no clue why this happens.

image

So I think value_template: "{{ value | float | round(1) }}" on mqtt sensor should solve this and I will try this now. Unfortunatly I've to wait for some rain ;)

I also now monitor the mqtt broker to see which values he is receiving.

Edit:
Now it happens... and I can see that rtl_433 does really report 99.60001 to mqtt broker.
image

So I will close this issue here, as it isn't a issue in utility_meter or homeassistant at all.
Thanks for support! :D

@vistalba vistalba closed this as completed Oct 5, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants