element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Episode 8: Forget Me Not: Using Twitter
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: michaelwylie
  • Date Created: 27 Aug 2014 6:19 AM Date Created
  • Views 1288 views
  • Likes 2 likes
  • Comments 6 comments
  • forget_me_not
  • openhab
  • iot_monitor_auto
Related
Recommended

Episode 8: Forget Me Not: Using Twitter

michaelwylie
michaelwylie
27 Aug 2014

Introduction

Since abandoning the Notify My Android setup, I decided to investigate a few more openHAB items before my first order shows up. I worked with the twitter action, which obviously allows openHAB to tweet for you. I created a second twitter account for my openHAB system so it wouldn't get confusing. I followed the guide at https://github.com/openhab/openhab/wiki/Twitter-Action and modified the instructions to accommodate working with the Pi.

 

Working with the Twitter Action

You’ve got to time this one correctly or it won’t work. Go through all the steps before you start because the entire process cannot take longer than 5 minutes. Upon starting, openHAB will create a URL that is use to bind or authenticate your twitter account to openHAB. This URL process expires in 5 minutes.

 

Step 1 - Modify openhab.cfg

Open openhab.cfg and modify the section for twitter action (don't forget to remove the #'s):

 

########################### Twitter Action configuration ##############################
#
# The ConsumerKey, ConsumerSecret combination (optional, defaults to official Twitter-App
# Key-Secret-Combination)
twitter:key=IPqVDkyMvhblm7pobBMYw
twitter:secret=2HatstDfLbz236WCXyf8lKCk985HdaK5zbXFrcJ2BM

# Flag to enable/disable the Twitter client (optional, defaults to 'false')
twitter:enabled=true

 

I used the key and secret above because otherwise it didn't work. I tried leaving them blank like the wiki suggested but that always resulted in a failed authentication. I found the key and secret in openHAB's Twitter.java:

 

/** the configured ConsumerKey (optional, defaults to the official Twitter-App key 'IPqVDkyMvhblm7pobBMYw') */
private static String consumerKey = "IPqVDkyMvhblm7pobBMYw";
/** the configured ConsumerSecret (optional, defaults to official Twitter-App secret '2HatstDfLbz236WCXyf8lKCk985HdaK5zbXFrcJ2BM') */
private static String consumerSecret = "2HatstDfLbz236WCXyf8lKCk985HdaK5zbXFrcJ2BM";

 

Step 2 - Authenticate openHAB for Twitter

 

Start openHAB:

 

pi@raspberrypi ~/openHAB $ ./start.sh

 

This is where it gets tricky. If you aren't echoing your openHAB messages to the terminal, you will miss this message:

 

21:13:50.197 INFO  o.o.a.t.i.TwitterActionService[:123]- ################################################################################################
21:13:50.213 INFO  o.o.a.t.i.TwitterActionService[:124]- # Twitter-Integration: U S E R   I N T E R A C T I O N   R E Q U I R E D !!
21:13:50.220 INFO  o.o.a.t.i.TwitterActionService[:125]- # 1. Open URL 'https://api.twitter.com/oauth/authorize?oauth_token=5ojKAILHvaxoHVN3bdqqbNfnaTeeAJbK'
21:13:50.252 INFO  o.o.a.t.i.TwitterActionService[:126]- # 2. Grant openHAB access to your Twitter account
21:13:50.256 INFO  o.o.a.t.i.TwitterActionService[:127]- # 3. Create an empty file 'twitter.pin' in your openHAB home directory
21:13:50.264 INFO  o.o.a.t.i.TwitterActionService[:128]- # 4. Add the line 'pin=<authpin>' to the twitter.pin file
21:13:50.275 INFO  o.o.a.t.i.TwitterActionService[:129]- # 5. openHAB will automatically detect the file and complete the authentication process
21:13:50.302 INFO  o.o.a.t.i.TwitterActionService[:130]- # NOTE: You will only have 5 mins before openHAB gives up waiting for the pin!!!
21:13:50.316 INFO  o.o.a.t.i.TwitterActionService[:131]- ################################################################################################

 

Your openHAB startup should PAUSE at this point. It will wait 5 minutes for you to complete the authentication. If it goes beyond this point the timer has stopped and you need to try again.

 

If you are not watching the messages, wait a minute and open the openhab.log file in the logs directory of the openHAB install directory. You should see the banner printed above in the log. Copy the link from your log and load it in a web browser. You will be taken to a twitter/openHAB authentication page where you need to login with your twitter credentials. Once you do that, you will see something like the following:

 

image

 

The blacked out portion will show an authentication number.

 

Step 3 - Set Authentication Pin

 

To set the pin, open a second terminal window, navigate to the openHAB install directory and type the following:

 

pi@raspberrypi ~/openHAB $ nano twitter.pin

 

This will open the nano text editor with a blank screen. Type:

 

auth=<your pin>

 

where <your pin> is the number from the website above. After you've done that, hit CTRL-X and say yes to the saving. Then just hit enter to confirm the file name (twitter.pin). If you've completed everything correctly and in the 5 minute window, twitter will authenticate:

 

21:46:31.492 INFO  o.o.a.t.i.TwitterActionService[:107]- TwitterAction has been successfully authenticated > awaiting your Tweets!

 

I wrote a simple rule to test this:

 

rule "Rocker Pressed"
when
    Item Rocker1A changed from OFF to ON
then
    sendTweet('Rocker 1A ON')
end

 

And, the result was:

 

image

 

Comments:

This sounds easy, but it's hard to get it all done in 5 minutes on the Raspberry Pi because it's relatively slow. How I eventually did it was by streamlining the process.

1. Do the nano twitter.pin part and have a terminal window waiting for you to enter the authentication pin. Don't save the file until after you put in the pin.

2. Have a browser open and waiting to accept a URL. Also, know your account login credentials.

3. Have a second terminal window for starting/stopping openHAB.

4. Have openHAB outputting its information directly to the terminal window.

 

Good Luck!

  • Sign in to reply

Top Comments

  • fvan
    fvan over 11 years ago +1
    Nicely done Seems like one of the more difficult things to configure in openHAB so far! Frederick
  • michaelwylie
    michaelwylie over 11 years ago in reply to fvan +1
    Thanks. Yah, it's crazy to be watching that green graph of the system load down in the lower right corner thinking, "I'm so not gonna make 5 minutes..."
  • michaelwylie
    michaelwylie over 11 years ago in reply to ravi_butani +1
    I was thinking about it, and I was also thinking about embedding the twitter feed in openHAB, but I'm not sure how to do either so far.
  • michaelwylie
    michaelwylie over 11 years ago in reply to ravi_butani

    I was thinking about it, and I was also thinking about embedding the twitter feed in openHAB, but I'm not sure how to do either so far.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ravi_butani
    ravi_butani over 11 years ago

    Is there any way to put image attachment with tweets?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelwylie
    michaelwylie over 11 years ago in reply to fvan

    Thanks. Yah, it's crazy to be watching that green graph of the system load down in the lower right corner thinking, "I'm so not gonna make 5 minutes..."

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 11 years ago

    Nicely done image Seems like one of the more difficult things to configure in openHAB so far!

     

    Frederick

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ravi_butani
    ravi_butani over 11 years ago

    Now I am finding good android app for twitter to show notification tweets on widget with sound...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube