Getting hold of Raspberry PIs on the cheap with Huginn.

Getting hold of Raspberry PIs on the cheap with Huginn.
... two ravens named Huginn and Muninn sit on Odin's shoulders. The ravens tell Odin everything they see and hear. Odin sends Huginn and Muninn out at dawn, and the birds fly all over the world before returning at dinner-time. As a result, Odin is kept informed of many events. Source: Wikipedia. Banner from the application Huginn.

I love home automation, but I hate what IFTTT have done with the free account. Yes, you could get multiple, but that is a mess. I get that they need to make money, but still, I wanted an alternative. Perferably self-hosted, so this can't be taken away from me. Also, at the time I writing, getting hold of raspberry pis is hard. Not impossible.

That's when I came across Huginn ( https://github.com/huginn/huginn ). The platform uses a series of agents to achieve certain tasks and that's what I'm going to look at. There are plenty of guides on how to install Huginn, so I'm not going to cover that. For reference, I am using a docker container to host my particular instance.

To get hold of a raspberry pi, I needed a reliable way of knowing when they were in stock. I am certainly not going to pay scalper prices. With a bit of google fu, I came across RPI Locator ( https://rpilocator.com/ ). The website also has a feed, and you can narrow down your search to your target country and / or device.

So, the first thing I need to do is take a look at https://rpilocator.com/feed/. This is the direct RSS feed, which is ripe for parsing via Huginn. Looking at the raw xml, we can see lots of item sections, which hold the data we want.

XML data for an in stock raspberry PI zero W in the US.

Each of these items are sub items from RSS and Channel. The elements within item that we are interested in are the title and the url. Each part of which we want to extract via Huginn, format in a message and send via telegram to a recipient. Using XPATH syntax, the areas of interest are /rss/channel/item/title and /rss/channel/item/url. Armed with this information, we are ready to write the initial scraper.

The first stage is to create a new agent. In the dialog box, start typing XML and the website agent appears, as shown below.

Once selected, you can start filling out the form, as per below (don't worry about the Recievers and scenarios, you can add those later). Also, nb, the screen is not complete. The text on the right handside does cover the options in more detail for a greater understanding of what is going on.

Once completed and saved, the form should look like this:

Initial scraper called RPI Locator source Details

If you perform a dry run, you may see events created. If there are a lot and they aren't relevent to you, go back to rpilocator to make sure your feed is narrowed down properly and working.

Once you have this all working, the next stage is to format the events for the message. Huginn has an agent for this, called the "event formatting agent". This follows a similar format to adding the website agent, just with different supporting text. For the output to telegram, the message instruction needs to be set. The text instruction is used for other things, so I've set at two.

As the text wraps, the full options becomes

{ "instructions": { "message": "{{title | regex_replace: '<title>','' | regex_replace '<\/title>',''}} {{url | regex_replace: '<link>','' | regex_replace '<\/link>',''}}", "text": "{{title | regex_replace: '<title>','' | regex_replace '<\/title>',''}} {{url | regex_replace: '<link>','' | regex_replace '<\/link>',''}}" }, "matchers": [ ], "mode": "clean" }

Great, again we can test that the events flow through. Don't forget to set the source to be the RPI Locator source you already set up. Finally, we need to send the events to telegram. This is quite straight forward, although you will want to set up a bot specifically for this. I have run in to issues sharing bots between systems. The botfather on telegram is who you want to speak to. There are lots of guides on this, so I'm not going to cover it.

Once you have your telegram details, the last agent is the "Telegram Agent". This does the actual sending. Once set up, it should look something like below.

Again, make sure you have your formatter as the source for this agent. Now, if everything is working, you should get events sent through to telegram. Now, just sit back and wait for the RPIs to become available....

As an Amazon Associate I earn from qualifying purchases.

If you have found this post useful, please consider donating.