alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.5k stars 287 forks source link

Amazon Thermostat reports incorrect temperature #1890

Open Angelos59 opened 1 year ago

Angelos59 commented 1 year ago

I am able to see echo temperature entities correctly. In the process of updating the integration to do this via checking the box to include devices connected via echo, I also got entity temperatures for the amazon thermostats. This was unexpected but good, the issue is that the temperature is reported incorrectly. I have five of these thermostats and they all do the same. All the echos, I have four report temperature correctly.

Is your feature request related to a problem? Please describe. This is not a request to report a problem but if possible to enhance the integration to report the correct temperature for the amazon thermostats.

Describe alternatives you've considered I have multiple temperature sensors zigbee, echo, etc.

If you are able to do this also consider exposing the humidity reading on the amazon thermostat, if possible.

Thanks very much

danielbrunt57 commented 1 month ago

I can also try faking the Fahrenheit value...

inger147 commented 1 month ago

Did you simply edit that one line (self._attr_suggested_display_precision = "1") in what you already had? There are other changes in the class like def _get_temperature_value(self, value) -> float:, etc.

Sorry, yes, I just replaced that line. This time I replaced the whole TemperatureSensor class with your code, but I still got the same result; everything ends in .0 except preciseTemperature.

danielbrunt57 commented 1 month ago

So, I overrode my value and scale yet I still saw Celsius in the UI with one decimal precision. But that's because HA's global units is Metric so the UI is converting whatever {unit, scale} to Celsius. I changed my Setting -> System -> General from Metric to US Customary:

image

and I now see the temperature in Fahrenheit:

image

image

    @callback
    def _handle_coordinator_update(self) -> None:
        """Handle updated data from the coordinator."""
        value_and_scale = parse_temperature_from_coordinator(
            self.coordinator, self.alexa_entity_id
        )
        self._attr_native_value = self._get_temperature_value(value_and_scale)
        self._attr_native_unit_of_measurement = self._get_temperature_scale(
            value_and_scale
        )
        self._attr_suggested_display_precision = "2"
        _LOGGER.debug(
            "Coordinator update: %s: %s %s",
            self._attr_name,
            self._attr_native_value,
            self._attr_native_unit_of_measurement,
        )
        super()._handle_coordinator_update()

    def _get_temperature_value(self, value) -> float:
        if value and "value" in value:
            # value = value.get("value")
            value = 74.4453125
            _LOGGER.debug("TemperatureSensor value: %s", value)
            return value
        return None

    def _get_temperature_scale(self, value) -> str:
        if value and "scale" in value:
            #value = value.get("scale")
            value = "FAHRENHEIT"
            _LOGGER.debug("TemperatureSensor scale: %s", value)
            if value == "CELSIUS":
                return UnitOfTemperature.CELSIUS
            if value == "FAHRENHEIT":
                return UnitOfTemperature.FAHRENHEIT
            if value == "KELVIN":
                return UnitOfTemperature.KELVIN
        return None

First, doublecheck that you do not have legacy settings in your configuration.yaml regarding this.


#  name: Norton Court
#  latitude: 49.175855483923094
#  longitude: -122.97057420015338
#  elevation: 6
#  unit_system: metric
#  currency: CAD
#  country: Canada
#  time_zone: "America/Vancouer"

homeassistant:
  allowlist_external_dirs:
    - /config/www

Then as per this post, try changing your global setting from US Customary to Metric selecting Update the unit of all sensors and see what the logs and the frontend are showing you then. image

Then change it back from Metric to US Customary selecting Update all and see what the logs and the frontend show then.

inger147 commented 1 month ago

I checked my configuration.yaml and I did have an entry for unit_system: imperial, so I commented that out. Then I changed my Unit System from Fahrenheit to Celsius and back again, each time updating the sensors. There were still no changes that I noticed afterwards - all of the logged Fahrenheit temperatures were still rounded except preciseTemperature.

Note that before doing the above steps, I had updated to the latest AMP version, but after I updated it, I re-copied your TemperatureSensor class from a few posts back into my sensor.py file.

danielbrunt57 commented 1 month ago

Damn! I'm not sure where to look now...

github-actions[bot] commented 1 week ago

This bug report has been labelled as help wanted since there has been no activity in the last 3 weeks. It will not be closed automatically.