Here’s a little guide to set up event logging using the standard Vera notification process.
Background:
The standard Vera notification process uses emails and/or text messages to notify you of anything that is going on, provided you have added notifications to the devices configured. When a notification needs to be sent, Vera calls a server at micasaverde with a number of parameters, and that server then takes care of the actual medium of sending. Although klunky, it does the job, but emails are “expensive” (lot of overhead for a simple notify) and text messages are unreliable. Not to mention, if you want to keep any kind of history, both methods are not really suitable for storing/parsing.
Vera offers a little known mechanism called ‘Alternate Event Server’. Using this method we are going to be able to receive notifications as they happen and in a format easily accessible to store them into a database.
Pre-requisites:
- Vera.
- Webserver with https listening. This can be apache2, lighttpd, whatever you fancy, but the important bit is that it supports url rewriting and php/mysql. The guide uses apache2.
- MySQL database.
Setup:
I am not going to describe how to install/setup your own webserver as there are many, many guides on the internet covering this already. What is important that in order to continue with the next steps is that you have a webserver that listens on port 443 (https) and is able to serve a page from it.
First we need to create the database and tables which will contain our notification data. Start a connection as root to your database:
[font=courier]$ mysql -uroot -p
Enter password:
mysql>[/font]
Once presented with the prompt, enter the following commands to create the database:
[font=courier]mysql> create database vera;
mysql> create user ‘vera’@‘localhost’ identified by ‘vera’;
mysql> grant all privileges on vera.* to ‘vera’@‘localhost’;
mysql> flush privileges;
mysql> quit;
$[/font]
Download the attached zip file and extract it in the document root for the secure content server. You’ll find 4 files inside:
[font=courier]$ ls -la
-rw-r–r-- 1 quinten quinten 51 Jun 12 13:01 .htaccess
-rw-r–r-- 1 quinten quinten 2089 Jun 12 13:01 alert.php
-rw-r–r-- 1 quinten quinten 352 Jun 12 13:01 alert.sql
-rw-r–r-- 1 quinten quinten 160 Jun 12 13:02 config.php
$[/font]
The [font=courier].htaccess[/font] file redirects the request Vera makes to the [font=courier]alert.php[/font] script. The [font=courier]alert.sql[/font] script contains the database definition and the [font=courier]config.php[/font] contains the configuration variables.
Edit [font=courier]config.php[/font] and set the variables correctly. Pay particular attention to the [font=courier]$vera[/font] variable which needs to point to your Vera’s IP address or name.
Now create the tables:
[font=courier]$ mysql -uvera -pvera vera < alert.sql
$[/font]
Further configuration:
If you’re like me, and do not want to receive an email everytime a notification is sent, you can circumvent this by creating a new user and NOT validate the email address that you’ve given it. Notifications will still work, but no emails will be sent out. Just ignore and delete the validation email that is sent to the notification user.
Just discovered that simply defining a notification without assigning a user will still sent the event to the alternative event server… No need for any users to be created!
Now all we need to do is tell Vera to use our alternate event server by entering the following url inside a browser:
[font=courier]http://<your.vera.ip.address>:3480/data_request?id=variableset&Variable=AltEventServer&Value=<your.webserver.ip.address>[/font]
You will need to reload your Vera (hit the Reload button in the Vera web interface) for it to become effective.