[REQUEST] Plugin for Tuya

Python and python framework

Moderator: leecollings

dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

Yes, problem solved!!!! Thanks for the help!
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

Is there an option to include the power / voltage / usage of the plug? I am really trying to find out.
scriptkiddie
Posts: 4
Joined: Thursday 21 February 2019 23:06
Target OS: -
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by scriptkiddie »

i have one error from plugin...

Code: Select all

2019-02-22 00:14:34.323  Status: (Tuya) Stopping threads.
2019-02-22 00:14:34.333  Status: (Tuya) Exiting work loop.
2019-02-22 00:14:34.333  Status: (Tuya) Stopped.
2019-02-22 00:14:44.816  Status: (Tuya) Started.
2019-02-22 00:14:44.996  Status: (Tuya) Entering work loop.
2019-02-22 00:14:44.996  Status: (Tuya) Initialized version 3.0.0, author 'tixi'
2019-02-22 00:14:44.998  (Tuya) Debug logging mask set to: NONE
2019-02-22 00:14:45.019  (Tuya) Tuya SmartPlug Device #1 created.
2019-02-22 00:14:45.021  (Tuya) Tuya SmartPlug Device #2 created.
2019-02-22 00:14:45.022  (Tuya) Tuya SmartPlug Device #3 created.
2019-02-22 00:14:45.023  (Tuya) Tuya SmartPlug Device #7 created.
2019-02-22 00:14:45.031  (Tuya) Tuya SmartPlug Device #8 created.
2019-02-22 00:14:45.034  (Tuya) Tuya SmartPlug Device #9 created.
2019-02-22 00:14:45.036  (Tuya) Tuya SmartPlug Device #10 created.
2019-02-22 00:14:45.037  (Tuya) Tuya SmartPlug Device #11 created.
2019-02-22 00:14:45.038  Error: (Tuya) 'onStart' failed 'AttributeError':'module 'pytuya' has no attribute 'OutletDevice''.
2019-02-22 00:14:45.038  Error: (Tuya) ----> Line 498 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onStart
2019-02-22 00:14:45.038  Error: (Tuya) ----> Line 366 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onStart
2019-02-22 00:15:04.502  Error: (Tuya) 'onHeartbeat' failed 'AttributeError':''NoneType' object has no attribute 'Connected''.
2019-02-22 00:15:04.503  Error: (Tuya) ----> Line 522 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onHeartbeat
2019-02-22 00:15:04.503  Error: (Tuya) ----> Line 472 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onHeartbeat
2019-02-22 00:15:04.503  Error: (Tuya) ----> Line 260 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function __command_to_execute
2019-02-22 00:15:24.515  Error: (Tuya) 'onHeartbeat' failed 'AttributeError':''NoneType' object has no attribute 'Connected''.
2019-02-22 00:15:24.515  Error: (Tuya) ----> Line 522 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onHeartbeat
2019-02-22 00:15:24.515  Error: (Tuya) ----> Line 472 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onHeartbeat
2019-02-22 00:15:24.515  Error: (Tuya) ----> Line 260 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function __command_to_execute
2019-02-22 00:15:44.525  Error: (Tuya) 'onHeartbeat' failed 'AttributeError':''NoneType' object has no attribute 'Connected''.
2019-02-22 00:15:44.525  Error: (Tuya) ----> Line 522 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onHeartbeat
2019-02-22 00:15:44.525  Error: (Tuya) ----> Line 472 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function onHeartbeat
2019-02-22 00:15:44.525  Error: (Tuya) ----> Line 260 in /home/alex/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/plugin.py, function __command_to_execute
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

Hi,

@dorenberg where did get the json outout of the plug ?
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

using the android app "packet capture". In the app you can find packages with the json output.
Have used it to obtain the keys, but all the other information can also be found then.
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

Hello,

Some ideas for the KWh:
- you can create a virtual device and then update it with the json api with a curl command
- This command should be inserted in line 425
- To get the needed information state['5'] should work (you may have to divide the value)

5 here correspond to the dps entry 5, depending on your device the value may be different.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [REQUEST] Plugin for Tuya

Post by sincze »

tixi7 wrote: Saturday 23 February 2019 23:50 Some ideas for the KWh:
- you can create a virtual device and then update it with the json api with a curl command
- This command should be inserted in line 425
- To get the needed information state['5'] should work (you may have to divide the value)

5 here correspond to the dps entry 5, depending on your device the value may be different.

The information is in state indeed. :lol:
tuya.jpg
tuya.jpg (15.93 KiB) Viewed 2272 times
Why not create those additional devices from within the plugin as well just as with the "Switch" when defining a plug?
something like:

Code: Select all

	Domoticz.Device(Name="Tuya SmartPlug Switch #" + str(val), Unit=val, TypeName="Switch",Image=8).Create()
	Domoticz.Device(Name="Tuya SmartPlug Voltage #" + str(val), Unit=val, TypeName="Voltage").Create()
	Domoticz.Device(Name="Tuya SmartPlug Ampere #" + str(val), Unit=val, TypeName="Current/Ampere").Create()
	Domoticz.Device(Name="Tuya SmartPlug Usage#" + str(val), Unit=val, TypeName="Usage").Create()
	Domoticz.Log("Tuya SmartPlug Device #" + str(val) +" created.")
And then fill them without using an external json api curl.. call ?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

sincze wrote: Sunday 24 February 2019 23:19
Why not create those additional devices from within the plugin as well just as with the "Switch" when defining a plug?
something like:

Code: Select all

	Domoticz.Device(Name="Tuya SmartPlug Switch #" + str(val), Unit=val, TypeName="Switch",Image=8).Create()
	Domoticz.Device(Name="Tuya SmartPlug Voltage #" + str(val), Unit=val, TypeName="Voltage").Create()
	Domoticz.Device(Name="Tuya SmartPlug Ampere #" + str(val), Unit=val, TypeName="Current/Ampere").Create()
	Domoticz.Device(Name="Tuya SmartPlug Usage#" + str(val), Unit=val, TypeName="Usage").Create()
	Domoticz.Log("Tuya SmartPlug Device #" + str(val) +" created.")
And then fill them without using an external json api curl.. call ?
Inside the plugin will be better, but i have no time and no device for that. so i put a sketch of solution that is easier to add.
If you have time to add it inside the plugin, go ahead!
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [REQUEST] Plugin for Tuya

Post by sincze »

tixi7 wrote: Monday 25 February 2019 7:49
sincze wrote: Sunday 24 February 2019 23:19
Why not create those additional devices from within the plugin as well just as with the "Switch" when defining a plug?
something like:

Code: Select all

	Domoticz.Device(Name="Tuya SmartPlug Switch #" + str(val), Unit=val, TypeName="Switch",Image=8).Create()
	Domoticz.Device(Name="Tuya SmartPlug Voltage #" + str(val), Unit=val, TypeName="Voltage").Create()
	Domoticz.Device(Name="Tuya SmartPlug Ampere #" + str(val), Unit=val, TypeName="Current/Ampere").Create()
	Domoticz.Device(Name="Tuya SmartPlug Usage#" + str(val), Unit=val, TypeName="Usage").Create()
	Domoticz.Log("Tuya SmartPlug Device #" + str(val) +" created.")
And then fill them without using an external json api curl.. call ?
Inside the plugin will be better, but i have no time and no device for that. so i put a sketch of solution that is easier to add.
If you have time to add it inside the plugin, go ahead!
No worries. You did an amazing job to design the plugin without the hardware.
Many thanks for that. My 'native'' domoticz language is PHP so have to figure out how to do that in python as well. :lol:
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

We can also test an other plug. I don't know if it has the same numbers. Not quiet sure. Need to test it tonight.
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

If I need to send over the plug to someone for testing purposes, let me know. That will make life much easier. (Based in The Netherlands)
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

dorenberg wrote: Monday 25 February 2019 10:41 If I need to send over the plug to someone for testing purposes, let me know. That will make life much easier. (Based in The Netherlands)
Hi,

If you do a sudo python3 get_dps.py what is the output of the plug ?
I'm curious about the output.

This is mine.

Plug State Information:
{'dps': {'2': 0, '4': 243, '6': 2392, '5': 42, '1': True}, 'devId': '00621010cc50e3c3d408'}

Then we can see of the DPS is the same.
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

Plug State Information:
{'devId': '12716401807d3a7b5c6b', 'dps': {'6': '00ff0000000000', '4': 255, '106' : 2272, '101': True, '1': True, '2': 'colour', '10': 'ffff0505ff000000ff00ffff00 ff00ff0000ff000000', '7': 'ffff500100ff00', '104': 0, '9': 'ffff5001ff0000', '8' : 'ffff8003ff000000ff000000ff000000000000000000', '3': 180, '5': '171918009c1919 ', '105': 0}}


This is the output. So 104 105 and 106
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

Is this from a powerplug or light?
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

This is a powerplug with an led light.

Aliexpress lonsonho. 16a 2 pin EU plug with power measurement
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

Ah I see it has a night light.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [REQUEST] Plugin for Tuya

Post by sincze »

jslegers wrote: Monday 25 February 2019 11:58
dorenberg wrote: Monday 25 February 2019 10:41 If I need to send over the plug to someone for testing purposes, let me know. That will make life much easier. (Based in The Netherlands)
Hi,

If you do a sudo python3 get_dps.py what is the output of the plug ?
I'm curious about the output.

This is mine.

Plug State Information:
{'dps': {'2': 0, '4': 243, '6': 2392, '5': 42, '1': True}, 'devId': '00621010cc50e3c3d408'}

Then we can see of the DPS is the same.
Based upon the info provided by @jslegers (he has 2 different types of plugs) the following data can be retrieved and keys seem consistent.
Tuya.jpeg
Tuya.jpeg (14.01 KiB) Viewed 2235 times
Next step would be to create the appropriate devices and have the plugin push the data to them.
At least the ordinary plugs should then be working.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

Maybe these dps values for the power consumption and voltage can be set as input boxes in the plugin?
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [REQUEST] Plugin for Tuya

Post by sincze »

dorenberg wrote: Tuesday 26 February 2019 13:07 Maybe these dps values for the power consumption and voltage can be set as input boxes in the plugin?
You mean something like this:
Tuya_Custom.JPG
Tuya_Custom.JPG (38.74 KiB) Viewed 2222 times
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
dorenberg
Posts: 110
Joined: Monday 22 June 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10982
Location: Veghel, The Netherlands
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dorenberg »

exactly what I meant!! Nearly there!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest