Page 1 of 1

Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Wed Jan 10, 2018 6:25 pm
by madscientist
I have recently installed an inexpensive WiFi plug-in switch and am wondering if it's possible to control it from within Indigo. The device support IFTTT, so I was thinking I might be able to control it using the Indio IFTTT plug-in, although setting that up is not straightforward. Is this the best approach, or is there an easier way?

Here is the device info: https://www.amazon.ca/Ardwolf-Required-Google-Control-Devices/dp/B074WM8M5V/ref=sr_1_11?ie=UTF8&qid=1515630122&sr=8-11&keywords=WiFi+Mini+Smart+Plug

Re: Support for Smart Life devices

PostPosted: Wed Jan 10, 2018 7:08 pm
by Different Computers
If it has an open API (almost certainly doesn't) that responds to URL requests, you could use Indigo to send those commands via the command line and the curl command.

Re: Support for Smart Life devices

PostPosted: Wed Feb 20, 2019 9:21 pm
by madscientist
It seems it does have an open API. Smart Life is just a rebranding of devices that use the Tuya cloud network. The API is provided here: https://github.com/codetheweb/tuyapi

There is also a Python port of the API here: https://github.com/clach04/python-tuya

I unfortunately don't know enough about programming to be able to use the information provided in the API to send commands via the command line, or to make a new Indigo plug-in, but it would be great if somebody with the right programming skills is up to the task. The Tuya / Smart Life devices are increasing in popularity and are very affordable. See for example these products: https://www.amazon.com/b?ie=UTF8&node=17915601011

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Fri Apr 19, 2019 2:05 pm
by madscientist
It wasn't easy and it isn't pretty, but I now finally have LOCAL network control of all my Tuya Smart Plug devices via Indigo. I thought I would share the details in case somebody finds this useful. Hopefully this will do until a Tuya device plug-in is developed.

1. Setup and register your Tuya smart plug using the Smart Life or Jinvoo Smart phone app. This step is required.

You will then have to obtain the Device ID, Local Key, and IP address for your Tuya device(s). The Device ID and IP address are easy to obtain, but obtaining the Local Key is more complicated.

2. To obtain the Device ID, open your Smart Life or Jinvoo Smart phone app, click on the device, click the edit icon at the top right (looks like a pencil), and then click Device Information. Your device ID can be found there (called Virtual ID).

3. Next you will need to find your Tuya device's local IP address. The IP address listed in the phone app is the WAN address. This is of no use. To obtain your local IP address, copy your device's Mac Address listed in the app, and then go to your router to find the local address. You will need to configure your router to use a static IP address (NOT randomly assigned by your DHCP server) for your Tuya device(s).

4. Now for the hard part of obtaining your device Local Key. You will need these installed on your Mac: CLI, XCode, Homebrew, Node and NPM

CLI: You can install it using the package installer available here: https://docs.cloudfoundry.org/cf-cli/install-go-cli.html.

Homebrew: You can install it by pasting this line in a Terminal window and pressing return:
Code: Select all
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


XCode: You can get this from the Apple app store. Howevever, you probably won't need to because Homebrew will offer to install it for you if you don't already have it. Be patient as it runs. It will take a few minutes.

Node and NPM: After installing Homebrew, simply copy and paste this line in a Terminal window and press return:
Code: Select all
brew install node


Next, go through all 9 steps described here: https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md. The process involves making your phone communicate through a proxy server running on your Mac. You will access the Tuya cloud via this proxy server using your Smart Life or Jinvoo Smart app. The proxy server will then intercept and identify your Local Key(s)!

5. Once you have the Device ID, IP address, and Local Key for your Tuya device(s), you will then need to install pytuya (the Python Tuya code) on the computer running your Indigo server. Simply copy and paste this command in a Terminal window:
Code: Select all
pip install pytuya


6. Now create an Indigo Action Group to control your Tuya device. It should set to run embedded Python code. Here is the code to turn on your Tuya device:
Code: Select all
import pytuya

d = pytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE')
data = d.status()  # NOTE this does NOT require a valid key
# print('Dictionary %r' % data)
# print('state (bool, true is ON) %r' % data['dps']['1'])  # Show status of first controlled switch on device

# Turn on switch
data = d.set_status(True)
if data:
    print('set_status() result %r' % data)


If you want to turn your device OFF, simply replace the "True" command with "False" at line 7.

You can also toggle your device using this code:
Code: Select all
import pytuya

d = pytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE')
data = d.status()  # NOTE this does NOT require a valid key
print('Dictionary %r' % data)
print('state (bool, true is ON) %r' % data['dps']['1'])  # Show status of first controlled switch on device

# Toggle switch state
switch_state = data['dps']['1']
data = d.set_status(not switch_state)  # This requires a valid key
if data:
    print('set_status() result %r' % data)

# on a switch that has 4 controllable ports, turn the fourth OFF (1 is the first)
data = d.set_status(False, 4)
if data:
    print('set_status() result %r' % data)
    print('set_status() extrat %r' % data[20:-8])

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Sun Oct 25, 2020 9:10 am
by SearchCz
Interesting, but how would I work this for a sensor? I don't want to send any instruction, I want to trigger actions based on a change of status.

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Sun Oct 25, 2020 11:34 am
by madscientist
SearchCz wrote:
Interesting, but how would I work this for a sensor? I don't want to send any instruction, I want to trigger actions based on a change of status.


I've actually moved away from the solution I posted earlier as it would intermittently stop working. I have had much better results with my Tuya <--> Indigo control using Node Red, which runs on a Raspberry Pi. If you aren't familiar with node-red, it's a great way of connecting all sorts of IoT devices that are not officially compatible.

You can get node-red Tuya control using node-red-contrib-smartlifeair, and Indigo control using node-red-contrib-indigo.

I have used it successfully with several Tuya smart switches for months. I'm not positive if it also works with sensors, but the node-red Tuya device does have a drop-down menu for inputs, so I suspect it will work.

I was having problems controlling my Indigo devices with Alexa (the Alexa-Hue-Bridge would intermittently stop working). The node-red palette called node-red-contrib-alexa-smart-home now provides very reliable Alexa control of my Indigo devices.

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Tue Apr 27, 2021 3:22 pm
by farberm
Is there any newer solutions for this other than node-red....

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Tue Aug 03, 2021 11:08 am
by freshwuzhere
Hi Farberm,

I will be working on this in the next few weeks - not promising a plugin but I’ll have a look at options for controlling my chicken coop doors that are driven by Tuya.

I’ll keep you posted on progress.

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Tue Dec 14, 2021 8:26 pm
by farberm
Any progress?

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Thu Apr 21, 2022 7:27 am
by dlleon
Same here. I'm looking to get <https://www.amazon.com/gp/product/B08HYLH8TG/ref=ox_sc_act_title_1?smid=A1IM8KN7ATY3I8&th=1> to replace a ton of Keypadlinc switches. Please let us know!!

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Thu Apr 21, 2022 5:51 pm
by GlennNZ
I had a look at this as well

Each user needs to sign up for developer account with tuya - a somewhat complicated process. This also seems to be renewed regularly. Access is all via
Cloud and not local - plenty of complaints about how well the tuya library works as well

It really wasn’t a user friendly process: doable plug-in wise just likely to cause a number of headaches…

Once sort out homebridge and python updates will think on some more …


Sent from my iPhone using Tapatalk

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Sat May 28, 2022 10:58 am
by boisy
I just found this thread.

This morning I went to my local Walmart and picked up two Mercury Smart Color LED bulbs for $10 (reduced price). They are Wi-Fi bulbs. I brought them home, downloaded the Smart Life app, and tried one out. It's pretty responsive.

Would be nice to see an Indigo plugin for these.

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Mon Sep 05, 2022 1:00 pm
by dlleon
HOOBS has a simplified Tuya web interface through HomeKit, perhaps an Indigo plug in could be based off of that? You just need the UID and PW for the SmartLife App, and it appears in HomeKit.

It's finicky, but it works.

I'm in the process of replacing all the dying stuff out with SmartLife, so if I could get this all working under Indigo, that would make life tons easier.

Re: Support for Smart Life (Tuya Smart Plug) devices

PostPosted: Wed Dec 07, 2022 2:37 pm
by 7rdr7
New to Tuya/Smart Life. Just swapped out my MR16 landscape bulbs for MR16 color changing Smart Life/Tuya bulbs. Works great on Homebridge. Would love to see it on Indigo to take advantage of better automation logic.