have you run tuya-cli to query which /dps/ topic that device uses? If you found your
tuya/<"socket" or "lightbulb">/<Virtual-id>/<localkey>/<ip-address>/command
tuya/<"socket" or "lightbulb">/<Virtual-id>/<localkey>/<ip-address>/state
with the anyproxy method then you had to install tuya-cli
This is the method of finding the keys, I was referring to:
https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md
“oh_newbie”, I believed you used a different method. So here are the commands to install tuya-cli on a windows 10 machine (for linux use the right directory):
open a window Admin powershell at c:/openhab2/userdata/etc/scripts
>git clone git@github.com:TuyaAPI/cli
>cd cli
>npm install -g --save
Note: on linux or windows you want to install Tuya-cli GLOBALLY (-g flag on npm install line)
Here is the link to Tuya-cli setup page: https://github.com/TuyaAPI/cli
Run this tuya-cli command at any command prompt to see if it installed correctly (
Important…
If tuya-cli throws an error under the following condition (#1 - somethimes, #2 always):
- try shutting down you OpenHAB2 server before using the tuya-cli command
- Also, BE-AWARE that while you are using the tuya-cli command DON’T have the Smart Life App (or which ever Tuya Smart App you use) OPEN while you are running the tuya-cli command on your server (tuya-cli will definitely through an unhanded error). If you must you the APP, access it before running the tuya-cli then make sure you exit the APP (don’t leave it running in the background on your phone)
tuya-cli help
or to find info on your plug:
tuya-cli get --id <Virtual-id> --key <localkey> --<ip-address> --all
example:
tuya-cli get --id 67833830cc50e3d4c9cf --key 559b607b2f0bac09 --ip 192.168.0.37 --all
tuya-cli produced the following output:
{ devId: '67833830cc50e3d4c9cf',
dps: { '1': true, '7': true, '11': 0, '101': 0 } }
From that output I see I have two plugs on my unit that can be controlled. The default, dps 1, can be controlled by using the MQTT state and command Topic below:
tuya/socket/67833830cc50e3d4c9cf/559b607b2f0bac09/192.168.0.37/state
tuya/socket/67833830cc50e3d4c9cf/559b607b2f0bac09/192.168.0.37/command, on="1", off="0"
I am presently testing this my self (I will let you know if this works) but I believe the second power port in the example can be controlled by the following MQTT state and command Topics:
tuya/socket/67833830cc50e3d4c9cf/559b607b2f0bac09/192.168.0.37/state
tuya/socket/67833830cc50e3d4c9cf/559b607b2f0bac09/192.168.0.37/dps/7, on="true", off="false"
I know this works:
tuya-cli set --id 67833830cc50e3d4c9cf --key 559b607b2f0bac09 --ip 192.168.0.37 --dps 1 --set false
result: the power turns off on dps 1 (the main socket)
tuya-cli set --id 67833830cc50e3d4c9cf --key 559b607b2f0bac09 --ip 192.168.0.37 --dps 7 --set false
result the power on the USB port turns off
This is my tuya smart plug:
https://www.amazon.com/Compatible-Function-Required-Allliances-Overcharging/dp/B07G78YSQS
So, now I just need to figure out how to translate the tuya-cli command into the MQTT topic. I am in the process of testing this out now, but I am in the middle of reinstalling Openhab2 first. I will let you know if I guessed wrong