We have moved at community.getvera.com

Author Topic: Direct Twitter messages from Luup scene - alternative notifications  (Read 5686 times)

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
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

Offline wseverino

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 854
  • Karma: +0/-0
  • Da Man, Da Myth, Da Legend - in his own mind!
Nice!!!!
My ZWave Network: Too friggin big to list.....

Offline veezer

  • Sr. Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Re: Direct Twitter messages from Luup scene - alternative notifications
« Reply #2 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

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Direct Twitter messages from Luup scene - alternative notifications
« Reply #3 on: September 29, 2010, 05:42:58 pm »
Great! Until they move to OAuth too :)

Offline veezer

  • Sr. Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Re: Direct Twitter messages from Luup scene - alternative notifications
« Reply #4 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

Offline m0jon

  • Full Member
  • ***
  • Posts: 113
  • Karma: +0/-0
  • @m0jon
Re: Direct Twitter messages from Luup scene - alternative notifications
« Reply #5 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