Sure, because it all it needs is just one sensor to be available for it to compute a value. Remember when I cautioned you about using this approach?
The only way to ensure it won’t compute anomalously low values is to restrict the calculation to when all sensors are available (not when some are and some aren’t).
average_house_temperature:
friendly_name: 'Inside'
unit_of_measurement: '°C'
availability_template: >-
{% set sensors = expand('group.indoor_temperature_sensors') | list %}
{{ sensors | rejectattr('state', 'in', ['unknown', 'unavailable'])
| list | count == sensors | count }}
value_template: >-
{% set sensors = expand('group.indoor_temperature_sensors')
| map(attribute='state') | map('float') | list %}
{{ (sensors | sum / sensors | count) | round(1) }}
The graph shows 3.9c at the bottom, I have around 25c on average right now and that’s over 7 sensors, seams to me like the value template returns true as all sensors are available but then when getting their values only one returns something, but still the count is 7 which would explain the low value.
You really need to determine the values reported by each sensor at startup. Without that information, this is all guesswork. Either examine each sensor’s history or the Logbook or, best of all, the values recorded in the database. It’s entirely possible they’re not unknown or unavailable but who knows what.
Further investigation shows that my Zigbee and Z-Wave sensors with bogus values have state ‘restored’, but my SensorPush sensors do not. They instead are missing the attribute "attribution": "Data by SensorPush".
So I would need to exclude sensors that have state restored and those that miss the attribute "attribution": "Data by SensorPush". If any sensor comes through that filer I would like to calculate average temperature based on those. Which would mean a way to filter them out again the the value template and also count that filter.
This is beyond my templating skills so help is greatly appreciated.
What’s more challenging is the other part, where SensorPush sensors normally have an attribution attribute except when they have a bogus value. We can’t simply reject all sensors that are missing an attribution attribute because it’s normal for non-SensorPush sensors to lack that attribute.
Is there some other attribute that SensorPush sensors always have but your other sensors do not? We’re looking for a way to positively identify a SensorPush sensor and then reject it if it lacks an attribution attribute.
Add a custom attribute to the 2 non-SensorPush sensors called attribution. Assign it whatever value you want.
Now when everything is running normally, all 7 sensors have an attribution attribute. On startup, the 5 SensorPush sensors will be (potentially) missing their attribution attribute but the other 2 will still have it (because it’s a custom attribute). Now the template can safely reject any of the 7 sensors that lack an attribution attribute (and any whose state is restored).
This seems like a perfect opportunity to improve your templating skills. You’ve been given several examples that can now be enhanced in the suggested manner.
First step, is to create custom attributes for the two non-SensorPush sensors. You can do it via the UI or via customize.yaml. You only have two sensors so I would suggest adding the custom attributes via the UI.
Ahh. I thought those attributes came straight from the sensor gateway but they are merged with any customization done before they become available?
I did poke around a bit in the SensorPush integration code and from what I understand "attribution": "Data by SensorPush" is just a config passed to HA and nothing set by the integration itself?
If that’s the case those other values must come from somewhere else?
I don’t use the SensorPush integration but if the sensor entities it creates usually have an attribution attribute then it’s a safe assumption that the SensorPush integration is responsible for it.
Your observation that this attribute is missing from SensorPush sensors on startup (and/or whenever it generates bogus values) is some sort of strange quirk of the SensorPush integration. I have no idea if that’s by design or accident.