Scaling a Thermostat setpoint & target

I have managed to get on quite well with setting up some basics using some of my existing Tuya enabled smart devices. Initially I just added these devices around the home for simple control via Alexa, now I am adding what I have to OH and extending this with more of the same and Zigbee.

One sticking point is the thermostat. It is a MoesGo WiFi thermostat I believe that I have added to Tuya Smart (no need for yet another app). The temperature is displayed in total units of 0.5°C, so 22.5°C is displayed as 45°C, and the setpoint the same.

How can I scale this or account for it? I see there are maths functions within OH but I’m unsure where to use them for existing items like the thermostat which was auto added, the code of which I have added below. Can I just simply add something directly here or do I need to do something custom elsewhere?

UID: tuya:tuyaDevice:[/redacted/]
label: thermostat
thingTypeUID: tuya:tuyaDevice
configuration:
  pollingInterval: 0
  protocol: "3.3"
  productId: [/redacted/]
  deviceId: [/redacted/]
  ip: 192.168.5.11
  localKey: [/redacted/]
location: Hall
channels:
  - id: ECO
    channelTypeUID: tuya:switch
    label: ECO
    description: null
    configuration:
      dp: 5
  - id: ChildLock
    channelTypeUID: tuya:switch
    label: ChildLock
    description: null
    configuration:
      dp: 6
  - id: TempSet
    channelTypeUID: tuya:number
    label: TempSet
    description: null
    configuration:
      dp: 2
      max: 70
      min: 10
  - id: Mode
    channelTypeUID: tuya:string
    label: Mode
    description: null
    configuration:
      dp: 4
      range: 0,1
  - id: tempSwitch
    channelTypeUID: tuya:string
    label: tempSwitch
    description: null
    configuration:
      dp: 103
      range: 0,1
  - id: TempCurrent
    channelTypeUID: tuya:number
    label: TempCurrent
    description: null
    configuration:
      dp: 3
      max: 100
      min: 0
  - id: Power
    channelTypeUID: tuya:switch
    label: Power
    description: null
    configuration:
      dp: 1
  - id: floorTemp
    channelTypeUID: tuya:number
    label: floorTemp
    description: null
    configuration:
      dp: 102
      max: 198
      min: 0
  - id: floortempFunction
    channelTypeUID: tuya:switch
    label: floortempFunction
    description: null
    configuration:
      dp: 104

Displayed where? I think this is an XY Problem. You don’t need to scale this value, you need to figure out why the value is wrong in the first place. Surely this should be something handled in the binding.

I don’t know this binding. If it supports transformations, add a JS transformation (or the rules language of your choice) to divide the value by 2 in the state direction and another one to multiply by 2 in the command direction.

If not, you can do the same by applying a transform Profile on the link.

State direction

(function(data){
  if(data == "NULL" || data == "UNDEF") return data;
  const value = parseFloat(data)/2;
  return value + '°C'; // keep the units

})(input)

Command Direction:

(function(data){
  if(data == "NULL" || data == "UNDEF") return data;
  return parseFloat(data)*2; // parseFloat will drop the units
})(input)
1 Like

Displayed everywhere. e.g. current temp is shown on the OH dashboard as 45°C, but it’s 22.5°C. I think this issue reared its head in Alexa once, never worked out why but now I have seen the raw values I think this was the reason and their scaling was turned off.

As for the binding being at fault, maybe, but the binding is for Tuya Smart and this is a MoesGo thermostat paired with Smart Life so I wouldn’t blame the binding assuming Tuya thermostats don’t have this issue.

This is what I was hoping for. This got me on the right path, being new to openHAB I just needed to know the right words to to get me going! Now I know what a transformation and a profile is (vaguely) I actually dropped on the Math Transformation addon which made it simple to just tick multiply/divide on the channels page and add a multiplier/divisor.

Thank you.