Home automation : Event2Gcal or how to receive free SMS alerts from vera

Event2Gcal or how to receive free SMS alerts from vera

Posted By: pmietlicki

Published to Home automation on Jul 01, 2012

LUA script for vera

Event2Gcal 1.1 beta 5

I noticed that, in France, it was not possible to use the vera feature to send text messages to our phones when an event or an alert occured with the domotic box : vera lite.

So I thought about a very simple solution : why not create event on our google calendar ? Thus we could be able to receive alerts from google and for free because google calendar can send you text message for any events inside your calendar. The only thing to do was creating a plugin to write events on our google calendar from the vera lite.

This plugin will give you the possibility to send text message from your scenarios with some luup code.

A text message is more interesting than a push notification for several reasons :

  • Battery usage : push works with an internet connection et that consumes much more battery
  • Mobile plan : not every provider will give you internet connection on your smartphone
  • Network coverage : Internet connection is not everywhere
  • Worldwide : a text message could be much cheaper and reliable

The goal is to create an event on your google calendar with the parameters you want (event name, description : for example "Presence" : "detected intrusion!", "flooding", ..) and then configure your google calendar to automatically send text messages.

Google calendar configuration

The plugin connects to your google calendar with a username / password. It does not use the OAuth fetature of google. I advise you to create a new email adress different from your main google calendar for security reasons. It is to prevent the case when someone ("not invited") would access your vera (with the Web interface for example). You'll have to provide to the plugin, the email adress and the password of your google account. Warning, avoid special characters for the password, I did not try it but a user told me it was not working.

On your new google account, go to the calendar page and change the settings inside "mobile configuration". Give the country, the phone number and confirm everything by sending a validation code to your mobile phone.

Click on « Save » and your mobile is now ready to receive text messages from your google agenda.

Inside your calendar

You should see the calendars that are linked to your google account. Click on "notifications" inside the one that will receive the events from your vera. You can create a new dedicated calendar that you can call "Home automation" for example. Warning, the calendar name is very important, the plugin will need it.

Inside the "notifications" part, you can indicate to send a reminder by SMS. Be sure to send it "0 minutes" before every event (to be warned as soon as possible, since the creation of the event).

Plugin installation

Automatic ?

You could (should?) be able to install it directly from this URL :

http://apps.mios.com/plugin.php?id=2078

Then connect with your login / password of your micasaverde account (the one that you use to see the logs of your vera), to select the vera you want and click "install" :

Manual

Please download the zip file : Event2Gcal

Decompress it, you should see 4 files : D_Event2GCal.json, D_Event2GCal.xml, I_Event2GCal.xml et S_Event2GCal.xml

- Inside your vera, go to «APPS» then « Develop Apps » then « Luup files ».

Go to the section "Send files" and select the 4 files you've decompressed.

In "manual mode", you'l have to create a virtual device (this is not a difficult task, you'll see). Just click on "create device" then indicates the name of the 2 main files (entry points of the plugin) : D_Event2GCal.xml, I_Event2GCal.xml

You'll obtain a new device callend "Envoi de SMS" or whatever the name you indicated.

Plugin settings

You'll have to indicate several parameters, you can modify them on demand by code (thus you won't have to create a new plugin for each calendar...).
To enter the settings, click on the "monkey wrench" at the right top corner of the device.

Then go to « Advanced », you'll see several settings available (Email, Password, CalendarName, EventName, EventDesc) :

Plugin usage

Static (1 device per event)

Disclaimer : this requires you to create a new module for each event!

It's your choice, or you directly indicate the desired fields in the "Control" or "Advanced". This may be interesting if you want to be alerted that a single event such as with EventName to "Intrusion" and EventDesc to "intrusion Alert! Call the police (17) ".

If you use the « Control » part, don't forget to click on « Set ».

You close it and then click on « Save » (that appears in the top right corner).

You'll now have the possibility to use this new virtual plugin in your scenarios by clicking on the « On » action of the virtual device :

It will create the event on your calendar and if correctly set, receive a text alert (SMS) with the name of the event and the description previously indicated.

By programming (1 to rule them all)

That's the best method because you can use the same virtual device for every events. You'll use Luup code directly inside your scenario :

luup.call_action("urn:event2gcal:serviceId:Event2GCal1", "SetEventName", {NewEventName= "Intrusion"}, device_id 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1", "SetEventDesc", {NewEventDesc= "Intrusion ! Call the police!"},device_id) 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1", "SetEmail", {NewEmail= "email@gmail.com" },device_id) 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1", "SetPassword", {NewPassword= "yourpassword"},device_id) 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1", "SetCalendarName", {NewCalendarName= "email@gmail.com_ou_autre_nom"},device_id) 
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue= 1},device_id) 

Where device_id is the device number of your virtual device (visible in the "Advanced" part of the device) :

In our example, this id is 112

Some tools

If you want to have the precise moment of the event, you can use this code :

local now = os.date("*t") 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1", "SetEventDesc", {NewEventDesc= "The alarm was disabled at "..tostring(now.hour).." heures "..tostring(now.min).." minutes "..tostring(now.sec).." secondes"},device_id 

To facilitate usage, I added some functions in my scenario called setEvent and addEvent. You'll have to add it inside « Edit Startup Lua » :

Here's the code :

function setEvent(name, desc, devid) 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1","SetEventName", {NewEventName=name}, devid) 
luup.call_action("urn:event2gcal:serviceId:Event2GCal1","SetEventDesc", {NewEventDesc=desc}, devid) 
end 
function addEvent(dev_id) 
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget", {newTargetValue= 1},dev_id) 
end 

I've also set Email and Password directly in the « Advanced » part of the plugin so it simplifies the code :

setEvent("Intrusion", "intrusion alert, etc", 112) addEvent(112)

In this case, you can just add a new virtual device for each google calendar account and thus you won't have to indicate the email address and password each time in your scenarios.


Tags: Domotique, Vera

Archive