The Vera Community forums have moved!

General => General => Topic started by: 325xi on May 20, 2010, 11:31:06 pm

Title: Direct Twitter messages from Luup scene - alternative notifications
Post by: 325xi on May 20, 2010, 11:31:06 pm
For those who want to send notification from Luup scenes, this is a fairly simple example of how to send yourself a direct Twitter message. The main advantage - it's simple, fast; and you can have it delivered as email or SMS.

Twitter shouldn't be used for anything mission critical as sometimes you may hit the fail whale. However most of the time it works much better then native Vera notifications... at least at this stage. I set it to send me twits every 20 min 24/7 to test it, and it have never missed... running for two days so far.

The Luup scene code below isn't polished, but it works. Fill the first three variables with your values; the last few lines is the example of logic sending a twit - modify it as you need. As you can guess you need extra user for your Vera.

Code: [Select]
local function twit(msg)
local user = 'your-vera-user'
local pwd = 'your-vera-user-password'
local recipient = 'your-user'

local update = os.date(msg .. ": %x %X!")

local cmd = 'curl -u '..user..':'..pwd..' -k -d \"'.. 'user='.. recipient .. '&text='.. update ..'\" https://twitter.com/direct_messages/new.xml'
local rc = os.execute(cmd)
if (rc ~= 0) then
luup.log('ERROR: os.execute returned '..rc)
return false
end
end

local lul_temp=luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",84)
if( lul_temp=="1" ) then
   twit("Garage door is open")
end
Title: Re: Direct Twitter messages from Luup scene - alternative notifications
Post by: wseverino on May 21, 2010, 08:27:46 am
Nice!!!!
Title: Re: Direct Twitter messages from Luup scene - alternative notifications
Post by: veezer on September 29, 2010, 12:11:18 pm
This is great!!!  It's so much more flexible than the built-in email/sms notifiations from vera.  Unfortunately, I just got it working, and then Twitter just turned off basic http/https/authentication, so it's not working anymore. I got kind of fed up of Twitter anyway, and their service slowdowns and interruptions, so I migrated everything over to http://identi.ca which is an open-source micro-blogging service, with the same twitter api.  To boot, it's also much faster to send me email notifications.  The only change you need to do is change the authentication url above to:

http://identi.ca/api/direct_messages/new.xml
Title: Re: Direct Twitter messages from Luup scene - alternative notifications
Post by: 325xi on September 29, 2010, 05:42:58 pm
Great! Until they move to OAuth too :)
Title: Re: Direct Twitter messages from Luup scene - alternative notifications
Post by: veezer on September 30, 2010, 07:55:31 am
Then we'll just have to bite the bullet and write some lua Oauth libraries  ;D

Actually, I'd probably just download the source of identi.ca then and host it locally.

I doubt it though; twitter's use of OAuth seems a little broken, so I hope no one else does something like this.  Lots of hyperbole in this article, but it does bring up some good points about the annoyances of the current OAuth security in twitter, especially for writers of client apps:
http://arstechnica.com/security/guides/2010/09/twitter-a-case-study-on-how-to-do-oauth-wrong.ars (http://arstechnica.com/security/guides/2010/09/twitter-a-case-study-on-how-to-do-oauth-wrong.ars)
Title: Re: Direct Twitter messages from Luup scene - alternative notifications
Post by: m0jon on September 30, 2010, 08:53:17 am
Hi 325xi
I'm new to coding and just wondered if you could explain the last few lines of your code
and where i should look to add my own references to a sensor that i use.

Ive attempted to add the details which i think are correct and have included them below

local lul_temp=luup.variable_get("urn:micasaverde-com:serviceId:Hallway_Sensor","Tripped",84)
if( lul_temp=="18" ) then
   twit("Its Getting Cold")

the red text is what i think i still need to change
many thanks in advance
m0jon