Monitoring and Power Control on a Dime Part III: Meters and API Access
(Note: Make sure to see Parts 1,2, and 4 in this series, where we explore other details!) In the last two parts, I decided to go through the process of building two sets of temperature probes. One used the DS18B20 and the other used the DHT11. Depending on which one was used for the process, the systems either has a simple temperature monitor, or a temperature and humidity monitor. In either case, live data can be retrieved from the Energy Monitor tab. Two readouts are given: One for each measurement.
The first thing to note is that the units of measurement can be changed through the “Customize” menu tab. If the user wants to have Celsius or Kelvin as the default for temperature instead of Fahrenheit, the dropdown can be adjusted and saved, at which point, the energy monitor tab will show outputs in that format. In the “Setup” tab and under the miscellaneous heading, the user can choose whether to use JPG, SVG, or PNG as the format for graphs and meters. (I use the SVG format.)
Once these selections are locked down, the task of actually creating the meters can begin. Creating a simple, one-segment display is very easy:
Click the “add meter” link in the energy monitor page. Give your new meter a nifty title.
Choose a data source, such as humidity or temperature. (Note: If you are using a DS18B20, you will only be able to use temperature.)
The “Minimal Value” will be set to zero and this needs to be changed. The important thing to remember is that temperature values will be in Kelvin. 273.15 is the equivalent to 32 degrees F or 0 degrees C, so use that.
For the width and height, use something reasonable and rectangular. The default values will work or you can make the meter larger. 256x128 works fine for my purposes.
Use a hex value (without the hash mark) to color the pointer.
Scale will be linear.
Number of decimal places. Two is usually fine.
Once the “save” button is clicked, the browser will return to the energy monitor, where the gauge will be collapsed. Expanding it again should reveal the temperature. As of right now, there will not be any gauge colors because those need to be defined next.
Click the title bar of the meter that is being edited. Below “meter properties,” find the “add sector” fields. In there, specify the name of this field.
Specify the range, from the minimal value to the absolute max, for this segment of the meter. For this demonstration, make it 40 degrees F. This needs to be in Kelvin, however, so the measurement should be 277.59.
Choose a hex color. Enter it in the color field without a hash mark.
Once all of the changes have been made, click “add.”
The click will momentarily refresh the browser and give another opportunity for a sector to be added after this one. Feel free to add as many sectors as are needed, in order, from lowest to highest maximum Once done, click “Save” on each sector as before, then finally, click “Back to Energy Monitor” when done adding new sectors.
If all of this was followed, the following should be the result:
While meters are useful for real-time data, they miss out on the benefits of giving historical data and some way of comparing current conditions with those from the last measured time periods. For that reason, The Web Power Switch also supports graphing of temperature and humidity data. To create a graph of temperature data, choose the energy monitor and click “Add plot.”
At first, configuring a plot only gives three options for customization: a title, a width, and a height. Enter these desired values and click “Save” to be brought back to the energy monitor. A collapsed plot with the name specified should be listed in the plots section. Click on the name of the plot to enter the configuration menu.
There are a lot of options here, and it is easy to make a mistake. Most of the basic features of the graph do not need to be explicitly set, but the actual data sources and line information for each data input need to be set. To do this:
Under “Add data line,” give the data source a title.
Choose a data source, such as temperature.
Choose a color to plot with.
Choose a line type. I usually choose “lines and markers.” (Some options may make the graphs load slowly or not at all.)
Choose a data line type. I usually choose “Solid.”
For marker type, I usually choose “Filled circle.”
Line size is set to 1, marker size set to 1.
Base axis is X1,Y1 for the initial plot.
If all of this was followed, your data input will look like the screenshot to the right. Once the data line input options are complete, save them, then click “Back to Energy Monitor.” If all of the data was entered correctly, after some time, a new graph will appear.
Feel free to experiment with colors and presentations. This is only a demo, and of course all of the settings can be customized for each use case. For references, I will display the graphs that I have set up for temperature and humidity plotting, as well as their graph settings. Click through each image to expand in another window.
Hopefully this helps to show some of the plotting and meter features of the Web Power Switch 7. There is a lot of configuration that can be done to all of the different visual data displays, and the outputs can be easily tailored to your needs.
API Access Examples:
To get the current status of all outlets:
curl -X GET "http://<ip_address>/restapi/relay/state.xml" -H "Authorization: Basic <base64_encoded_username_password>"
Replace <ip_address>
with the IP address of the Web Power Switch Pro device and <base64_encoded_username_password>
with your base64-encoded username and password separated by a colon (e.g., user:password
).
To turn on Outlet #1:
curl -X GET "http://<ip_address>/restapi/relay/outlet?1=ON" -H "Authorization: Basic <base64_encoded_username_password>"
Replace <ip_address>
and <base64_encoded_username_password>
as described above.
To turn off Outlet #2:
curl -X GET "http://<ip_address>/restapi/relay/outlet?2=OFF" -H "Authorization: Basic <base64_encoded_username_password>"
Replace <ip_address>
and <base64_encoded_username_password>
as described above.
To read the current temperature from a temperature sensor connected to the Web Power Switch Pro:
curl -X GET "http://<ip_address>/restapi/environment/temperature.xml" -H "Authorization: Basic <base64_encoded_username_password>"
Replace <ip_address>
and <base64_encoded_username_password>
as described above.
Note that these are just a few examples of the many API endpoints available for the Web Power Switch Pro. The full API documentation can be found on the Digital Loggers website.