Get the last reading from Xsensior Lite using the command line

If you wish to get hold of the latest reading from a Xsensior Lite sensor, either directly yourself or from a script. The quickest and simplest way is to read the data yourself from the database used by Xsensior Lite.

Firstly, you will need to download the SqlLite3 command line tools. Sqlite is a small SQL database, perfect for use as an embedded database. Xsensior Lite uses Sqlite to store all configuration data as well as all sensor data.

When you've installed the Sqlite command line tools, open a Windows Command Prompt and execute the following command:

sqlite3.exe "C:\ProgramData\Openxtra\XSensior Lite\XSensiorLite.sqlite" "select Value from Reading order by Timestamp desc limit 1;"

The first argument is the full path to the Xsensior Lite database file. The path is likely the same on your system. You can check by entering "C:\ProgramData\Openxtra\XSensior Lite\" in your Explorer navigation bar. You should see the XSensiorLite.sqlite database file there as well as a bunch of log files. The second argument is a SQL query to retrieve the most recent reading stored inside the database.

The program will print out the latest reading.

If your system has more than one sensor, or has one or more combined temperature / humidity sensors, you will see more than one number printed out. All sensors on a system have their readings in the Reading table.

In order to print out the information you want, you need to find out the identifier for the sensor you are interesteed in.

select ProbeID,Name from Probe;

This will print the probe identifier and name of all probes / sensors in the database. Note down the identifer of the sensor you are interested in. You will need to substitute it in the next query.

select Value from Reading order by Timestamp desc limit 1 where ProbeID=<place your id here>;

To put everything together, if your probe id is 1, then the query would look like this:

select Value from Reading order by Timestamp desc limit 1 where ProbeID=1;

For a complete example using the above query, your command line would look like this:

sqlite3.exe "C:\ProgramData\Openxtra\XSensior Lite\XSensiorLite.sqlite" "select Value from Reading order by Timestamp desc limit 1 where ProbeID=1;"

Hope that helps. Many thanks to customer Joao Patrao @ GoldenGest in Angola for sending us the tip.

Categories: Xsensior Lite