Raspberry pi weather notification and Facebook messenger bot

Eimantas Jazonis · August 28, 2019

Raspberry pi based project that gets upcoming day weather information from OpenWeather API and sends it directly to users as a facebook message every morning.

Why can’t you just check the app on your phone?

Because I am THAT lazy. Ok, to be fair - it’s not the laziness that brought me to this project. In this day of age, when you get the overwhelming amount of information offered to you, usually we start to “shut it down” and ignore it. How many times you checked the weather app and forgot minutes later to take your umbrella? Or how many times you clearly saw, that it will be a warm day on your phone, but you still went to work wearing winter jacket. I know I can’t be the only one! However - I spend quite a lot of time in Facebook Messenger. In Lithuania, contrary to middle-west side of Europe who mostly uses WhatsApp, Facebook Messenger is the main source of communication. I agree it’s not the best, nor the most privacy-secure platform, however, when you can find ~80% of younger population there - it’s hard not to use it. As I send messages to multiple friends, groups and chats during the day, I tend to remember and value information that I get from it. And that’s where this project comes into play. Instead of me going to the app to check the weather I decided to get the weather information literally thrown at me on my most used app.

Few words about the implementation

Full structure of the application is shown in the image below.

Every morning cron job starts a application at 6:30 am. It fetches the weather information from the OpenWeather API, formats nice message with emojis and sends it as Facebook Messenger message. To send it directly to the user (me) a fake account was created (official Facebook API only allows the response bots, which means you have to message it first). To send formatted message fbchat library was used. This is a cool library that connects to your account with headless browser, can fetch all your chats and send messages to every individual or a group. The application was hosted on Raspberry pi 4 device, which is on all the time.

Application in action

An example message is shown here:

Final thoughts

Overall - I am happy with the results. There are a lot of things and implementation improvements that can be done, but for now I am keeping this as it is. My future goal is to connect this application to the larger microservice architecture on Raspberry pi, but that’s for later. Thank you for reading, until the next time!

Full project code can be found here

Twitter, Facebook