My Tuya devices - sockets and thermostat

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

My Tuya devices - sockets and thermostat

Post by Westcott »

Hi all,
Last November I bought a couple of Anoopsyche SP-G01B2 WiFi sockets with energy monitoring.
There are lots of similar ones from various brands.
My original plan was to open them and flash ESPeasy, already on several other of my devices.
There was no obvious way to open then, but they were reported to be Tuya standard.
So I used tuya-convert to flash OTA with Tasmota.
Someone had kindly created a template for this device, so they are now nicely integrated with Domoticz, including energy and voltage monitoring.
It also made me start using MQTT.

For Christmas I bought a "Programmable Touch Screen WiFi Thermostat".
This would have been easy to flash, but the touchscreen display commands are unknown. It is however a Tuya device.
Instead I discovered the wonders of Node.js and the TuyAPI library.
It's taken only a few lines of Javascript (Node.js code) to read and update the thermostat with MQTT., without using any other programs or plugins.
If I'd known at the time, this is how I'd have done the sockets as well.

If anyone is interested, I can give more details.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
hanryz
Posts: 27
Joined: Monday 31 October 2016 23:18
Target OS: Windows
Domoticz version: 3.5837
Location: Netherlands
Contact:

Re: My Tuya devices - sockets and thermostat

Post by hanryz »

Hi, if the offer is still on the table, I would like to take it:) Please allow some questions:
1) How did you read out the LocalKey of your WiFi thermostat?
2) Are you able to locally control it, without it being connected to the Tuya cloud?
3) How did you integrate it into Domoticz?
Sorry if they are too many, my questions:) Any info will be highly appreciated. Thanks!
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: My Tuya devices - sockets and thermostat

Post by Westcott »

Hi Hanryz,

Yes, I got it all working, but have since gone forward to ZigBee instead. Much more open and far easier.
Anyway -
1) How did you read out the LocalKey of your WiFi thermostat?
That was a real pain, and needed much Googling.
I ended up using BlueStacks to emulate Android, and installed Tuya's SmartLife app. This paired with the thermostat, and wrote the local key into a folder that was readable. Otherwise you have to 'root' your Android device to read that folder.

2) Are you able to locally control it, without it being connected to the Tuya cloud?
Yes, read its temp, and set the setpoint. All local, no cloud! :)

3) How did you integrate it into Domoticz?
As part of a Node.js program and MQTT. There's a library to read and set the Tuya values, and MQTT to send them to Domoticz devices by idx.
You have to create the devices yourself.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
hanryz
Posts: 27
Joined: Monday 31 October 2016 23:18
Target OS: Windows
Domoticz version: 3.5837
Location: Netherlands
Contact:

Re: My Tuya devices - sockets and thermostat

Post by hanryz »

Hi Westcott,
thanks a lot for your quick reply and the hint with the Android emulator to read out the LocalKey, that's really useful.

However, I guess the Node.js program you meant is the implementation of the tuyapi by codetheweb guy, from here https://github.com/codetheweb/tuyapi isn't? If so, did you also need to install the tuya-cli subscript to get it to work? Thanks again...

P.S. only because you touched on Zigbee, just my 2ct: Zigbee is (at times much) more expensive and the operating range of it more limited as compared to WiFi which works over my whole house. Further, the direct Google Assistant integration of Tuya is quite valuable to me (I know you can do it through various plugins in Domoticz and MQTT, but, it is a workaround then). Finally, Zigbee integration with Domoticz cannot work without both, the Domoticz and a separate MQTT broker running all the time, while as a last resort, you always have your Tuya app to control your devices. I believe Tuya has a brighter future, but I may easily be wrong as well:)
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: My Tuya devices - sockets and thermostat

Post by Westcott »

Hi Hanryz,

Yes, that's the library I used, with his sample code in my big 'mqtt2domoticz' program.
No, I didn't need tuya-cli, his code was enough.
My 'mqtt2domoticz' program replaces all Domoticz plugins that might otherwise be needed. NIH!
I agree that WiFi devices are very affordable, and I have several, directly with Yeelights, and various switches with Tasmota and ESPeasy.
Zigbee allows me direct access to the device parameters, with Domoticz simply as a GUI.
The Zigbee devices I get from AliExpress are hardly more than the equivalent WiFi ones, and the battery sensors have a very long life.
Interestingly, there are Tuya compliant Zigbee thermostats, mains and battery.

I hope you don't think me patronising, but your English is perfect!
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
hanryz
Posts: 27
Joined: Monday 31 October 2016 23:18
Target OS: Windows
Domoticz version: 3.5837
Location: Netherlands
Contact:

Re: My Tuya devices - sockets and thermostat

Post by hanryz »

Hi Westcott,
thanks a lot for your reply and the kind complement regarding my English skill, much appreciated, especially when it comes from somebody who´s native speaker:)

yes, I´ve seen the Tuya Zigbee devices on Aliexpress and also their Zigbee hub which is, I guess, needed to get their stuff to work (you can of course go with zigbee2mqtt, but then you will loose Tuya Google assistant integration).

Nevertheless, later on I might decide to buy some of the Zigbee stuff just for fun. But first, I would like to get the WiFi stuff to work as it should in Domoticz using the Nodejs-based tuyapi and MQTT (btw I am on Windows, which makes it a challenge even more).

Turning to Tuya WiFi again, I managed to install the Android emulator (thanks again for the hint) and then to install the Tuya SmartLife app in it. Got the root access and looked into the shared_prefs folder. found "preferences_global_key<someid>.xml" file, as described here: https://github.com/clach04/python-tuya/wiki/Setup or here https://community.openhab.org/t/step-by ... entk/59371. However, the bloody file is just empty!! I cannot extract any Local Key from it. Which file did you read out to get the key? Thanks!

Btw, any chance to try your mqtt2domoticz app, if it is not fully proprietary, of course?
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: My Tuya devices - sockets and thermostat

Post by Westcott »

Hi Hanriz,
I'm Scottish, so I had to learn 'English' as well!
Ah, the local_key is actually only written by earlier versions of SmartLife, I seem to have 3.6.1 installed.
I posted the correct version in a relevant topic somewhere, I'll try to find it
You are welcome to my code, it is mainly an interface between zigbee2mqtt and Domoticz.
I use a configuration file to convert each device's properties to a domoticz/in topic.
You are welcome to it, a work always in progress.

UPDATE
This is worth reading -
https://community.home-assistant.io/t/w ... 019/140110
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
hanryz
Posts: 27
Joined: Monday 31 October 2016 23:18
Target OS: Windows
Domoticz version: 3.5837
Location: Netherlands
Contact:

Re: My Tuya devices - sockets and thermostat

Post by hanryz »

Hi Westcott, or, better, Guid mornin!
we learn something all the time, don't we:)

Thanks for the hint with the version number, got it, just in case I need it. In the mean time, I managed to read the dev key using the method from here: https://github.com/codetheweb/tuyapi/bl ... s/SETUP.md. Worked for me without pain (no idea if it stops once the trial period of tuya API cloud development service expires).

If you could point me to the place here in the forum where to start with your code, I would be very grateful! Thanks.
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: My Tuya devices - sockets and thermostat

Post by Westcott »

Here's 3 files, the maximum number of attachments.
More to come
Attachments
config.js
(739 Bytes) Downloaded 86 times
BulbEffects.js
(2.61 KiB) Downloaded 79 times
TuyaControl.js
(2.16 KiB) Downloaded 102 times
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: My Tuya devices - sockets and thermostat

Post by Westcott »

And 2 more.
NodeHelper is the 'main'
Rename configuration.js to configuration.yaml
Attachments
NodeHelper.js
(5.21 KiB) Downloaded 92 times
configuration.js
(10.88 KiB) Downloaded 109 times
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest