Page 8 of 19

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 19 February 2019 18:01
by dorenberg
Yes, problem solved!!!! Thanks for the help!

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 19 February 2019 18:43
by dorenberg
Is there an option to include the power / voltage / usage of the plug? I am really trying to find out.

Re: [REQUEST] Plugin for Tuya

Posted: Thursday 21 February 2019 23:10
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

Re: [REQUEST] Plugin for Tuya

Posted: Friday 22 February 2019 11:41
by jslegers
Hi,

@dorenberg where did get the json outout of the plug ?

Re: [REQUEST] Plugin for Tuya

Posted: Friday 22 February 2019 13:05
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.

Re: [REQUEST] Plugin for Tuya

Posted: Saturday 23 February 2019 23:50
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.

Re: [REQUEST] Plugin for Tuya

Posted: Sunday 24 February 2019 23:19
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 2438 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 ?

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 7:49
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!

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 10:05
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:

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 10:14
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.

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 10:41
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)

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 11:58
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.

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 12:27
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

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 13:32
by jslegers
Is this from a powerplug or light?

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 13:53
by dorenberg
This is a powerplug with an led light.

Aliexpress lonsonho. 16a 2 pin EU plug with power measurement

Re: [REQUEST] Plugin for Tuya

Posted: Monday 25 February 2019 14:33
by jslegers
Ah I see it has a night light.

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 26 February 2019 9:17
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 2401 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.

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 26 February 2019 13:07
by dorenberg
Maybe these dps values for the power consumption and voltage can be set as input boxes in the plugin?

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 26 February 2019 17:00
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 2388 times

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 26 February 2019 18:43
by dorenberg
exactly what I meant!! Nearly there!