Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Python and python framework

Moderator: leecollings

User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

gillesMa wrote: Monday 05 February 2024 18:05 Hello,
They're juste basic wifi Tuya plugs, with an on/off state. Some of them also have electric meters, but it doesn't makes a difference. I also receive two notifications with a Cubetouch. It seems to be the case with all my Tuya devices.
Okay, thanks for the info, I will try to investigate!
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

Xenomes wrote: Monday 05 February 2024 19:58
gillesMa wrote: Monday 05 February 2024 18:05 Hello,
They're juste basic wifi Tuya plugs, with an on/off state. Some of them also have electric meters, but it doesn't makes a difference. I also receive two notifications with a Cubetouch. It seems to be the case with all my Tuya devices.
Okay, thanks for the info, I will try to investigate!
I was a bug in Domoticz and is resoled in the current beta.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
gillesMa
Posts: 5
Joined: Sunday 26 April 2020 14:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by gillesMa »

Xenomes wrote: Sunday 11 February 2024 15:58
Xenomes wrote: Monday 05 February 2024 19:58
gillesMa wrote: Monday 05 February 2024 18:05 Hello,
They're juste basic wifi Tuya plugs, with an on/off state. Some of them also have electric meters, but it doesn't makes a difference. I also receive two notifications with a Cubetouch. It seems to be the case with all my Tuya devices.
Okay, thanks for the info, I will try to investigate!
I was a bug in Domoticz and is resoled in the current beta.
Thank you very much for your investigation. Unfortunately I cannot check the beta as I have a pi zero w. I will wait for a release working on pi zero w.
Thank you again.
papryk18
Posts: 6
Joined: Friday 23 February 2024 10:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by papryk18 »

Hello!

I have some WiFi Door Sensors that have already been successfully added to the Smart Life mobile app and Domoticz.
I tested and found that everything works fine, but only sometimes.

When I enter the house, the period of time from opening to closing the door is relatively short (5-10 seconds?). The door sensor sends open/close information to the Smart Life app very quickly, but the device status in my Domoticz is not updated. Moreover, my Domoticz usually doesn't record door-opening events at all (not just too late).

Is there any setting where I can fix it? Can I add the sensor not from the Tuya cloud but directly from LAN? Can I change the update interval in the plugin?

Best regards,
Patrick
neveride
Posts: 8
Joined: Saturday 30 March 2024 10:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by neveride »

I have similar problem to Patryk. My garage door contracon is updated in Domoticz after around 1 minute, while in Tuya app I see its status change in real time. I think, that Domoticz-TinyTUYA-Plugin refreshes the devices and their states every ~1 minute. Can someone (Xenomes? :>) confirm how the device update works? Is it possible to trigger a state update of one device (door contracton) when the state of another device is toggled (door open/close)

And additional question, as this is also something I cannot figure out. I have a monostable switch In Tuya. When I click it and the door is closer then it will start opening. If I click it again while opening/closing it will stop the action of opening/closing. If I click it again it will do the opposite of the first action (so if the door was previously being opened and it will start closing it).

What switch should I use for that in Domoticz? Normal on/off does not work as it will send the action to the door only when I close them. When the door's status is 'Closed' and I try to open them nothing happens. Only after that when I click again, then the close action will be executed and the door will be opened/closed depending on their state (which is not visible in Domoticz, because the status is updated after a long time - see the first paragraph)
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

neveride wrote: Tuesday 02 April 2024 15:45 I think, that Domoticz-TinyTUYA-Plugin refreshes the devices and their states every ~1 minute. Can someone (Xenomes? :>) confirm how the device update works?
Hi, The plugin retrieves the status from the Tuya server once every minute. Therefore, if a device is opened and closed within that minute, Domoticz will not register any change. For the cloud version, there isn't much that needs altering. If you increase the frequency of requests to Tuya, it's possible that your account may exceed its request limit. I am building an offline version, but it is not yet fully ready.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
neveride
Posts: 8
Joined: Saturday 30 March 2024 10:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by neveride »

OK, clear. Is there any way to request the sensor state after changing the device state? I have a garage door that I control and a garage door sensor that I do not control. But if I could request its state e.g. 5s after pressing the garage door, then it would show as open and all would be working well for me. I am trying to figure out a way to do that..
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

neveride wrote: Tuesday 02 April 2024 23:16 OK, clear. Is there any way to request the sensor state after changing the device state? I have a garage door that I control and a garage door sensor that I do not control. But if I could request its state e.g. 5s after pressing the garage door, then it would show as open and all would be working well for me. I am trying to figure out a way to do that..
You could try using the following for that device: https://github.com/Xenomes/Domoticz-Tin ... cal-Plugin.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
neveride
Posts: 8
Joined: Saturday 30 March 2024 10:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by neveride »

I will try the local one after the weekend. Yesterday I was fighting with the cloud plugin. Since yesterday I get the following when I start the plugin:
2024-04-06 08:59:22.742 Tuya: Pushing 'PollIntervalDirective' on to queue
2024-04-06 08:59:23.041 Tuya: No device data returned for Tuya! Check if subscription cloud plan has expired!
2024-04-06 08:59:23.041 Tuya: No device data returned for Tuya! Check if subscription cloud plan has expired!
2024-04-06 08:59:23.041 Tuya: No device data returned for Tuya! Check if subscription cloud plan has expired!
I thought that maybe my plan has expired (strange, because I just set everything up a few days ago). When I fill the information on https://iot.tuya.com/cloud/products/apply-extension and press Submit I see an error:
All input parameters of the remote API are lost.
Did they change something and the plugin does not work currently or is it classical PEBKAC?
B8rt
Posts: 2
Joined: Thursday 05 March 2020 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by B8rt »

Xenomes wrote: Wednesday 03 April 2024 19:54
neveride wrote: Tuesday 02 April 2024 23:16 OK, clear. Is there any way to request the sensor state after changing the device state? I have a garage door that I control and a garage door sensor that I do not control. But if I could request its state e.g. 5s after pressing the garage door, then it would show as open and all would be working well for me. I am trying to figure out a way to do that..
You could try using the following for that device: https://github.com/Xenomes/Domoticz-Tin ... cal-Plugin.
Xenomes, keep up the good work! Using TinyTUYA now for a while, and i'm very happy with it.
But also facing the issues with the poll-interval, so it is not seeing any button-press events.
Is the offline version already ready to use?
If not, when do you expect to have a 100% working release version?
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

B8rt wrote: Thursday 11 April 2024 12:12 Is the offline version already ready to use?
With the last update it should be better, i need to do a long time test.
B8rt wrote: Thursday 11 April 2024 12:12 If not, when do you expect to have a 100% working release version?
I hope in a couple of weeks that my devices are running perfect, unknown devices that will be a issue, so 100% it will never be.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
B8rt
Posts: 2
Joined: Thursday 05 March 2020 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by B8rt »

Xenomes wrote: Thursday 11 April 2024 21:57
B8rt wrote: Thursday 11 April 2024 12:12 Is the offline version already ready to use?
With the last update it should be better, i need to do a long time test.
B8rt wrote: Thursday 11 April 2024 12:12 If not, when do you expect to have a 100% working release version?
I hope in a couple of weeks that my devices are running perfect, unknown devices that will be a issue, so 100% it will never be.
Oke, sounds good. Yesterday i installed the local version. I was not able to run the local version and the cloud version together.
When i stopped the cloud version, the local version started and added some devices (after i moved the devices.json file to the correct folder).
Devices showed initial values but didn't update/refresh. And for example voltage value didn't show a comma. 232,2V was shown as 2322V.
So for now it was not a working alternative for me.

I'm going to follow the development since i'm very interested in a working version!
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

Thanks for testing!
B8rt wrote: Friday 12 April 2024 8:39 Oke, sounds good. Yesterday i installed the local version. I was not able to run the local version and the cloud version together.
When i stopped the cloud version, the local version started and added some devices (after i moved the devices.json file to the correct folder).
I will update the readme to run in at the root of the plugin.
B8rt wrote: Friday 12 April 2024 8:39 Devices showed initial values but didn't update/refresh. And for example voltage value didn't show a comma. 232,2V was shown as 2322V.
So for now it was not a working alternative for me.
I will look at the update/refresh data, could be a small typo. Comma is a scaling issue, it could be to wrong data returning to codding error.
B8rt wrote: Friday 12 April 2024 8:39 I'm going to follow the development since i'm very interested in a working version!
Hope to have some time in the debug these issues.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
tarmacalastair
Posts: 95
Joined: Wednesday 30 October 2019 14:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Great Britain
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by tarmacalastair »

EdwinK wrote: Sunday 07 May 2023 7:16 Possible. When I visit that page I get an 'all input parameters of the remote API are lost'

After the weekend I will try and do some more work in it. Now I'm going enjoy a lazy sunday.
Probably way too late for you EdwinK as I've only just experienced this. I was getting the Error: tinytuya: handleThread: string indices must be integers
problem, found this forum topic and discovered, like you, that my subscription had expired. I also got the same problem when I tried to renew. However I found that if I clicked the back arrow (webpage, not browser) and then clicked the renew subscription option (for IOT Core) then this time it worked. After about five minutes the TUYA website said "approved" (and then "in service") and now, after restarting the plugin all my devices are back and the error in the log has disappeared.
Running Domoticz and Dashticz beta on Raspberry Pi OS 32 bit - has anyone had success with 64 bit?

Desktop access from Ubuntu Linux
Ramnol
Posts: 8
Joined: Sunday 18 June 2017 9:52
Target OS: Linux
Domoticz version: 2024.4
Location: Landgraaf, Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Ramnol »

Hi,

Today I updated the TinyTuya-Plugin from version 1.6.1 to 1.8.5. Also updated Domoticz to version 2024.4 (build 15992).
Domoticz is running on Linux (Ubuntu 22.04.4 LTS).
At this moment more then 30 switches and sensors are used and everything is running fine, except for the readings of Temperature, Voltage (kWh).
These readings are a factor 10 to high.
2024-05-13 153157.png
2024-05-13 153157.png (114.85 KiB) Viewed 1521 times
Is there a way to fix this problem?

Thanks in advance,

Ramnol.
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

Hi Ramnol,

Strange... the scaling is read from the json provide from the tinytuya, in version 1.6.1 the scaling was correct?

Could you please generate a JSON dump using the debug_discovery.py script from the tools directory? After generating it, could you email the dump to [email protected]?
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

Ramnol wrote: Monday 13 May 2024 15:57 Hi,

Today I updated the TinyTuya-Plugin from version 1.6.1 to 1.8.5. Also updated Domoticz to version 2024.4 (build 15992).
Domoticz is running on Linux (Ubuntu 22.04.4 LTS).
At this moment more then 30 switches and sensors are used and everything is running fine, except for the readings of Temperature, Voltage (kWh).
These readings are a factor 10 to high.
2024-05-13 153157.png
Is there a way to fix this problem?

Thanks in advance,

Ramnol.
Issue fixed in version 1.8.6
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Ramnol
Posts: 8
Joined: Sunday 18 June 2017 9:52
Target OS: Linux
Domoticz version: 2024.4
Location: Landgraaf, Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Ramnol »

Everything works fine now.
Thanks very much.
DKTigra
Posts: 1
Joined: Thursday 03 December 2020 3:04
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by DKTigra »

Hello.

I've got wall sockets with energy monitoring with data updates only when tuya smart application is opened (looks like "updatedps" command is needed but it is supported only for local versions). But there is one dps parameter that is updated with timestamp - totally used power.
Spoiler: show

getdps
{
"code": "add_ele",
"dp_id": 17,
"type": "Integer",
"values": "{\"unit\":\"kwh\",\"min\":0,\"max\":100000000,\"scale\":3,\"step\":100}"
}
getdevicelog
{
"logs": [
{
"code": "add_ele",
"event_from": "1",
"event_id": 7,
"event_time": 1716793698706,
"status": "1",
"value": "221280"
},
{
"code": "add_ele",
"event_from": "1",
"event_id": 7,
"event_time": 1716793669845,
"status": "1",
"value": "221270"
},
}
Looks like this dps is updated every 10 watts are consumed. My goal was to monitor when device is actually consumes power and total power consumption per day, so i've tried to make dirty modification of plugin.py
Spoiler: show

if dev_type == 'switch':
....
if searchCode('cur_current', ResultValue):
currentcurrent = StatusDeviceTuya('cur_current')
currentpower = StatusDeviceTuya('cur_power')
currentvoltage = StatusDeviceTuya('cur_voltage')
....
lastupdate = (int(time.time()) - int(time.mktime(time.strptime(Devices[dev['id']].Units[14].LastUpdate, '%Y-%m-%d %H:%M:%S'))))
lastvalue = Devices[dev['id']].Units[14].sValue if len(Devices[dev['id']].Units[14].sValue) > 0 else '0;0'
currentEle = StatusDeviceTuya('add_ele')
Domoticz.Log(currentEle)
Domoticz.Log(float(lastvalue.split(';')[1]))
Domoticz.Log(lastupdate)
Domoticz.Log(3600)
UpdateDevice(dev['id'], 14, str(int((currentEle- float(lastvalue.split(';')[1]))*(3600/lastupdate)*1000 )) + ';' + str(currentEle) , 0, 0, 1)

UpdateDevice(dev['id'], 13, str(currentvoltage), 0, 0)
After this modification it is possible to calc Daily/Monthly consumption (with 10W accuracy) and monitor if device is active now. Recalculating currentpower by add_ele isn't accurate because there is some time passes between add_ele parameter is updated by device and device is polled by Domoticz. I think it could be far more accurate by getting it from devicelog and adding correction for devicelog timestamp data, but i'm not so good in python.

Could you thinks about adding such an option for future releases (recalculate power usage and get total power consumption from "add_ele" dps if this dps is supported by device? Thsnks.
User avatar
Xenomes
Posts: 388
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: Domoticz-TinyTUYA-Plugin (Cloud)

Post by Xenomes »

DKTigra wrote: Monday 27 May 2024 9:50 Hello.

I've got wall sockets with energy monitoring with data updates only when tuya smart application is opened (looks like "updatedps" command is needed but it is supported only for local versions). But there is one dps parameter that is updated with timestamp - totally used power.
Spoiler: show

getdps
{
"code": "add_ele",
"dp_id": 17,
"type": "Integer",
"values": "{\"unit\":\"kwh\",\"min\":0,\"max\":100000000,\"scale\":3,\"step\":100}"
}
getdevicelog
{
"logs": [
{
"code": "add_ele",
"event_from": "1",
"event_id": 7,
"event_time": 1716793698706,
"status": "1",
"value": "221280"
},
{
"code": "add_ele",
"event_from": "1",
"event_id": 7,
"event_time": 1716793669845,
"status": "1",
"value": "221270"
},
}
Looks like this dps is updated every 10 watts are consumed. My goal was to monitor when device is actually consumes power and total power consumption per day, so i've tried to make dirty modification of plugin.py
Spoiler: show

if dev_type == 'switch':
....
if searchCode('cur_current', ResultValue):
currentcurrent = StatusDeviceTuya('cur_current')
currentpower = StatusDeviceTuya('cur_power')
currentvoltage = StatusDeviceTuya('cur_voltage')
....
lastupdate = (int(time.time()) - int(time.mktime(time.strptime(Devices[dev['id']].Units[14].LastUpdate, '%Y-%m-%d %H:%M:%S'))))
lastvalue = Devices[dev['id']].Units[14].sValue if len(Devices[dev['id']].Units[14].sValue) > 0 else '0;0'
currentEle = StatusDeviceTuya('add_ele')
Domoticz.Log(currentEle)
Domoticz.Log(float(lastvalue.split(';')[1]))
Domoticz.Log(lastupdate)
Domoticz.Log(3600)
UpdateDevice(dev['id'], 14, str(int((currentEle- float(lastvalue.split(';')[1]))*(3600/lastupdate)*1000 )) + ';' + str(currentEle) , 0, 0, 1)

UpdateDevice(dev['id'], 13, str(currentvoltage), 0, 0)
After this modification it is possible to calc Daily/Monthly consumption (with 10W accuracy) and monitor if device is active now. Recalculating currentpower by add_ele isn't accurate because there is some time passes between add_ele parameter is updated by device and device is polled by Domoticz. I think it could be far more accurate by getting it from devicelog and adding correction for devicelog timestamp data, but i'm not so good in python.

Could you thinks about adding such an option for future releases (recalculate power usage and get total power consumption from "add_ele" dps if this dps is supported by device? Thsnks.
Hi DKTigra,
Thanks for the modification. I can't test your modification (I don't have a Tuya power plug). I will add it to the code; if there are issues, let me know.
edit: Added to version 1.8.7
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest