Support for Smart Life (Tuya Smart Plug) devices

Forum rules

Questions about hardware that can be controlled by Indigo (but not through the interfaces and plugins listed). If Indigo doesn't support some bit of hardware you're interested in, and you don't find a 3rd Party Plugin for it, add it to this forum. Be sure to include links to as much information as you can find about it.

Note: adding it here does not mean we're going to add it - in fact it's possible one of our 3rd party developers may decide to write a plugin for it. We add hardware/features based on a lot of different factors beyond just having a request for it.

Posted on
Wed Jan 10, 2018 6:25 pm
madscientist offline
Posts: 78
Joined: Jan 05, 2007
Location: Ontario, Canada

Support for Smart Life (Tuya Smart Plug) devices

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
Last edited by madscientist on Fri Apr 19, 2019 1:07 pm, edited 1 time in total.

Posted on
Wed Jan 10, 2018 7:08 pm
Different Computers offline
User avatar
Posts: 1858
Joined: Jan 02, 2016
Location: East Coast

Re: Support for Smart Life devices

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.

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Posted on
Wed Feb 20, 2019 9:21 pm
madscientist offline
Posts: 78
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: Support for Smart Life devices

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

Posted on
Fri Apr 19, 2019 2:05 pm
madscientist offline
Posts: 78
Joined: Jan 05, 2007
Location: Ontario, Canada

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

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])

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests