Thanks really for your help. I uploaded Tasmota on FcMila RGBW Light bulb which seems to be a Tuya. I succeeded in connecting to tasmota interface. I used generic configuration of the modula. A low blue red light always remained. when I click to toggle on, the light switches on, when I move the dark cursor, I get the small light (blue red).
How can I love it? Would it be possible to upload the original firmware? The process provided don’t work and I suppose it is because the bulb is not in flashing mode. How can I get it?
use gitHub Desktop: (file-> clone repository…choose URL…enter in TuyaAPI/ cli…and select c:\openhab2\userdata\etc\scripts directory). Now you have the repository in the right place. open power shell with admin and type “npm install -g” at the cli directory
to see if it installed it globally try out the command at the C:\ power shell prompt:
tuya-cli help
clone the repository unparagoned/ njsTuya and place it in c:\openhab2\userdata\etc\scripts. in power shell change dir to njsTuya and type “npm install”, leave off the -g flag. You only need to install tuya-cli as a global command.
clone the repository TheAgentK/ tuya-mqtt , and place it in c:\openhab2\userdata\etc\scripts. in a power shell window change directory to tuyaapi_mqtt and type in “npm install”, again leave off the -g flag.
Each install must not produced errors, if you get WARNing that OK. If if finds vulnerabilities do nothing.
once you get all that installed the tuya-mqtt.js file needs to be installed as a service.
so i found this topic:
From the topic you find out to just installed qckwinsvc by:
open power shell with admin, type “npm install -g qckwinsvc”
Now, after you installed qckwinsvc, ran qckwinsvc in cmd.exe with admin and answered the questions.
as follows:
qckwinsvc
tuya-mqtt
Server that converts MQTT topics into commands for tuya plugs and bulbs
c:\openhab2\userdata\etc\scripts\tuyaapi_mqtt\tuya-mqtt.js
y
before running tuya-mqtt.js make sure you copy the config.json.sample to config.json and edit it for your system settings.
Ensure the tuya-mqtt is running as a service. Go to control panel–>administrative tools–>services.
tuya-mqtt should be listed in Services and the status should be running/ automatic. If it is not showing “running” then right-click and select “start”.
The tuya-mqtt.exe is now installed as a service and will be set to run again when you log off or the system reboots.
tuya-mqtt is the client at 127.0.0.1 and will now be listening on your openhab server running on windows 10. Tuya-mqtt.exe basically converts the MQTT topic to a command that the tuya plug or tuya lightbulb can understand. So that is why you need the Tuya-mqtt.exe file running on the system always. With out it the tuya device would not understand the MQTT protocol. These tuya devices nativaly talk over TCP port 6668.
Now follow THE ABOVE GUIDE right after the tuya-mqtt.js script is running.
Find all your Tuya-Devices IP address, DeviceID and LocalKeys. I used the following technique to find mine:
it uses:
To interface with openhab2 follow the instructions for “Update for MQTT-Binding 2.4”
I have both lights and plugs so for the <tuyaAPI-type> use “lightbulb” for the lights and for smart plugs use “socket”. Also make sure you do the copy of the “config.json.sample” to “config.json”. Because the “config.json” needs to be there. I did not edit mine. I just used 127.0.0.1 which is the default.
To use the tuya-mqtt.exe server you will need to use the embedded-MQTT broker.
NOTE: THE EMBEDDED MQTT BROKER can be found at:
ADDONS —> Misc.-----> “MQTT Broker Moquette”
or you could install Mosquitto on your machine. Here is an excellent step-by-step guide in how to install mosquitto on windows and linux machines
I used this Steve’s mosquitto files (see below). I only downloaded from his site because his mosquitto files were the only ones that passed www.virustotal.com virus scans. They had no viruses in them at all. Be care of other mosquitto files downloads. To be sure go to virustotal
and upload the file before you install it on your machine.
Here is the URL to the excellent step-by-step guide to mosquitto,
there are many Tuya apps to use on the App Store. He uses Smart Life by Tuya Inc. I use Smart life+ by RSH - TECH Company. Not all Tuya Apps will place the information in the “shared_prefs” folder. For Smart life+, I had to go to /data/data/com.rshsmartlife/shared_prefs/preferences_global_keyxxxxxxxxxxxxx.xml
you just need to install the app you use and check in the right folder to see if the information is in the .xml file. If not I would delete the devices from your App and use the Smart Life App for Tuya Inc. Then follow his directions
Today i have added a new device on my smart life aplication, and i have followed the steps to get de global key of the device but, the preferences_global_keyxxxxxxxxxxxxx.xml does not have the information of any device.
Something changed in the last days?
I had the same issue. I posted above the way I got my details using an android phone, I didn’t use bluestatcks as I was unable to install the certificate.
Hi!)
I’m very new with Nodejs. I tried to do each step as right as in the instruction, but I have stopped at the starting “tuya-mqtt.js” with an error:
/etc/openhab2/scripts/tuyaapi_mqtt/node_modules/tuyapi/index.js:4
const {EventEmitter} = require('events');
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/etc/openhab2/scripts/tuyaapi_mqtt/tuya-device.js:1:78)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
If not please give me some ideas on how to control such a plug with OH. I scanned the binding list but could not find one to use with this device.
Many thanks!
I know it works with these smart plugs, i run openhab 2.5.0 on a windows 10 machine. I use a MQTT broker from a raspberry pi , just make sure you use “socket” instead of “lightbulb” in the tuya/ topic
I have zero MQTT experience and this will be my first integration with MQTT. I’m not yet familiar with the MQTT lingo and it would be very helpful for me if I could see how different pieces connected together. Based on the guide above and your message, I guess this is how the pieces are connected together:
yes, thats the flow of information. You need to decide if you will use the OpenHAB embedded MQTT broker or have one in your network somewhere. I was having trouble with the embedded option so i build a raspberry pi magic mirror and its running my MQTT Broker.
so OPENHAB <> MQTT-Binding[Embedded MQTT Broker Thing]<>MQTT-Generic-Thing<>Tuya-mqtt-Client(aka topic)<>Smart Plug
what you need to see here is that After you install the MQTT Binding the first thing you do is ADD the MQTT misc Embedded MQTT Broker then Define the MQTT Broker to use the embedded broker as a bridge broker. Then you finally define a MQTT-Generic-Thing that links to your smart plug and tells the system to use the MQTT Broker with commands like this
one for state:
tuya/socket/XXXXXXXXXXXXXXXXXXXXXXX/192.168.0.19/state
one for command:
tuya/socket/XXXXXXXXXXXXXXXXXXX/192.168.0.19/command
Thank you for sharing this. Could you give an example of your channel settings? Do you use OH2.4 with tuya-mqtt from AgentK or maybe also with the fix from tsightler?
I’m not able to get any dps value shown in OH2.
What I have done so far:
I have added a Channel(Channel Type:Text Value) to my Generic MQTT Thing.
In the channel I set MQTT State Topic to:
“tuya/socket/82141708dc4f22905494/XXX/192.168.178.38/dps/6”
Linked this channel to an item.
In PaperUI the value for the item is only “-”… Thats all I see
I can switch Power ON/OFF with tuya-mqtt from tsightler and OH2.4. But I am not able to get any other dps value shown in PaperUI or BasicUI.
Btw. thank you to all other developers and to the community. I am very new to OH, but I found many helpful explanations and add-ons here.
That’s an interesting way to handle it. So far, I have specified everything for tuya in the PaperUI, nothing really worked fine. But I will try this also and specify everything in files.
Which version of AgentK’s implementation are you using?
I was using master branch, commit 53811376843cca325fee83cd935c645c0c1863f4 to be specific.
The reason I did it in files was just because it was easier to then add new plugs - it was a case of copy/paste and change a few values. I think PaperUI should work, but I haven’t tried it.
It’s not working for me. I handled it the same way. But my smart plugs won’t switch reliable if I use OH2.4.
I tried it with the old 1.x-Binding and Mosquitto and everthing is working fine. On is on, Off is off, absolutly reliable and without any delay.
I tried many different settings with OH2.4 and MQTT. In one setup I was able to switch the plugs, but there was ab big delay and it was not reliable. In this setup I connected the things driectly to the embedded broker of OH2.4.
In the other settings I often received an error from the tuya-mqtt.js. Sounds like something is preventing the communication to the device:
"at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
(node:22334) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing i
nside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (reje
ction id: 5) "
Another stupid thing is. I have two smart plugs and I can switch the one more reliable than the other… Dont know why. The Id and the key of both are correct, they work with 1.x and Mosquitto.
After frustrating hours of trying I went back to my 1.x setup with Mosquitto… But with this setup I’m not able to observe the dps output of the devices… Or?
Maby somebody has an idea? I’m grateful for any help!
Thanks Holgi. I just checked and node was already installed on my RPi .
Currently, I’m having the "“Permission denied (publickey)” problem when trying to download AgentK’s Tuya-MQTT-Client. I saw your #5 post above on how to fix that but have not yet implemented it.
Thanks to this Project.
I was now able to handle my GOSUND SP111 Socket with openHAB.
For those who still trying to get the localkey and do not have root access on android.
Check the man in the middle method, using Burp Suite as Proxy with your Smartphone to capture the traffic and find the localKey.
In openHAB I needed to extend the Things Settings to work with the GOSUND: