First off, I’m new here, and to the Home Assistant world.
Now my question - does the statistics platform read and recognize the unique_id paremeter? Docs suggest that it does, but I don’t think it works.
Here’s my context and configuration: I’m working on (yet another) implementation of tracking kWh consumed per cooling degrees, taking deep inspiration from others that have posted in the forums on this topic.
So, I’m trying to set up a template sensor to track the following:
kWh Cooling per Cooling Degrees Daily = [ 24 hour running average outdoor temperature ] / [ 24 hr running total HVAC power consumption ].
In my sensors.yaml file, which is included into configuration.yaml, I have the following relevant snippets:
# Keep track of the running 24 hours temperature
- platform: statistics
state_characteristic: average_linear
entity_id: sensor.openweathermap_forecast_temperature
name: Average Daily Temperature
unique_id: average_daily_temperature # (Does this even do anything?)
max_age:
hours: 24
# Use 24 hours averaged hvac power to calculate a running 24 hours total
# Note, sensor.hvac_1min is another template sensor that sums 1 min power data from 4 different sensors, 2 x AC units and 2 x air handlers. The sensors all come from an Emporium Vue 2 that I've connected via the cloud integration.
- platform: statistics
state_characteristic: average_linear
entity_id: sensor.hvac_1min
name: Average Daily HVAC
unique_id: average_daily_hvac # (Does this even do anything?)
max_age:
hours: 24
sampling_size: 1440
The above two sensors are then used to calculate the energy efficiency metric I hope to track:
Snippet from configuration.yaml:
template:
- sensor:
- name: "Cooling Degree Day"
unique_id: cooling_degree_day_daily
state: >
{% set dd = states('sensor.average_daily_temperature_2') | float - 65.0 | float %}
{% if dd > 0 %}
{{ dd }}
{% else %}
{{ 0 }}
{% endif %}
unit_of_measurement: °F
- name: kWh per Cooling Degree 24hrs
unique_id: cooling_degree_day_24hrs
state: >
{% set hvac_usage = states('sensor.average_daily_hvac') | float %}
{% set dd = states('sensor.cooling_degree_day_daily') | float %}
{% if dd > 0 %}
{{ hvac_usage / dd }}
{% else %}
{{ 0 }}
{% endif %}
So I’ve noticed that first of all, the sensor created by the statistics have a different id, and appear to be named by HA derived from its name:
parameter.
Initially things worked fine, but after a few restarts for (and for no apparent reason?) the sensor.average_daily_temperature
sensor started showing up in HA as sensor.average_daily_temperature_2
, even though I did not update the unique_id
parameter.
In fact, I then noticed that changes I make to the unique_id
parameter in the statistics platform have no effect on the sensor id in HA, and that Home Assistant appears to just assign the sensor a name?
Am I missing something?