ollo69 / ha_tuya_custom

Tuya Custom Component for testing
Apache License 2.0
39 stars 18 forks source link

Cannot set curr_temp_divider to decimal value #50

Open svkowalski opened 3 years ago

svkowalski commented 3 years ago

First, let me say that your Custom Tuya integration works great with my SmartLife thermostat (InkBird C929). Just having a problem factoring the current temperature value. I determined that I need to divide the displayed value by 3.47 to match the true temp. However, despite the comment stating that "any positive number" can be entered, it appears that it only actually accepts an integer (in my case, either 3 or 4).

Here is my configuration.yaml entry:

tuya_custom:
    devices_config:
        - device_name: "C929 Thermostat"     # this is mandatory with at least one of the other keys
            unit_of_measurement: "F"         # "F" or "C", not set to use value provided from cloud
            temp_divider: 10                 # any positive number, all temperature values will be divided by this value
            curr_temp_divider: 3.47          # **any positive number**, only current temperature values will be divided by this value
            ext_temp_sensor: sensor.temperature     # a sensor that provide ambient temp used when not provided by device
ollo69 commented 3 years ago

Sorry for late answer but I was busy on this last month. At this moment only integer values are accepted, but 3.47 is a very strange value. Are sure that your problem is not related to unit_of_measurement? Can you provide some example of value showed and expected?

svkowalski commented 3 years ago

Thanks for your response. I have unit_of_measurement set to '°F'.

As I recall, the original values reported by sensor.temperature were something like 275(? almost looks like Kelvin!) So I fiddled around with cur_temp_divider until I got to a reasonable value (91.7). After comparing to a known good thermometer (85), I factored the sensor value further by dividing by 1.19 to achieve the "correct" temp in the Lovelace dashboard view.

In other words, I can get the InkBird C929 Thermostat to report the temperature accurately by making one back-end calculation (curr_temp_divider: 3.47) and another for the front-end display (sensor.current_temperature / 1.19).

I suppose I could skip the back-end adjustment and revise the calculation on the sensor. It would just be more elegant if your curr_temp_divider would accept a float value.

Here is how I define the InkBird C929:

climate:
  - platform: generic_thermostat
    name: Office closet
#   heater: climate.3417831284f3eb78e0b2
    heater: climate.c929_thermostat
    ac_mode: true
    target_sensor: sensor.temperature

...and here is the sensor attribute:

        value_template: >
          {{ '%0.1f' | format(state_attr('climate.c929_thermostat', 'current_temperature') | float / 1.19 ) }}
svkowalski commented 3 years ago

Solved: After reworking my tuya_custom and sensor YAML settings, I found that I can just set the curr_temp_divider to 1. Then, I divide the current_temperature attribute by a value that results in a match to what the InkBird/SmartLife app is reporting.

So just update your document to clarify that the curr_temp_divider must be an integer/whole number, and not just "any positive number." No need to change any code.

Thanks again for looking into my issue.

svkowalski commented 3 years ago

BTW: Just saw that you have updated the integration & removed it from configuration.yaml.

I updated my HA configuration to 0.1.2 (running in 0.118.5) and everything--InkBird & Tuya LED lights--works fine.

Thanks again!

ollo69 commented 3 years ago

I think that 275 is 27.5 multiplied by 10 in Celsius. If you just set temperature values divider = 10 and unit of measure = Celsius in integration option probably you will have te right temperature.