Thanks for the details. Well, based on the code I can’t explain why the unit_of_measurement attribute for sensor.server_daily_energy is W. Clearly it should be kWh.
Is there any chance that there is a customization entry for sensor.server_daily_energy that is changing its unit_of_measurement attribute?
Well then I’m stumped. You could try enabling debug but I didn’t see any log messages that would help explain why this is happening. You could always modify the code to add some.
I found onew with the help of the developer. THe problem is apparently that the unit is defined first time the sensor is created, so if you have done something wrong there, it will never change. So I got a suggestion with creating a new integration sensor and a new utility meter sensor called ‘test’, and that changed the unit, so I just created a new pair for them (https://github.com/home-assistant/home-assistant/issues/30233)