Avoid missing values in sensors during restart

Yeah but I’m not that skilled with templating so I can to it practically.

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.

After some excellent help from @123 I’m happy to report my template_sensor works perfectly now!

Here is what I ended up with. I decided to require at least two sensors as just one could deviate from the expected average value too much.

average_house_temperature:
  friendly_name: 'Inside'
  unit_of_measurement: '°C'
  device_class: temperature
  availability_template: >-
    {% set sensors = expand('group.house_temperature_sensors') | list %}
    {{ sensors
       | rejectattr('state', 'in', ['unknown', 'unavailable', 'restored'])
       | selectattr("attributes.attribution")
       | list | count > 1
    }}
  value_template: >-
    {% set sensors = expand('group.house_temperature_sensors')
       | rejectattr('state', 'in', ['unknown', 'unavailable', 'restored'])
       | selectattr("attributes.attribution")
       | map(attribute='state') | map('float') | list %}
    {{ (sensors | sum / sensors | count) | round(1) }}

Where is that requirement in availability_template? What I see is that it accepts a minimum count of 1 sensor to declare availability.

count > 0

Or have I misunderstood what you wrote?

Yeah, you need to look again :wink:

Sneaky, but the post’s history revealed the alteration. :slight_smile: