How to give a sensor units? (should be °F instead of unitless)

I am using ha-average ( GitHub - Limych/ha-average: Average Sensor for Home Assistant ) to make a sensor. However, it is coming up unitless, so I can’t put it in a graph along with other temperatures. How do I properly give it a unit of Fahrenheit?

I tried adding [ unit_of_measurement: “°F” ], however HA gives an error in the logs saying that it’s deprecated. What’s the new way to do this?

YAML below:

sensor:
  - platform: average                                
    name: 'Average Outside Temp'              
    duration:                                                                 
      minutes: 10                                       
    entities:                                        
      - sensor.midea_bedroom_outdoor_temp_fix     
      - sensor.midea_sunroom_outdoor_temp_fix     
      - sensor.midea_living_room_outdoor_temp_fix  

what does the HA documentation say is the new way to do it? that too hard to look up?

I looked it up and there’s no details about what to actually do. I searched for actual documentation for an hour and came up with nothing so trying here instead.

I agree, it’s a bit obscure. I assume our friend is referring to this bit of the github readme:

Known Limitations and Issues

  • Due to the fact that HA does not store in history the temperature units of measurement for weather, climate and water heater entities, the average sensor always assumes that their values ​​are specified in the same units that are now configured in HA globally.

Your temperature units are presumably set to °F in Settings | System | General. If your average temperature is coming up without units, that implies that the three sensors you’re averaging don’t have the correct device class. That might be the first thing to check.

Otherwise, if you look up sensor in the HA docs:

It refers you to another page about how to modify units of measurement (using customize):

Don’t tell him I told you. :wink:

you spent an hour and couldn’t find anything? You gotta learn how to use a flipping search box dude, it’s not hard. I was able to go find this in 2 minutes. You are trying to modify a sensor so maybe try doing a search for “sensor” and Oh, what do you know, here it is…

Ah, but you knew what you were looking for. :wink: The search box is hopeless if you don’t have the right search term. I usually use a google site search - gives more results and prioritizes them better.

Hi @Stiltjack, thanks for the info.

I went to the Customizing entities page you mention, and I just tried to set the three sensors to have °F, but when I do with this option
unit_of_measurement: "°F"

I get this error:
2023-04-28 16:10:03.113 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.statistics]: [unit_of_measurement] is an invalid option for [sensor.statistics]. Check: sensor.statistics->unit_of_measurement. (See /config/configuration.yaml, line 67). Please check the docs at https://www.home-assistant.io/integrations/statistics

However, when I go to that URL, I don’t see any way for me to properly set the unit.

Am I missing something obvious?

@Fallingaway24, the page you referred me to is the thing I’ve already tried that isn’t working. Unless my syntax is off or something, I don’t understand why the documentation is saying one thing when HA is acting another.

Below are the bits of my YAML that are pertinent for context:

sensor:
                                         
  - platform: average                                
    name: 'Average Outside Temp Fix'              
    duration:                                                                 
      minutes: 10                                       
    entities:                                        
      - sensor.midea_bedroom_outdoor_temp_fix     
      - sensor.midea_sunroom_outdoor_temp_fix     
      - sensor.midea_living_room_outdoor_temp_fix  

  - platform: statistics
    name: "Midea Living Room Outdoor Temp Fix"
    entity_id: sensor.midea_living_room_outdoor_temperature
    unit_of_measurement: "°F"
    state_characteristic: value_max
    sampling_size: 50
    max_age:
      minutes: 30
             
  - platform: statistics     
    name: "Midea Bedroom Outdoor Temp Fix"
    entity_id: sensor.midea_bedroom_outdoor_temperature     
    unit_of_measurement: "°F"
    state_characteristic: value_max
    sampling_size: 50                   
    max_age:                  
      minutes: 30  

  - platform: statistics     
    name: "Midea Sunroom Outdoor Temp Fix"
    entity_id: sensor.midea_sunroom_outdoor_temperature     
    unit_of_measurement: "°F"
    state_characteristic: value_max
    sampling_size: 50                   
    max_age:                  
      minutes: 30  

As I said earlier, this is the place where temperature units are set globally.

If you go to Developer Tools | States and look up your various temperature sensors, they should have state attributes something like this:

state_class: measurement
temperature_valid: true
unit_of_measurement: °F
device_class: temperature

If they have the device class temperature, then the unit of measurement should be assigned automatically. If not you can change the device class with customize.