PHPUnit Triggers Lights0:28
blinking green when they pass. Again, not very practical, but sometimes you just got to have some fun. I find it incredibly cool that you can use a standard REST API to control a piece of hardware, in this case, our lights. So let me show you PHPUnit, and let me show you the lights blinking red when our tests fail. So I'm going to run phpunit, and you'll see the light turn red when the tests fail, or blink red. There we go. So our tests fail, and you can see the light blinking.
Using Bridge Debug Client2:23
So if you look at the documentation here, you'll see that once you get the IP address, we can just go here. So let's go there. So it's .2, .23, /debug/clip.html. So I believe it's in my history, so I'll just do it here. Okay. And here we have a REST client for our lights. So let's take a look at the next step. So we have this. And what we need to do is make a POST request so we can get a User, so we can start making
Creating API User2:48
So we have this. And what we need to do is make a POST request so we can get a User, so we can start making calls to the API. So we want to make a request to /api, and it's a POST request, and we want to give it a device name. So in this case, this is the name of the device. Let's grab this. Let's go here, and let's go /api, and let's paste it in the body. And let's name our device Laracast Hue. So let's say LC Hue.
Listing Connected Lights3:40
The bridge is underneath my desk, so give me a second. Okay. So I reached underneath my desk and I pressed the button, so let's make another POST request. And now we get a success, and there is our username. So let me grab this, and let's go ahead and make our first request. So back to the docs, let's see what we can do here. So this is the username that we saw, and we want to get information about our lights. So it's /api/username/lights. So let's do that. So let's paste in the username here, and let's say /lights.
So let's do that. So let's paste in the username here, and let's say /lights. So this is going to be the endpoint for all of our lights connected to our bridge. So in my case, I have three, and you'll see that when I press get, and there's one, two, and three is here. And you can see the state of that light, like on or off, and the hue, saturation, and brightness, and so on and so forth. So let's look for my off lights. So I believe the ID of that is three, so let me look for three. There it is, and it's off right now, as you can see.
So if I hit get, there we see my two groups, one living room and two office. And you can see the lights associated with them. So I only have one for my office, and I have two for my living room. So back to the docs. Let's go ahead and turn a light on or off. So this was the get request. And now we want to get certain information about a certain light. So we can do /lights/{id}. So in our case, we want 3, because that's the ID of this light over here. So lights/3, get, okay.
Turning Lights On/Off5:49
So in our case, we want three, because that's the ID of this light over here. So lights three, get, okay. And how do we turn on or off the light? You can see it here. We just have to make a PUT request to this endpoint, so /state, and then give it this JSON. So if I go here, /state, and let's say on is false. So you should see the light turn off here if I make a PUT request. And there it turned off. Cool.
Controlling Light Groups6:35
So if you want to do groups, and my groupId is 2 for my office, and I believe the endpoint is action, and the body is the same. So let's say false. PUT request. That should turn off. It does. And true. PUT. And that turns on. Cool.
The scale might not be the same, but you can just use math to change it to this scale over here. So, yeah, that's basically it for the API. Remember, you're not limited to just this client over here. You can use it anywhere you like. So in this case, for this Vue 3 app, I'm using Axios. And for PHPUnit, I'm using just the Laravel HTTP client. And this is the basis for all apps that you use on your mobile app. For example, I have one running on my computer here that uses Alfred, and I can control it here as well.
