Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| plugins:sql_logger [2014/02/26 15:17] – mattb | plugins:sql_logger [2025/04/14 20:10] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== SQL Logger Plugin ====== | ||
| + | |||
| + | The SQL Logger Plugin for Indigo automatically logs device state changes, variable value changes, and event log entries to either [[http:// | ||
| + | |||
| + | This allows Indigo to integrate with other applications or services, and allows for historical data recording. You can, for example, use PHP to dynamically generate graphs or charts of device states (like temperature) stored in a PostgreSQL database. | ||
| + | |||
| + | By default, OS X 10.5 and higher includes the libraries needed to use SQLite, which makes using the SQLite option fast. | ||
| + | |||
| + | Although more complicated, | ||
| + | |||
| + | ==== Configuring SQL Logger with SQLite ==== | ||
| + | |||
| + | Choose the **'' | ||
| + | |||
| + | By default, Indigo will create a SQLite database file inside the logs folder: | ||
| + | |||
| + | < | ||
| + | |||
| + | ==== Configuring SQL Logger with PostgreSQL ==== | ||
| + | |||
| + | PostgreSQL is not included with the macOS X install (note it is included on more recent OS X Server installs), but it is free and there are some package installers available. Here are the basic steps for installing it: | ||
| + | |||
| + | * Download a [[https:// | ||
| + | * Add the path to the PostgreSQL binary to your bash profile file. From the Terminal copy/paste: | ||
| + | < | ||
| + | * Next, open the System Preferences and choose the PostgreSQL Server icon that was added. You should now be able to start the server. Note the some installers seem to included a Server Manage.app application, | ||
| + | * From the command line you can now try to connect to the server via: | ||
| + | < | ||
| + | * Next, select the **'' | ||
| + | |||
| + | By default, Indigo will connect to the PostgreSQL server running on the same Mac (**'' | ||
| + | ==== Logging Options | ||
| + | |||
| + | From the SQL Logging configuration dialog (**'' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Automatically pruning data from the tables will help keep the database size more manageable, but you can turn the option off if you want to manually clean up the database. | ||
| + | |||
| + | Auto deleting unused tables will have the plugin remove any tables for devices or variables that are not defined in the current Indigo database. However, note that this means that if you switch Indigo database files then the device and variable history stored for the previous database will automatically be deleted from the SQLite/ | ||
| + | |||
| + | ==== Database Table Format ==== | ||
| + | |||
| + | Indigo creates a unique table for every device and variable to track its state/value history. Example database table names include: | ||
| + | |||
| + | < | ||
| + | and | ||
| + | < | ||
| + | |||
| + | To find the specific device or variable IDs used in the table name, right-click on the device (or variable) inside Indigo and choose the **'' | ||
| + | |||
| + | Columns are automatically created for the tables for every state used by that particular device. For example, here is the device history table for a dimmer switch, **'' | ||
| + | |||
| + | ^ ts ^ brightnesslevel | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 18: | ||
| + | | 2012-05-16 19: | ||
| + | | 2012-05-16 19: | ||
| + | | 2012-05-16 19: | ||
| + | |||
| + | And here is the table created for a temperature humidity sensor, **'' | ||
| + | |||
| + | ^ ts ^ temperature | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 18: | ||
| + | | 2012-05-16 19: | ||
| + | | 2012-05-16 19: | ||
| + | | 2012-05-16 19: | ||
| + | |||
| + | Using SQL you can query the table for all the defined columns. | ||
| + | |||
| + | Variable tables are similarly created -- one table per variable. However, they always have the same columns: **'' | ||
| + | |||
| + | ^ ts ^ value ^ | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | | 2012-05-16 16: | ||
| + | |||
| + | Lastly, a single table is created to track all event log entries, **'' | ||
| + | |||
| + | ==== Example Queries ==== | ||
| + | |||
| + | Below are some example SQLite and PostgreSQL queries. Note that the table names below are examples, and must be modified to match your unique table names. | ||
| + | |||
| + | === PostgreSQL Queries === | ||
| + | |||
| + | PostgreSQL query to retrieve all event log history: | ||
| + | < | ||
| + | PostgreSQL query to retrieve all device history for a specific device: | ||
| + | < | ||
| + | PostgreSQL query to retrieve the timestamp, rain rate and rain total from an Oregon Scientific rain sensor: | ||
| + | < | ||
| + | |||
| + | === SQLite Queries === | ||
| + | |||
| + | For SQLite queries, first change to the directory in which the database file resides: | ||
| + | < | ||
| + | |||
| + | SQLite query to retrieve all event log history: | ||
| + | < | ||
| + | SQLite query to retrieve all device history for a specific device: | ||
| + | < | ||
| + | SQLite query to retrieve the timestamp, temperature, | ||
| + | < | ||
| + | |||
| + | Note that when selecting the timestamp from a SQLite table you must use the notation **'' | ||
| + | |||
| + | ===== Events ===== | ||
| + | |||
| + | The SQL Logger provides a useful event (even if it's not logging anything): **'' | ||
| + | |||
| + | **'' | ||
| + | |||
| + | To use the **'' | ||
| + | |||
| + | < | ||
| + | Aug 9, 2012 3:38:10 AM | ||
| + | My Type Error this is an error from a script | ||
| + | NOAA Weather Plus Error Error parsing XML from NOAA for device Weather Forecast: not well-formed (invalid token): line 1, column 111 | ||
| + | </ | ||
| + | |||
| + | In the configuration dialog for **'' | ||
| + | |||
| + | This is primarily useful for plugin errors although if you have scripts that generate errors it could be used for those as well. For plugins (unless the developer decides otherwise), errors will be generated using the plugin' | ||
| + | |||
| + | ===== Scripting Support ===== | ||
| + | |||
| + | Here's the plugin ID in case you need to programmatically restart the plugin: | ||
| + | |||
| + | **Plugin ID**: com.perceptiveautomation.indigoplugin.sql-logger | ||
| + | |||
| + | ===== Support and Troubleshooting ===== | ||
| + | |||
| + | For usage or troubleshooting tips [[https:// | ||
| + | |||