Tuya: reading plug consumption info

Hello,

First of all, thank you @Lokkye for developing this service!

Currently, I’m using it with a smart plug Outdoor Smart plug_Wi-Fi_BLE

Only the switch functionality works. Would it be possible to add the following features?

countdown_1\tInteger\t

{
  "unit": "s",
  "min": 0,
  "max": 86400,
  "scale": 0,
  "step": 1
}

add_ele\tInteger\t

{
  "unit": "kW·h",
  "min": 0,
  "max": 50000,
  "scale": 3,
  "step": 100
}

cur_current\tInteger\t

{
  "unit": "mA",
  "min": 0,
  "max": 30000,
  "scale": 0,
  "step": 1
}

cur_power\tInteger\t

{
  "unit": "W",
  "min": 0,
  "max": 80000,
  "scale": 1,
  "step": 1
}

cur_voltage\tInteger\t

{
  "unit": "V",
  "min": 0,
  "max": 5000,
  "scale": 1,
  "step": 1
}

Hello @PhilippeMA

I just made the small PR to add these values:

But I couldn’t add ‹ countdown_1 › because we don’t have the integration for this type of value.
This normally allows turning off the plug or the light after a certain time.
@pierre-gilles: have we ever had a device with this feature?

And the value reported by « add_ele » is quite weird because according to the doc: « Increased power: It refers to the power consumption of the device. Each time the “incremental” is reported. »
So we would need to add the values together but I don’t know by what magic.

I hope this still meets your expectations.

Tell me if you want a test docker image :slight_smile:

Hello @Lokkye

Great, thanks for your quick reply.

This data is the cumulative consumption. I have the impression that this cumulative is done internally by Tuya; the returned value already takes the calculation into account. It deserves to be tested (I’m at your disposal!).

Thanks again!

No, we have nothing for that! But it can be added quite easily if it’s requested

Well, on my side, on my device, it only responds 0 or 1 so I think I have to do the calculation.

Here is the Docker image to run tests on your side: delogzway/gladys:add_energy_tuya (it will be active in 1 hour because it is being built)

Thanks for the reply @pierre-gilles.
@PhilippeMA: I think we’ll need to make another specific request to add the feature (But I think we can already achieve this behavior with scenes if I’m not mistaken)

2 Likes

Indeed, for now I’d welcome feedback from @PhilippeMA on the Docker image — it’s already great if we deploy the consumption info to production, even if we add the other feature later!

Thanks @Lokkye for the PR :clap:

1 Like

I’m away on a business trip until Friday evening. I’ll take a look this weekend!

2 Likes

Hello,

Image tested today.

The Current, Power and Voltage readings are correct.

Regarding the Energy data, I can’t figure out what it corresponds to:
![image|378x241](upload://kmc

I found how to read the data. If it’s the data Add Electricity, is it a rounding/precision issue?

In any case, as you indicated, this data is aggregated to feed the cumulative energy total and the day’s energy.

Here is part of my day’s data:
![image|637x500](upload://z

@PhilippeMA : Thanks for the test and investigation. I hadn’t seen that in the docs it said the returned value was multiplied by 100. :frowning:
J’ai fait la modif. Je vais sortir une image avec ce correctif.
But I think this value will only be useful in a chart.

2 Likes

@PhilippeMA : Were you able to rerun tests with the new Docker image?

1 Like

Hello @Lokkye

It’s good, image tested. I confirm that all the returned values are correct.

Thanks :wink:

@PhilippeMA Thanks for the tests. :star_struck:
@pierre-gilles : Can you do a quick review ? :slight_smile:
I think it’s ready to be merged

1 Like

It’s fine with me to merge, but is there a merge conflict on the PR?

1 Like

Yes, I just rebased from master (and fixed the conflict).

2 Likes

Thanks! I’ve merged into master, it’ll go out in the next release :raising_hands:

1 Like

This feature is available in Gladys Assistant 4.30!