j0ta29 / esphome

ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
https://esphome.io/
Other
6 stars 2 forks source link

Negative number in temperature sensor #7

Closed adorobis closed 7 months ago

adorobis commented 7 months ago

Hi all,

As the temperatures dropped in Europe I've noticed that the outside temperature sensor (0x0800 address in my case) returns very high values, e.g. 65515. It took me a while to realise that it is an unsigned integer that should be converted to a signed integer in esphome. So far I could not figure out how to do it in esphome. Do you have a hint for it?

Many thanks! Adam

adorobis commented 7 months ago

btw, I've found an example on esphome, here is the filter:

        - lambda: !lambda |-
            // Fix negative values for now
            if (x > 6000) {
              return x - 6553.6;
            }
            return x;

Seems to be working ok :) Not sure if this should be implemented in optolink platform or rather left to the user to configure.

adorobis commented 7 months ago

Digging a bit further it is even more simple: the unsigned int has to be converted to short int and here is how it can be done in the filter (on raw data, not divided by 10):

      - lambda: !lambda |-
          return (short)x;
adorobis commented 7 months ago

I've provided proposal to include a warning in the documentation for the Sensor section.