Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fahrenheit temperatures not converted properly #47

Closed
MeirSD opened this issue Jul 1, 2024 · 29 comments
Closed

Fahrenheit temperatures not converted properly #47

MeirSD opened this issue Jul 1, 2024 · 29 comments
Assignees

Comments

@MeirSD
Copy link

MeirSD commented Jul 1, 2024

I'm trying to migrate over from the smartHomeHub/SmartIR (which was working okay other than not supporting Farenheit). I see the Readme mentions there may be some breaking changes but it's not clear what those are. I'm not using any custom codes and I'm getting the ERROR (MainThread) [custom_components.smartir.climate] Missing device IR code for '158' target temperature. logged when I try to control my AC. Here is my config:

climate:
  - platform: smartir
    name: Back Office AC
    unique_id: back_office_ac
    device_code: 1281
    controller_data: remote.backoffice_ehub
    temperature_sensor: sensor.backoffice_ehub_temperature
    humidity_sensor: sensor.backoffice_ehub_humidity
@litinoveweedle
Copy link
Owner

Hello, which temperature unit do you use in HA?

@litinoveweedle litinoveweedle self-assigned this Jul 1, 2024
@MeirSD
Copy link
Author

MeirSD commented Jul 1, 2024 via email

@litinoveweedle
Copy link
Owner

OK, seems to be error on the side of the integration.

  • What is the minimum and maximum temperature settable via home assistant climate card?
  • What is the correlation between temperature you are trying to set and temperature reported as missing by the error message?

@MeirSD
Copy link
Author

MeirSD commented Jul 2, 2024

I can select from 61F to 84F. 64F logs 142 and 84F logs 183 so it looks like it's actually treating the Fahrenheit number as Celsius and then converting it to Fahrenheit.

@MeirSD
Copy link
Author

MeirSD commented Jul 2, 2024

I edited climate.py to import TemperatureConverter from homeassistant.util.unit_conversion import TemperatureConverter and then I modified the _send_command with the following after target_temperature is initialized:

if self._temperature_unit != self._data_temperature_unit:
                target_temperature = str(round(TemperatureConverter.converter_factory(self._temperature_unit, self._data_temperature_unit)(
                    temperature
                )))

That fixes the problem. Do you need me to make a pull request?

@litinoveweedle
Copy link
Owner

litinoveweedle commented Jul 2, 2024

Hello, thank you for troubleshooting.

Actually you can't use rounding, as integration supports all precision (half, tens, etc.) I have new PR for preset mode support ready to be merged and it changed a lot of lines around your fix. Will you be please able to check this branch? I would fix this into this branch and than merge it into master and release...

BTW: this branch already uses TemperatureConverted and I believe I fixed your issue in there already some time ago. :-)

@litinoveweedle litinoveweedle changed the title Migrating from original SmartIR Fahrenheit temperatures not converted properly Jul 2, 2024
@MeirSD
Copy link
Author

MeirSD commented Jul 2, 2024

Thanks, I'll try to test that out later today. I had some thoughts about the rounding that I'm not sure if you want to address. Fujitsu does whole number rounding in Celsius and when in Fahrenheit it only let's you set even numbers. It wouldn't surprise me if manufacturers who do half integer rounding in Celcius do whole integer rounding in Fahrenheit. I'm not super. Concerned with the number on the thermostat matching exactly what I set it to in HA but it's something to consider if that's the goal.

@litinoveweedle
Copy link
Owner

Finding of the closest existing temperature is also implemented in the branch you are going to test. So please test it and report back as I want to release this version.🤞

@MeirSD
Copy link
Author

MeirSD commented Jul 3, 2024

Okay, I tested it and it works to control the AC. For whatever reason the degrees displayed on HA are 4 lower than what it shows on the thermostat. I didn't pay attention to whether that was happening with my patch but I'm guessing that it was. It's possible that's just an issue with the codes file. Looking forward to the next release! Thanks

@litinoveweedle
Copy link
Owner

Okay, I tested it and it works to control the AC. For whatever reason the degrees displayed on HA are 4 lower than what it shows on the thermostat.

That is definitely not correct. I will prepare version with debug logging - would you be able to test it with debug on?

@litinoveweedle
Copy link
Owner

updated version is ready here. Please enable debug logging by adding appropriate lines into HA configuration.yaml:

logger:
  default: warning
  logs:
    custom_components.smartir.climate: debug

@MeirSD
Copy link
Author

MeirSD commented Jul 4, 2024

Here is the resulting log from sending 70 and then 66 which resulted in the thermostat showing 74 and then 70

2024-07-03 19:23:15.113 DEBUG (MainThread) [custom_components.smartir.climate] Found 'cool' operation mode command.
2024-07-03 19:23:15.117 DEBUG (MainThread) [custom_components.smartir.climate] Found 'auto' fan mode command.
2024-07-03 19:23:15.117 DEBUG (MainThread) [custom_components.smartir.climate] Found '70', temperature command.
2024-07-03 19:23:37.811 DEBUG (MainThread) [custom_components.smartir.climate] Found 'cool' operation mode command.
2024-07-03 19:23:37.812 DEBUG (MainThread) [custom_components.smartir.climate] Found 'auto' fan mode command.
2024-07-03 19:23:37.812 DEBUG (MainThread) [custom_components.smartir.climate] Found '66.0', temperature command.

@litinoveweedle
Copy link
Owner

Thank you for testing. Just to be sure, that I understand your report correctly:

  • When you set the temperature via HA climate card to 66, it will immediately reset to 70?
  • What happens if you set odd temperature?

@MeirSD
Copy link
Author

MeirSD commented Jul 5, 2024

No problem, so when I set it to 66 it stays on 66 in HA but my physical thermostat shows 70. That's why I'm pretty sure the issue is with the ir json file.

Setting to an odd temperature doesn't do anything different. Setting it to 67 shows 67 on the HA climate card, logs [custom_components.smartir.climate] Found '67.0', temperature command. but my physical thermostat gets set to 70.

@litinoveweedle
Copy link
Owner

I think I found the issue. I think it is fixed in latest version of the branch.

Please note, that some of the other new changes are now present in the branch, so please:

  • replace at least init.py and climate files
  • strict evaluation of the data files is now present - it may now raise error. If so the the data file needs to be fixed first.

@MeirSD
Copy link
Author

MeirSD commented Jul 8, 2024

It's now only letting me set even numbers and jumping in 2 degree increments which is correct.
It's still 4 degrees off from what is displayed so I think I'll just have to make my own code file as it seems 1281.json is off by 2 C across the board.

Here are the logs.

2024-07-07 20:32:03.965 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68' from '°F' to '°F' with 'None' precision.
2024-07-07 20:32:03.966 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68°F' converted into device temperature '20.0°C'.
2024-07-07 20:32:03.966 DEBUG (MainThread) [custom_components.smartir.climate] Found 'cool' operation mode command.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] Found 'auto' fan mode command.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '20' from '°C' to '°C' with '2' precision.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] Input temperature '68°F' closest found temperature command '20°C' converts back into HA '68°F' temperature.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] Found '68', temperature command.
2024-07-07 20:32:07.706 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68' from '°F' to '°F' with 'None' precision.
2024-07-07 20:32:07.706 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68°F' converted into device temperature '20.0°C'.
2024-07-07 20:32:55.268 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66.0' from '°F' to '°F' with 'None' precision.
2024-07-07 20:32:55.268 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66.0°F' converted into device temperature '18.88888888888889°C'.
2024-07-07 20:32:58.669 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68.0' from '°F' to '°F' with 'None' precision.
2024-07-07 20:32:58.669 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68.0°F' converted into device temperature '20.0°C'.
2024-07-07 20:33:00.443 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68.0' from '°F' to '°F' with 'None' precision.
2024-07-07 20:33:00.443 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68.0°F' converted into device temperature '20.0°C'.
2024-07-07 20:33:03.045 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66.0' from '°F' to '°F' with 'None' precision.
2024-07-07 20:33:03.045 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66.0°F' converted into device temperature '18.88888888888889°C'.
2024-07-07 20:33:03.213 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66.0' from '°F' to '°F' with 'None' precision.
2024-07-07 20:33:03.213 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66.0°F' converted into device temperature '18.88888888888889°C'.
2024-07-07 20:33:03.213 DEBUG (MainThread) [custom_components.smartir.climate] Found 'cool' operation mode command.
2024-07-07 20:33:03.214 DEBUG (MainThread) [custom_components.smartir.climate] Found 'auto' fan mode command.
2024-07-07 20:33:03.214 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '19' from '°C' to '°C' with '2' precision.
2024-07-07 20:33:03.215 DEBUG (MainThread) [custom_components.smartir.climate] Input temperature '66.0°F' closest found temperature command '19°C' converts back into HA '66°F' temperature.
2024-07-07 20:33:03.215 DEBUG (MainThread) [custom_components.smartir.climate] Found '66', temperature command.
2024-07-07 20:33:05.699 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66' from '°F' to '°F' with 'None' precision.
2024-07-07 20:33:05.700 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66°F' converted into device temperature '18.88888888888889°C'.
2024-07-07 20:33:09.014 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68.0' from '°F' to '°F' with 'None' precision.
2024-07-07 20:33:09.014 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68.0°F' converted into device temperature '20.0°C'.

@litinoveweedle
Copy link
Owner

litinoveweedle commented Jul 8, 2024

thank you for the test. I am still confused by this:

To my understanding,

  • in the device file temperatures are in the 'C' and the precision (step between temperatures) is 1C, correct?
  • In the HA GUI, climate card shall now be in 'F' with 2F steps, correct?

I am bit confused by some of the logs. This is how the full temperature change shall looks like:

2024-07-07 20:32:03.965 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68' from '°F' to '°C' with 'None' precision.
2024-07-07 20:32:03.966 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68°F' converted into device temperature '20.0°C'.
2024-07-07 20:32:03.966 DEBUG (MainThread) [custom_components.smartir.climate] Found 'cool' operation mode command.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] Found 'auto' fan mode command.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '20' from '°C' to '°F' with '2' precision.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] Input temperature '68°F' closest found temperature command '20°C' converts back into HA '68°F' temperature.
2024-07-07 20:32:03.968 DEBUG (MainThread) [custom_components.smartir.climate] Found '68', temperature command.

This seems to be correct. EDIT: those are on/off actions....

2024-07-07 20:32:07.706 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68' from '°F' to '°C' with 'None' precision.
2024-07-07 20:32:07.706 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68°F' converted into device temperature '20.0°C'.
2024-07-07 20:32:55.268 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66.0' from '°F' to '°C' with 'None' precision.
2024-07-07 20:32:55.268 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66.0°F' converted into device temperature '18.88888888888889°C'.
2024-07-07 20:32:58.669 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68.0' from '°F' to '°C' with 'None' precision.
2024-07-07 20:32:58.669 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68.0°F' converted into device temperature '20.0°C'.
2024-07-07 20:33:00.443 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '68.0' from '°F' to '°C' with 'None' precision.
2024-07-07 20:33:00.443 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '68.0°F' converted into device temperature '20.0°C'.
2024-07-07 20:33:03.045 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66.0' from '°F' to '°C' with 'None' precision.
2024-07-07 20:33:03.045 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66.0°F' converted into device temperature '18.88888888888889°C'.

And following change in temperature:

2024-07-07 20:33:03.213 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '66.0' from '°F' to '°C' with 'None' precision.
2024-07-07 20:33:03.213 DEBUG (MainThread) [custom_components.smartir.climate] Input HA temperature '66.0°F' converted into device temperature '18.88888888888889°C'.
2024-07-07 20:33:03.213 DEBUG (MainThread) [custom_components.smartir.climate] Found 'cool' operation mode command.
2024-07-07 20:33:03.214 DEBUG (MainThread) [custom_components.smartir.climate] Found 'auto' fan mode command.
2024-07-07 20:33:03.214 DEBUG (MainThread) [custom_components.smartir.climate] convert temp '19' from '°C' to '°F' with '2' precision.
2024-07-07 20:33:03.215 DEBUG (MainThread) [custom_components.smartir.climate] Input temperature '66.0°F' closest found temperature command '19°C' converts back into HA '66°F' temperature.
2024-07-07 20:33:03.215 DEBUG (MainThread) [custom_components.smartir.climate] Found '66', temperature command.

EDIT: so this seems to be OK for me completely. I am just still confused by the shift of the temperatures on your physical thermostat. How is this one connected to you HVAC device? Did you though about testing with HA global settings to C? Could you set your thermostat into C?

@litinoveweedle
Copy link
Owner

The preset branch was now merged with the master. In case we will not find root cause for temperature difference in the code, I think that this issue could be closed.

@MeirSD
Copy link
Author

MeirSD commented Jul 8, 2024

I think the incomplete one is changing the temperature while it's already on vs changing it and then switching it to cool from off.

@litinoveweedle
Copy link
Owner

Ok, thanks for info. Are you OK with closing this issue now? If you will find anything new you are free to reopen it or create new - I would like to definitely fix this, but currently I am not ware of any problem in the code itself.

@MeirSD
Copy link
Author

MeirSD commented Jul 10, 2024

I edited the json file and put it in custom codes and everything seems to be working properly. Thanks for addressing this!

@MeirSD MeirSD closed this as completed Jul 10, 2024
@Aersaud
Copy link

Aersaud commented Jul 16, 2024

Hello I am also running into this issue with my Broadlink and using this fork of SmartIR with my Lennox minisplit system. I have figured out something must be going wrong with the detection of if the units should be converted somewhere along the way from C to F or vice versa. My thermostat is in F and I am using 2161.json as my "remote". When sending any command using HA through the thermostat card it converts my Fahrenheit temperature into Fahrenheit again using the Celsius to Fahrenheit conversion.

I have witnessed this by setting my Mini Split using the thermostat card to 72F Cool and I can see in the HA logs that is erroring and returning:

Source: custom_components/smartir/climate.py:603
integration: smartir ([documentation](https://github.com/litinoveweedle/SmartIR), [issues](https://github.com/litinoveweedle/SmartIR/issues))
First occurred: 11:27:03 PM (1 occurrences)
Last logged: 11:27:03 PM

Missing device IR code for '162' target temperature

using some quick math I realized that it is applying a conversion on my Fahrenheit temperature as if it was Celsius.

(72°F × 9/5) + 32 = 161.6°F ~ 162°F

So it is somehow not seeing that my thermostat is already in Fahrenheit and is trying to convert it from Fahrenheit to Fahrenheit currently (thinking it is Celsius to Fahrenheit).

If you need any more info please let me know, or if you would like me to open a new issue @litinoveweedle

@MeirSD
Copy link
Author

MeirSD commented Jul 16, 2024

Did you install the latest master manually? I don't think the latest release on HACS includes the fix yet.

@Aersaud
Copy link

Aersaud commented Jul 16, 2024

I did not do it manually no. I will try that in the morning and report back.

__
Actually got around to doing it now since it was bugging me I couldn't control it without the remote (hahah!) it seems to be working nicely except I notice that it only allows setting temperature to even numbers (70,72,74,76....etc) is this intended or am I missing something?

@litinoveweedle
Copy link
Owner

Hello, there is new pre-release available which contains all those fixes.

@Aersaud
Copy link

Aersaud commented Jul 17, 2024

Hello! Thank you for your support and maintaining this project. I have installed the latest pre-release 1.18.0b1 and I am still encountering the issue where it is only moving temperature by an increment of 2 degrees Fahrenheit.

@litinoveweedle
Copy link
Owner

If your device file has temperatures in the whole Celsius degrees, then the given behaviour is completely correct. If you disagree please describe what your expected behaviour shall be.

@Aersaud
Copy link

Aersaud commented Jul 17, 2024

I understand where the problem is occurring now thank you for that last bit of information. It makes sense since the json for the device code is in Celsius as increments of 1 degree C that it changes by 2 in F when it is converted. To resolve my particular issue I will more than likely have to grab the IR codes from the Broadlink for the in between temperatures.

Is it possible for me to create my device code json in Fahrenheit with every step in between 70,71,72,73..etc ?

Or am I better off leaving it in Celsius and using half increments on the temperatures 17,17.5,18,18.5..etc ?

@litinoveweedle
Copy link
Owner

You are completely correct, 😌 in most cases C converts directly to even F. Regarding your question, if your device supports command in F it is always better to records command in native units (units supported by device and IR remote) than to do any conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants