TUYA API (Setup, Basics and FREE FINGERBOTS)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's video we're going to be having a look at the two-year api we're going to be having a look at how we can control our own iot devices with the two-year cloud and also how we can go about starting our own projects to utilize the two-year api and if you stick around till the end i'll be sharing details on a two-year competition you can enter to win yourself some amazon vouchers or some of these to your fingerbots check it out [Music] what's going on guys i hope you're all doing well today we're going to be having a look at the 2 year api and as i said we're going to be looking at how we can control our own iot devices with that api we'll be doing a full run through of creating the 2a developer account creating a cloud project and enabling the different apis we'll then also add our iot devices to that project and then start controlling them if you're a subscriber of my channel you will have seen in the past i've done a couple of other two-year videos i've done a standard two-year integration video and also a few different local two-year videos and if you're new here then don't worry we're going to be starting from scratch doing a full run through and if you hit the subscribe button and ding dong the notification bell you'll be alerted to any future video that i do to keep this video relevant to you and to allow you to just access the bits of information that you want this video will be chaptered you can find those chapters in the description below and here's some of the head-ins that i'll be using so who or what is a two-year 2yet is a global internet of things platform or iot platform that enables products for consumers brands manufacturers and much much more 2year doesn't produce the smart home devices but rather creates a smart home platform that allows manufacturers to easily create and develop their own devices and utilize the to your cloud so to think of this in a simple manner do you deal with the back end and deal with the whole cloud connectivity of getting the smart devices connected through the cloud and that cloud connectivity is what allows you to control your devices from anywhere in the world so manufacturers register their devices on the two-year platform which allows them to then utilize this to your cloud you can then control these products through the cloud using either the provided manufacturer app or the standard two-year or smart life apps the 2year app and the smartlife app are probably the most common ones you'll see and you'll see these dotted around all over the place and you'll also see them listed on packaging for two-year devices these apps allow you to configure and control your devices you can do things like creating simple automations or scenes for your devices you'll see lots of smart home devices and iot devices that use the two-year cloud and that's just because it's simpler for a manufacturer to just work with a two-year platform and have two deal with the backend and it's not just manufacturers that it's simplified for it's also simplified for developers and that's because two offer a wide range of different apis tools and services that developers can utilize to create their own apps and to just connect to the two-year service and yeah that all sounds great but what are the pros and cons of two-year to start with any two-year compatible device is also compatible with the two and the smart life apps which as i mentioned are the most popular apps so all of these devices are compatible and just work within this one app as the two-year devices connect to the two-year cloud you can connect to any of your devices from anywhere in the world providing you've got an internet connection the vast majority of the two-year devices just work straight over wi-fi so there's no need to buy any additional gateway or any other bits of tech to integrate with other third-party services like amazon alexa and google home so you can add voice control to all of your two-year devices and probably the last and most important pro that i can think of is the two-year service is free for the consumer so there's no monthly subscriptions or any subscription of any kind you buy your device you connect it to the cloud and that's it so that's the pros for two year what about the cons first of all is it's cloud connected now some people would see this as a disadvantage and other people probably just wouldn't care so it kind of depends where you sit with the whole having your all of your information stored within the cloud next up we've got latency so sometimes devices can be a bit slow to react so for example you turn on your light sometimes it might take a couple of seconds to actually turn on and other times it'll be instant and again that will be because it's cloud connected so it actually needs to send a signal out to tell to you to send the command to actually turn the light on now it's not ridiculously slow or anything like that it's just sometimes with that latency you do have that delay and if you compare that to say a zigbee bulb you would see the difference in the speed my next con then is the device configuration now i think this is because there's so many different two-year devices there's lots of different ways to do the configuration some of the devices can be quite complicated and they can be things like you know hold this button for 10 seconds and then double press this button then do a backflip and you know and again that's not all devices it's just some of the devices have quite complicated setups another disadvantage is that you're fully reliant on the cloud so if whatever reason two-year is down or your network can't connect it to you you're not going to be able to control any of your devices and for my last connect then i'm gonna go with product saturation and what i mean by this is just that because two you're so openly available and manufacturers can just build on their platform you sometimes get lots of different manufacturers creating the same type of product so for example if you did a search on amazon for to your light bulb you'll see that lots of products are all made by different manufacturers but they actually all look the same so those were my pros and cons for two year let me know in the comments below what yours are you should now have an idea of who to you are and what they do so let's delve into that api and start controlling our devices okay so we're here on the main two-year developer web page and at this point there's a few things that i assume you've already got set up so if you're watching this video you're most likely interested in having to play around with the two-year api so i expect you've already got the two-year app or the smart life app set up on your phone and if you've got the app installed i'm assuming you've also got a to your account and you've also got a couple of devices linked to your account so maybe you've got a couple of smart plugs or a couple of smart bulbs if you haven't got those things set up you can still follow along with the video but i'm working on the assumption that you have those things and the demo and everything i do will be working as if you have those things so we're going to be linking to and connecting to our devices that are in either our twoyear or our smartlife app and if you're happy with that we can finally get started there'll be a link for this page in the description below so go ahead and click that once you've got this opened up we're going to click on iot platform in the top right there it's then going to ask us to fill in our account information so we're going to need to give it our email address our password it's also going to ask for a company name for the company name you can put whatever you want next up is going to ask us to set our country or region now i'm uk based but if i set the uk here i have to do a couple of extra steps where i have to get in touch with two-year and get them to reconfigure some things on my profile just to allow me to actually access and use the cloud you can do this if you want to but there will be a delay because you've got to wait for two-year to go in and change the account settings sometimes this can just be a few minutes but if two are quite busy they do say that the estimated weight could be 12 hours so for the purpose of this demo i'm just going to set my region to be usa that way it'll be instant and i haven't got a way around i'm not sure what this is like for other regions as i've only tried it with the uk but if you do try it with a different region other than the united states of america there is a chance you may have that delay and again the delay can be anywhere from within a couple of minutes to a couple of hours so we've got all of our information entered here we're now just going to click agree and then we're going to click the big orange agree we're then just going to complete the capture and it should prompt us to do an email verification so if you check your email for the account you just signed up with you should have a verification code so just grab that and then paste that in here and then we can just simply click on create account that's then just going to bounce us back to the login page so enter your username and password there and hit login the first time we log in we're going to be presented with this little helper pop-up this is just going to show us how to navigate around the two-year dashboard so you can read through this at your own pace but i'm just going to skip through this now so i'm just going to press continue next next and next so this is the 2-year developer dashboard on the left-hand side here we can see all the different developer tools that we have access to along the top we've got all the different help options and the documentation for the developer tools and in the bottom right just here you've got a little help services button so you can submit a help ticket or you can speak to a member of the two-year team now that we're on the tv dashboard the first thing we're going to want to do is to create a cloud project to do this we're just going to click cloud on the left-hand side menu here we're then just going to click on projects at the top if you've followed along with my steps so far you'll hopefully see a screen like this where we're going to be subscribing to the cloud development platform if your screen doesn't look like this and you've got a little pop-up like that that'll just mean the country or region you registered your account with currently doesn't have access to the cloud api depending on your region you'll either need to resolve this by verifying some extra account information or you'll need to open a support ticket with two-year and get them to change it opening the support ticket with two-year could take anywhere from a couple of minutes to a few hours so moving on we're going to just click on this free trial in the trial edition section and from here we're going to want to make sure that trial edition is selected and we're just going to click buy now that should then take us through to the cloud development plans and we should see the trial package that we just chose this will have opened in another tab so we can just now close this tab and head back to the iot platform we're then just going to press on the subscribe button here and we'll see a blank project section like this now that that's all done we can go about creating our project and the project's going to be what houses all the different bits we're going to be making use of so we're just going to click this blue create button in the top right this is then going to ask us for some information about the project so everything marked with the orange asterisk we're gonna have to fill in so we're gonna need to give it a name set the industry the development method and the availability zone so go ahead and fill in all of your details for the industry you're gonna wanna set this to be smart home for the development method you wanna choose smart home pass and for the availability zone you can choose multiple different ones for now i'm just setting it to be europe and we're going to hit create it's then going to pop up the configuration wizard and it's going to give us all the suggested apis for the industry we chose so i can see here we've got all the smart home ones which makes sense as we chose a smart home one we're just going to hit authorize there and that will then take us back to our project overview and in that we'll see the new project that we just created you might have spotted that i had another project set up this one makes use of the custom development but for the purposes of this demo we're just going to be sticking with the smart home pass one now that that's all done the next thing we're going to do is to link our app to the project to do this we're going to click link with devices you'll then see this blue add up account button in the right so press on that will then be presented with a qr code that we'll need to scan with either the to your app or the smart life app so on your mobile device open up whichever app you have in this demo i'm using the smart life app so i've got that open on my phone in the top right corner you're going to click on the blue plus button and then again in the top right corner you're going to click on the little minus you'll then just need to scan the qr code with your phone you'll then get a message asking you to confirm the login so press confirm login you should then see the browser page refresh and you'll get a notification on your phone to tell you that somebody logged into your account on the page here we can now see the app account that we just added so in my case it was the smart life app to the right of that i can see the amount of devices that have been pulled through with the app and if we click on those devices it's going to take us to the device list page from here i can see a list of all my devices so it's pulled through 18 devices and i can see that 17 of them are online and one of them is offline so we've now got access to the apis that we need we've set up a new project and we've linked our smart app to that project and what we can now start doing is utilizing the two-year api and start controlling those iot devices that we've linked and as i mentioned the iot device we're going to have a look at controlling is the two-year fingerbot and if you do stick around till the end of this video i'll be sharing details of that competition where you can go about winning yourself some of these if you want to know a bit more about the fingerbot then i do have a video coming out where i do a full setup and review and go through some of the practical uses of the device so the fingerbot is manufactured by a company called adderprox and the main idea of it is to retrofit devices and give them smart capabilities so for example you can turn on and off devices that don't have those smart capabilities so things like coffee machines and robotic vacuums the device is controlled by bluetooth and uses an app created with the two-year platform you can also link the device directly to your existing two-year or smart life apps in order to connect the fingerbot to the cloud you're also going to need the adderprox home hub the home hub will connect to your router and allow you to pass wi-fi signals and translate them into bluetooth signals so in our use case we're going to be firing commands at the fingerbot and the way that the fingerprint's going to receive them is the first going to pass through to the home hub the home hub is going to translate that and then pass that to the fingerbot so the home hub acts as the middleman between the fingerbot and the two-year cloud if you've got your home hub set up and you've also got your fingerbot set up then you'll be good to go now if you're making use of this tutorial to control another device for example a smart bulb then you're not going to need that home hub let's have a go then at firing some commands at the fingerbot the first thing we're going to need is the fingerbot's id to get this we're just going to click on device list at the top here in the device list you're going to want to make sure that you're using the correct app account and that the data center is also correct you're then going to want to just scroll through your devices until you find the one that you want i can see the fingerbot here and just underneath the fingerbot is the device id so i'm going to want to just copy and paste that and now that we've got the device id we can head into the api explorer so you're going to want to make sure you're in the cloud tab and then choose api explorer so this is the two-year api explorer and this is going to be where you do all of your experiment in and playing around with the various endpoints so in the explorer we've got three different sections we've got the device management the network management and device control and each of those three sections refers to different endpoints within the api that we can control and make use of let's have a look at this now then so we'll start off with the device management and we'll just have a look at the device status so choose get device status and in here it's going to ask us for the parameter of the device id which is what we just copied into our clipboard a second ago so if we just paste that in and then we can just press submit request this response returns some json and in that i can see information about the fingerbot so i can see there the battery percentage so this particular fingerboard has currently got 76 battery so from that we can see it's working we can see we can connect to our fingerbot and get information back using the api explorer let's now have a look at the device control so on the left there we're going to choose device control and we're going to want to click on get the instruction set supported by the device and again in here we're going to want to just enter that device id so just paste that in there again and hit submit request so this json that's come back is all of the different functions that the fingerbot supports so i can see from that it's got an option to switch and it takes the parameter type of boolean so if i called that one that would be the switch on and off it's also got a function for mode so again we could swap that between click and switch if it's a click it's just going to press the button and then come back up and if it's a switch it's going to go down and stay there until you switch it back off there's then also a few other functions in there so you can control the timer you can control the arm down percent you can also control the click sustain time and also the arm up percent basically any control that you can do within any of the smart apps that control the fingerbot you can do with this api and that's because those apps are created on the two-year platform and utilize this api just in case i didn't make it clear enough this bit on the left is all the bits of the api that you can control the bit in the middle is where you're going to set your post and get information for a particular device and then the bit on the right then is going to be your debugging information so this is where you're going to see any errors or responses from the devices and this top part here is a split pane so the first option that you've got is the debugging result that's where you're going to see all of your feedback and the next option over then the view document is just a bit of information of how the responses are formatted so let's have a look at that now so this is a bit of the api documentation and it's going to tell you a bit about the parameters and what it expects and what it needs let's have a go controlling some of those functions we mentioned for the fingerbot to do this we're going to click on control device and again we're going to want to enter the device id as we're going to be calling the api now we're going to want to swap back to the debugging result view just so we can see any error messages or feedback from the device what we're doing here is a http post for the device we've chosen which is the fingerbot we can see it's also asking for the body of this post and it's expecting some commands just next to the commands is this little question mark and if we hover over it it's going to show us an example command we can just click copy on that and then we can paste that into the commands to send this request we're just going to hit submit request there what we did here was called the example command now because that's just an example it doesn't work with our fingerbot so we got an error and we can see that it errored by in the response here the success type is false had that been successful the return type there would have been true there's also a little message in that response to tell us why it failed so we can see that it failed because the command or value is not supported if i just pull up a snippet here of the supported instruction set for the fingerbot you might remember the first one that was in that list was the option for switch so we can see there the code is switch and the type it's expecting is boolean in our command here we can see we're trying to call code switch underscore one which isn't supported by our fingerbot so the fingerbot is just looking for the code switch so if we take off that underscore one that now matches with what the fingerbot's looking for the second bit it was after was a boolean which is either gonna toggle on or off the switch we can see here we're setting it to be false so let's have a go at setting that to be true and seeing what happens when we call up here's the fingerbot then there's many like it but this one is mine and we're just going to hit submit request there and you can see it fires off the command let's have a go at pressing submit request again in the response there you can now see it's true and you can see that the fingerbot actually called and it did its little arm movement when you press submit request there is a slight delay but it's nothing major and if you think about what it's doing we're sending the command from our machine here which is going through the to your cloud down to our router to the adderprox hub and then to the fingerbot it's not a crazy amount of time but i'm going to press submit request now and i'll actually time how long it takes that one was pretty instant so i'll try and do it again having done a few test calls it takes anywhere from between two to six seconds for the actual call to go through let's have a look at another command then so we're back in the instruction set for the fingerbot and this time we're going to have a go at calling the mode so the code that we need is mode and the type is an enum below the type is a set of values that the enum can take so it could be either a click or a switch and back to our control device then so we're going to update our command here and instead of switch it's going to be mode for the value of this it's going to be an enum and there's two different enums we can choose from so it can either be a switch or a click let's have a go at swapping us out for a click so it needs to be in quotations i'm going to put quotes and then click i'm just going to go ahead and click submit request the robot should now be in click mode and what this means is the little robot arm is going to go down and then come back up to simulate a click now i think click is the default mode so let's have a go at changing this to switch and what the robot arm should do is just go down and stay down to do this all we're going to do is just swap out the word click for the word switch and then we're just going to hit submit request again so we can see there that the robot arm's gone down and hasn't come back up if we now call the original command we did the switch command and we give it the value true it should switch on and that should retract the robot arm let's give that a go now we've just had a look at controlling the device based on the instruction set another thing that you can do is have a look at the specification attributes so in the left hand menu there if you click get device specification attributes and again just enter the device id and hit submit request what we now get is a response that contains all the codes and all the different values that are applicable to those codes so these are all the different possible values for those attributes so let's pick a random one from the list we'll go for the charge status here in the charge status we can see that it's an enum type and these are all the different possible values for that enum so you've got the values non charging and charge done just for another quick example here and also to just contrast against the fingerbot i've got a device id here for a two-year light bulb and with this one i've just done the instruction set supported call and here's the response for that and again with this bomb we can see we've got the codes and the different values that we can make use of so if i was to do this similar thing to what we did with the fingerboard i could turn on and off the light and also adjust the colors and the temperature of the light bulb so that's been a quick look at the two-year api explorer hopefully from watching that you've got an understanding now of how you go about getting information about a device and also controlling that so just go and have a play around there is a ton of help and documentation on the website and you can also do a live chat and support with the two-year engineers in addition to the two-year api explorer there are a few other ways you can make use of the two-year api one of the other popular methods is by using postman on the 2u website there's a full written guide and i'll have this linked in the description so two you give you instructions for the whole setup of postman and they also include some environment files these environment files contain everything you need to pre-populate 15 different requests if you've never used postman before it's a handy tool that you can use to make use of exploring and testing apis one really nice thing about using postman with the two-year api is that you can save everything if you watched my local 2u videos you'll know that i created a console app to extract the to your local keys from a preference file i do plan on updating that console app with giving it the ability to connect to the two-year api and extract the keys from the api as well as updating my key extractor tool i plan on creating a video where i'll be using the two api to control and interact with a robotic vacuum that i've got we'll then be utilizing that information and turning it into web requests which we'll be calling with a python script and using home assistant to call those python scripts and as i further develop that i'm going to try and turn it into a full-blown home assistant integration and if that sounds like a project you'd be interested in make sure you hit the subscribe button and ding dong that notification bell so the bit you've all been waiting for the two-year competition now the best thing about this competition is it's totally free and all the materials you need are all provided and even better yet if you followed along with this video you'll actually be eligible for some of these prizes already two yet are currently running a competition to encourage developers to develop content for their platform the competition prices include a seven dollar coupon a finger bot and a 35 amazon voucher so for the competition there's four different missions that you can do in order to get those three prizes the first one is for developing an app for either android or ios using the two-year sdk the second one is for linking open source hardware to the to your cloud platform the third mission is for controlling devices with either home assistant or home bridge and the last one is for just developing an automated system using the two-year api so choose one of those four missions and then you'll be able to just follow the four steps in order to get your prizes so here in the first one we've got the two-year iot app sdk so this one's for creating that app for android or ios you've then got the open source one the home assistant one and the two api one again if you followed along with this tutorial you will have actually done that to your api one so let's click that one so step one is register for a two-year cloud platform which you did step two is to create a cloud project which you've also done and for that one you'll be rewarded with a 50 off coupon for a fingerbot and step three is to just request api permissions which again if you followed along you will have done so as you would have done those three steps you should be eligible for a free fingerbot and if you're still not sure of what the fingerbot is be sure to check out my setup and review video of the fingerbot when it's live to complete step four of this particular mission you'll need to create something and then upload it to github and then you'll need to share that with twoyer as i mentioned i will be doing some work on my console project to connect it to the two-year api and also creating some python scripts to connect to the api and i'll be sure to share that work with you and other examples which you can use to base your foundations off in order to help you with that mission for if you've got any questions about the competition there is a handy little faq on that webpage for the competition so go and check that out if you're still stuck then be sure to message the two engineers for any more information so go and give it a go win yourself some fingerbots and potentially some amazon vouchers let me know in the comments below any cool ideas you've got for the fingerbot and which of the four missions you're going to have a go at doing if you've enjoyed this video don't forget to drop it a like right here if you found this video interesting or you like the sound of any of the upcoming projects that i've mentioned then be sure to hit that subscribe button and if you ding-dong that notification bell you'll be alerted to whenever those videos come out before i go i wanted to say a big thank you to tuya for giving me early access to this competition and an even bigger thank you to these awesome dudes who are my patrons thank you guys for supporting my channel and if you're interested in becoming one of these awesome dudes be sure to check out the link for my patreon in the description below so thank you for watching and i'll catch you in the next one [Music] cheers [Music] you
Info
Channel: Mark Watt Tech
Views: 33,034
Rating: undefined out of 5
Keywords: MarkWattTech, HomeAssistant, Hassio, Home Assistant, Smart Tech, Smart Home, Mark Watt, Automations, Home Asistant, tuya, iot, development, api, control tuya, tuya developer, setup api, configure api, adaprox, setup fingerbot, fingerbot
Id: w-BawMpxBYs
Channel Id: undefined
Length: 26min 2sec (1562 seconds)
Published: Sun May 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.