Section 13: API

You are viewing Section 13 of 13

We can have other devices control our motor, all while we sit back and relax. 

For example. We can create an automation like this:

If you Nest thermostat turns on the air conditioning, notify Home Assistant on our Raspberry Pi. Then have Home Assistant trigger your VAL-2000 to automatically close your window for you, saving electricity just in case you forgot to close your windows!

 

That isn't just a dream, this is something I do at my house every day. Here's how:

WiFi Setup

First we need to put the VAL-2000 onto your network. Right now we are only connecting to it directly. By putting it on your network you do not need to disconnect your WiFi from your computer.

Click on the "WiFi" tab at the top of the screen.

NOTE: Only 2.4 GHz networks will work. Do not connect to a 5 GHz network. If your router supports both, it will automatically connect to the 2.4 GHz network.

Enter your WiFi name and password and click save.

 

The ESP32 will now disconnect from your computer and connect to your network.

Connect your computer back to your WiFi network.

We now need to find the IP address of the ESP32. There are many ways to do this, here are a few:

  1. Log in to your router and look for a device called "valar-systems". Open it up and find the IP address.
  2. Download Angry IP and scan for the Hostname "valar-systems.lan" and copy the IP address.
  3. Using your iPhone on the same WiFi network, download the app Network Analyzer. Scan your network for "valar-systems.lan" and copy the IP address.

Once you have the IP address, enter it into your browser. You can now access the device locally.

 

API Setup


Let’s navigate to our GUI interface and click on the API tab


Here you’ll notice that we have 2 different API endpoints.

This first one allows up to set the position of the device from 0 to 100 percent.

The second one allows us to see the current position of the device

Let’s open up a new browser window and enter the settings API into the window.

http://192.168.4.1:8080/settings


You can see here that we get a return of the position in JSON for the current Step position.

{"position":30000}


Now let’s change the position. We simple copy all of this into the browser and change the percent to whatever we want. Here we use 50 percent.

http://192.168.4.1:8080/position?percent=50

And now the motor will move to that position.

You can use this in conjunction with almost any system that can make GET requests and completely automate your device.

 

Course Sections:

1 comment

  • Excellent Tutorial. Thank you so much for your thoroughness and details to explain the code and mechanics. It has been of great help.

    Roi

Leave a comment