Section 13: API
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:
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:
- Log in to your router and look for a device called "valar-systems". Open it up and find the IP address.
- Download Angry IP and scan for the Hostname "valar-systems.lan" and copy the IP address.
- 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.
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.
You can see here that we get a return of the position in JSON for the current Step position.
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.
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.
- Section 0: Background
- Section 1: Hardware Setup
- Section 2: Stepper Motor Basics
- Section 3: Arduino Setup
- Section 4: Understanding Trinamic Drivers
- Section 5: Setting Trinamic Drivers
- Section 6: Power Requirements
- Section 7: StallGuard
- Section 8: FastAccelStepper Library
- Section 9: ESP32 Dual Core Setup
- Section 10: Motor Setup
- Section 11: Preferences Library
- Section 12: ESPUI
- Section 13: API