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

history_stats: Accidentally passing in state: on (boolean) instead of state: "on" (string) always results in 0.0 value #121045

Open
rahatarmanahmed opened this issue Jul 3, 2024 · 1 comment

Comments

@rahatarmanahmed
Copy link

The problem

If you mistakenly put state: on instead of state: "on" in your config, YAML parses that as the value True.

sensor:
  - platform: history_stats
    name: HVAC Heating Last 24 Hrs
    entity_id: binary_sensor.any_thermostat_is_heating
    state: on
    type: time
    end: "{{ now() }}"
    duration:
      hours: 24

It seems like we just compare the recorded state against the boolean, which never matches so the statistic always calculates to 0.0.

According to the history_stats docs, state should be a list|string, so this seems like invalid state. Something should probably validate the configured state. (It also seems like state object states are always strings, so it's never valid to allow a boolean. I'm new to HA so I could be wrong here, though.)

What version of Home Assistant Core has the issue?

2024.4.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

history_stats

Link to integration documentation on our website

https://www.home-assistant.io/integrations/history_stats/

Diagnostics information

No response

Example YAML snippet

sensor:
  - platform: history_stats
    name: HVAC Heating Last 24 Hrs
    entity_id: binary_sensor.any_thermostat_is_heating
    state: on
    type: time
    end: "{{ now() }}"
    duration:
      hours: 24

Anything in the logs that might be useful for us?

I checked the logs, it doesn't say anything.

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Jul 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant