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

Problem with propagation of temperature unit when averaging a statistics helper #185

Open
Gyosa3 opened this issue Feb 27, 2023 · 0 comments
Labels
bug Something isn't working.

Comments

@Gyosa3
Copy link

Gyosa3 commented Feb 27, 2023

Environment

  • Home Assistant Core release with the issue: 2023.2.5
  • This custom component release with the issue: 2.3.0
  • Last working this custom component release (if known):
  • Operating environment (Home Assistant/Supervisor/Docker/venv): HAOS on raspberry Pi

Describe the bug

I have a temperature sensor for outdoors temperature. Unit is degrees Celcius as "°C" (2 symbols).
I take an average of the temperature on a 24h window and it works well.
I want to calculate the min and max temp values on the 24h window and average them as well to make them smoother.
For this I make 2 "statistics" helpers to calculate the min and max temp of the last 24h.
Then I average these helpers on a 24h window.
All sensors show up with the "°C" measurement unit except the last 2 average sensors that are produced without unit.

Configuration.yaml

# initial physical sensor
mqtt:
  sensor:
    - name: "ext_temp"
      unique_id: "ext_temp"
      state_topic: MobileAlerts/022d3ad26f5e/json
      unit_of_measurement: '°C'
      value_template: "{{value_json.temperature[0]}}"

sensor:
# average sensor with good unit propagated
  - platform: average
    name: 'Average Outside Temperature'
    unique_id: "average_ext_temp"
    precision: 1
    duration:
      days: 1
    entities:
      - sensor.ext_temp

# statistics sensors with good unit propagated
  - platform: statistics
    name: 'Minimum temp over the last 24h'
    unique_id: "min_ext_temp"
    entity_id: sensor.ext_temp
    state_characteristic: value_min
    precision: 1
    max_age:
      hours: 24

  - platform: statistics
    name: 'Maximum temp over the last 24h'
    unique_id: "max_ext_temp"
    entity_id: sensor.ext_temp
    state_characteristic: value_max
    precision: 1
    max_age:
      hours: 24

# average sensors with unit not propagated correctly
  - platform: average
    name: 'Average Min Outside Temperature'
    unique_id: "average_min_ext_temp"
    precision: 1
    duration:
      days: 1
    entities:
      - sensor.minimum_temp_over_the_last_24h

  - platform: average
    name: 'Average Max Outside Temperature'
    unique_id: "average_max_ext_temp"
    precision: 1
    duration:
      days: 1
    entities:
      - sensor.maximum_temp_over_the_last_24h

Steps to Reproduce

  • Take a temp sensor;
  • Create a statistics helper based on this sensor
  • Create an Average sensor based on the statistics helper

Expected behavior

The average sensor should be able to retrieve the proper unit of measurement also from a statistics helper.

Debug log


There are no log entries related to any issue with this component

Additional context

image
On this graph you can see on the above graph that the outdoor temp, its average, and the statistics helpers are all measured in °C as expected. The below graph shows that the average sensors of the 2 statistics helpers have no unit and Lovelace displays them is a separate graph.

I have found a possible workaround by using the attributes of the average sensor of the physical measurement:
image

I would then extract these attributes in separate sensors using the custom component "attribute extractor", then average this new sensor, but I may end up with the same issue of units if the custom component acts same as the statistics helper for the unit of measurement.

@Gyosa3 Gyosa3 added the bug Something isn't working. label Feb 27, 2023
Limych pushed a commit that referenced this issue Mar 27, 2024
…-2.3

Update pygithub requirement from ~=2.2 to ~=2.3
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

1 participant