Tuesday, 2 October 2018

Controlling Tuya (Smart Life) Devices from IFTTT


I have a number of Tuya (Smart Life) lightbulbs and while these are integrated seamlessly with Amazon Voice Services and Google Home, I would also like to be able to control remotely, via Python and also directly by voice from my XMOS VocalFusion™ Stereo Dev Kit (https://www.xmos.com/support/boards?product=37033).
I looked into the Tuya API (https://iot.tuya.com) and decided that it would be much easier to control the lights via IFTTT.

Here is a step-by-step guide.

First we need to enable Webhooks, to allow us to trigger the event via a URL. To do so, search for “Webhook” here : https://ifttt.com/search

Click on "Webhooks" and activate it.


This will give you a URL that looks like : https://maker.ifttt.com/use/xxxxxxxxxxxxxxxxxx
Where xxxxxxxxxxxxxxxxxx is your key, which we will use later.

To create a private Applets go to : https://platform.ifttt.com/p/username/applets/private - note the username is your IFTTT username.



Click New Applet and fill out the fields :




Note for triggering events using URLs I find it easier to ensure there are no spaces in the trigger name e.g. “Turn_On_Light”.
Scroll Down to Action and enter the details :




Enter a Title and Description. I just used “Turn On Light”

Click Save.
Click “Enable On IFTTT”
Turn The Applet On.


You can also create an Applet to turn off the Light. Or to make it easy, just go to the Applet Preview Page and hit “Copy” for the above Applet.
Modify the details of the new Applet and click Save.

You can view your private Applets here : https://platform.ifttt.com/p/username/applets/private

To test your Applet go to here : https://maker.ifttt.com/use/xxxxxxxxxxxxxxxxxx

Enter then name of your Applet “Turn_On_Light” in {event} and click “Test It”.

Now our Applets are setup and tested we only need the URLs for turning on and off the light, these are :

https://maker.ifttt.com/trigger/Turn_On_Light/with/key/xxxxxxxxxxxxxxxxxx

https://maker.ifttt.com/trigger/Turn_Off_Light/with/key/xxxxxxxxxxxxxxxxxx

To trigger the events, just open up the above URLs in a browser and you should be able to remotely control the light.

Alternatively, using Python requests you can do :

import requests
requests.post("https://maker.ifttt.com/trigger/Turn_On_Light/with/key/xxxxxxxxxxxxxxxxxx")


No comments:

Post a Comment