New in Apilio: Tuya (Smart Life) devices now with proper scaling

Hello internet friends!

Today we are releasing an update to our integration with Tuya that will delight many of you using sensors: we are now applying scaling units to the figures that Tuya is sending so you won’t see that your living room is at 2100º anymore, but instead the real 21º!

What’s changed?

Some of you noticed this issue already:

  1. Tuya Thermostatic Radiator Valves
  2. Add the ability to do math on Variables
  3. Ampersand in device name causing Tuya device not to be selectable - #3 by philsj

When we first implemented this integration, we couldn’t find a way to convert the scale of the units from sensors in a way that didn’t involve a lot of hacky code, we just couldn’t find how Tuya was doing it and we suspected a hardcoded solution was implemented on their app. After reviewing intensely the API documentation we found that the information to scale the units was available, albeit in a rather convoluted way!! The good news is that we can implement this in a more sustainable and not hacky way now thanks to the discovery.

Give me some examples!!

Your temperature sensor will say 21º instead of 2100º.
Your lux sensor will say 50 Lux instead of 5000.

Handy! This will help enormously when comparing devices, constants or variables to device values!

This is an example of the old values:

And here’s the new values!

You’ll also see the units of magnitude

Previously we would display numeric attributes but we wouldn’t display if they were volts, amps, watts, degrees Centigrade or Fahrenheit… Now you’ll see the unit that applies to your numeric attribute: V, mA, W, KWh, ºC, etc if they are available for your device (we can’t control what the manufacturer does, sorry!!).

See anything that hasn’t scaled yet?

You need to wait until your device sends an update, then the units will display correctly. Check this example above, the sensor on the right has received the update, the one on the left will do it shortly but it is still displaying the old values.

Please get in touch! Many devices are integrated in weird ways with the Tuya platform and, even if we’ve seen some edge cases that we can account for, you might find a funky device that is escaping all our crafty scaling development. We’d love to hear about it, drop a message below!

There is a small cosmetic display issue for users with Tuya conditions based on values that are now scaled: On the card of the configuration and when entering edit mode, it shows the old, unscaled value (but the logic runs based on adapted values). In those cases, just edit the condition and set the proper value.

2 Likes

While I very much appreciate the attempts to get this to work, for me the outcome is even worse than before. I have two different brands of Tuya thermostats, which both show the same issues. Each actually allows temperatures to be set between 5 and 35C, in 0.5 degree intervals.

In the “old” version of your implementation, you somehow interpreted the device information such that you could set between “10” and “70”, but only allowed “5” unit increments. This was clearly different from how both Smart Life and (independently) Alexa treated each thermostat, where they did allow correct control.

Your updated code now shows the temperature in C, which is correct, but still displays this as exactly double the values that are set in the device.

But what is worse is that you now seem to interpret that it is only possible to set the temperature between 1C and 7C, and prevent me doing anything other than that. It does, however, let me enter half-integer values, such as “2.5”

If I use this to set the temperature to “2” then it manages to set the device to 10C, out by a factor of 5. Although it accepts half integer values such as 2.5, when you try to action these they do not change the temperature of the device, so it looks as though there is some sort of rounding going on before the values are passed.

Where this leaves me is that before I could just note that the temperature settings in Apilio were out by a factor of two, though as you stopped any value being passed that was not within a step of 5, I could only control the thermostats to 2.5C intervals rather than the 0.5C they are capable of. Not great, and as we have communicated before, what would have worked for my case would be if you removed the “step of 5” limitation when setting the temperature value. The situation now is that the temperatures are still recorded incorrectly, but I can now only set the temperature in 5C increments because of the “accepts values between 1 and 7C”–which is not terribly useful.

For the record, if you query these devices in the Tuya development platform, they display their accepted values and scaling as follows:

{“code”=>“temp_set”, “type”=>“Integer”, “values”=>“{"unit":"℃”,"min":10,"max":70,"scale":1,"step":5}"},

I know we have had lots of offline conversations about this and you will probably tell me that my thermostats are all wrong in their implementation and Apilio is correctly interpreting these settings to come up with the thermostat only allowing itself to be set to temperatures in the range 1C to 7C. But if this is the case, why are Smart Life and Alexa correctly interpreting readings from these thermostats?

1 Like

Hi @pebneter ,

For the record, my interpretation of how the device scaling is being interpreted by Smart Life and Alexa for my devices is as follows:

“min 10, max 70” mean that you can pass any raw value between 10 and 70 to the device
“scale 1 step 5” means that the actual step value is 0.5C (5 / 10^1)

As each integer in the input values therefore corresponds to 0.5C, raw input values of “10 to 70 in integer steps” equates to real world settings of 5C to 35C in 0.5C steps.

I therefore think that for these devices, a control program should therefore be allowing any value between 5 and 35, limited to half integer steps. Then in the background you should multiply this by 2 and pass the resulting integer to the device as the raw value in the range 10 to 70. This is certainly how Smart Life and Alexa are allowing the settings to be made for these specific devices.

1 Like

Hi @robin,
the outcome for your case is as expected (very bad), but we prepared a solution to correct the mismatching specification.
I can permanently override the scaling factor per attribute, I can do that for your device. I would start by setting a factor of 2, sou you should see correct values. And you can then check what it does to the input restrictions.
Let me know when is a good time to make the change!

1 Like

Hi @pebneter ,

I seem to have some confusing results.

All my TRV’s are Saswell SEA802 DF but some valves are updating and some are not.

Here are the dashboards from Apilio and Home Assistant both taken a few minutes ago.

I have made several changes to the Temperature Set on the Lounge valve using Smart Life App and re-sync’ed afterwards but the current value of 22° is not shown on the Apilio Dashboard whereas it is on the Home Assistant.

I hope this is of some help.

1 Like

Hi @pebneter ,

That would be much appreciated, but are you absolutely sure that your interpretation of the scaling for these devices is correct, as if wrong then that would affect others too? Given that Smart Life and Alexa are interpreting whatever information is being provided in a way that is “correct” given the operation of the thermostat, I’d be very wary of any interpretation that produced a different answer, or had to be hard-coded to work properly.

But if you want to try it, the situation for my particular devices is that the data entry should allow values 5 to 35 (so scale the min and max by a factor of 2), and the step size should be 0.5. When entered, these should be passed to the device as values in the range 10-70 (so multiplied by 2).

If it is easy to implement, please try this for my thermostat called “Ensuite” and let’s see if that can be got to work!

Many thanks,

Robin

1 Like

@robin I set a scaling factor of 2 for the device set temp. So it should display your values correctly in conditions and actions.
Let me know if the step size restrictions work out now or if still too restrictive. Another way to fix it would be to set a scaling factor of 0.2, so then you could enter 215 which would be sent as 43 to your device.

1 Like

@doncevans Can you recheck if the attributes have updated in the meantime? I checked the Lounge thermostat and at least that one seems to have received updates.

1 Like

@pebneter
Yes I checked, re-sync’ed, signed out and back in again but still no update showing for me.

as you can see my dashboard is showing last update as Saturday for Temperature Set but that gets changed by Alexa routines about 6 or 7 times a day.

What has changed for Lounge is Switch Status and I have never seen that change before. I don’t know whether Tuya have made some changes in the last couple of days but until I completely re-installed Home Assistant yesterday I wasn’t seeing any change in switch status there either (where it now says Heat/Cool it always said ‘off’ before and the Power button and circulation icons were absent also).

Incidentally since we last conversed at length , the original supplier of my TRV accepted a return on them and I purchased these Saswell ones which have the code integrated into the Gateway that I was doing here on my Logicblock and that then controls a 2-channel switch for Central Heating and Hot Water. It is still not a solution I’m overly pleased with as Saswell are totally uncommunicative and there are several unknowns still. The status information that I was getting from the previous valves is no longer available for me to use here unfortunately.

1 Like

Hi @pebneter
I now can’t seem to pass any values to the device at all:

This was just trying to pass “3” as a value, which is in the middle of the current ‘allowed range’ of 1-7, and earlier resulted in setting the actual temperature to 15C.

:cry:

1 Like

Hi @pebneter ,
Sorry to report that it is not working yet. In Apilio it now reads the set temperature as 3C and the current room temperature (“Upper temp”) as 38C
image

In Smart Life:

In Alexa:

These are both correct, as the set temperature is currently 15C and the actual room temperature 19C.

In logicblocks it is still only possible to set the device temperature to between 1 and 7C

1 Like

@pebneter Quick note to say that for my Tuya devices, the scaling works as expected now, but for some reason now I cannot click into the Temp and Humidity device detail pages. They both give me the “Sorry… Something went wrong” message. Happy to provide any info needed.

i can still get to the device details for my Tuya switches though.

Thanks for the continued support!

1 Like