【脱IFTTT】Raspberry Pi 5とn8nで構築する「鉄分特化型」自動ニュース発信基盤 /[Beyond IFTTT] Building a Rail-Specific Auto-Posting Infrastructure with Raspberry Pi 5 & n8n

【脱IFTTT】Raspberry Pi 5とn8nで構築する「鉄分特化型」自動ニュース発信基盤 

GalaVision(がーらけにあ)です。 

「自動化ツールの定番だったIFTTTの制限が厳しくて、思うように動かせない……」 

そんな悩みを抱えていませんか? 

「便利だけど、これ以上月額課金は増やしたくない」というのが本音。そこで私は、最新の Raspberry Pi 5 と、自由度の高いiPaaS 「n8n」 を組み合わせ、特定のSNSや有料サービスに依存しない、自分専用の「自動情報発信スタンド」を構築しました。 

今回は、101社の鉄道プレスリリースをさばく「フィルタリングの極意」と「AI活用のコツ」をシェアします。 

 

1. なぜ「n8n」なのか?(コストと自由度の両立) 

長年愛用してきたIFTTTですが、無料プランの制限が年々厳しくなっています。一方、n8nは自前のサーバー(Raspberry Pi 5)でセルフホストが可能。 

  • 無制限の実行: 自作サーバーなので、実行回数やノード数を気にせず「使い放題」。 

  • 高度なロジック: JavaScriptでの条件分岐や、最新AI(Gemini)との連携も自由自在。 

  • 低コスト: 最初にラズパイを買ってしまえば、運用コストは電気代とAPI利用料(従量課金)のみ。 

 

2. 「鉄分」を抽出せよ!AIとJSによる2段構えの検問 

鉄道会社のプレスリリースには、車両の新型導入だけでなく、駅ビルのテナント情報やマンション分譲といった「不動産ニュース」も多く含まれます。 

「鉄道ファンが読みたい情報」だけを届けるため、以下の2段階フィルタリングを実装しました。 

第1段階:JavaScriptによる「高速仕分け」 

まずは特定のキーワードで機械的に振り分けます。 

  • 採用: 車両, ダイヤ, 駅, 新型, 試運転, 決算 

  • 除外: マンション, ビル, 分譲, ホテル 

JavaScript 

// 実装ロジックのイメージ 
const railKeywords = ["車両""ダイヤ""駅""新型""試運転""決算"]; 
const realEstateKeywords = ["マンション""ビル""分譲"]; 
 
const isRail = railKeywords.some(k => line.includes(k)); 
const isNotRealEstate = !realEstateKeywords.some(k => line.includes(k)); 
 
return isRail && isNotRealEstate ? line : "SKIP"; 
 

第2段階:Geminiによる「文脈判断」 

キーワードだけでは判断が難しいものは、AI(Gemini 2.0 Flash)に「鉄道専門記者」としての役割を与えて最終判定させます。ニュース性がない場合は、無理に記事を作らず「SKIP」と答えさせるのがブログの質を保つコツです。 

 

3. 読ませる工夫:AIに「インパクトのあるタイトル」を 

毎日「◯月◯日のニュースまとめ」というタイトルでは、誰もクリックしてくれません。そこで、AIに記事全体を象徴するキャッチーなタイトルを生成させ、Bloggerの投稿タイトルに反映させています。 

【プロンプトの工夫】 

「回答の1行目には、ニュース全体を象徴するインパクトのあるタイトルを【 】で囲んで出力してください。2行目以降に本文をHTML形式で出力してください。」 


これにより、「【激変】新型車両がついに試運転開始!」といった、思わず読みたくなるタイトルが自動で生成されます。 

 

4. 構築環境と「嘘をつかないAI」の作り方 

今回の心臓部は、Raspberry Pi 5 (8GB) です。 

  • OS: Ubuntu Server / Docker / Portainer 

  • ハルシネーション対策: AIが「もっともらしい嘘」をつくのを防ぐため、n8nで取得した「プレスリリースの原文」をコンテキストとして直接AIに読み込ませる(RAG的手法)を採用しています。 

また、深夜のテストで「SKIP」が連発される現象に遭遇しましたが、これは正解。企業のプレスリリースは9時〜15時に集中するため、自動実行スケジュールをその時間帯に合わせることで、鮮度の高い情報を効率よくキャッチできるようになりました。 

 

結びに代えて:技術で手に入れる「自由なダイヤ」 

「お金をかけずに、どこまで高機能なシステムを作れるか」。 

n8nとラズパイの組み合わせは、まさに個人開発者の武器です。 

今後は、このラズパイに「家計簿サーバー」を共存させたり、Tailscaleを使って外部から安全に管理画面へアクセスしたりと、生活全般の自動化を計画中。 

「金がかかるなら、技術で解決する」。 

このワクワクする「ダイヤ改正」の様子は、引き続きレポートしていきます! 

 

技術スタック 

  • iPaaS: n8n (Self-hosted) 

  • AI: Gemini 2.0 Flash (via OpenRouter / 低コスト運用) 

  • Infrastructure: Raspberry Pi 5 8GB / Docker 

 

調整後のポイント 

  • 「本音」の反映: 冒頭と最後に、コスト意識と技術的工夫を強調する表現を追加しました。 

  • 構成の整理: 鉄道ニュースのフィルタリング(前半)と、システム構成(後半)をスムーズに繋げ、一つのストーリーにしました。 

  • 技術的魅力: JavaScriptのコードブロックや、n8nでの正規表現など、読者が「真似したくなる」要素を残しています。 

Geminiは会話型とAPIじゃ雲泥の差がある上、今回はGeminiさんと話し合いながら構築した形になりますね。 

※OSインストール後から構築までGeminiさんとの会話でこぎつけた。

 

[Beyond IFTTT] Building a Rail-Specific Auto-Posting Infrastructure with Raspberry Pi 5 & n8n 

Have you been struggling with the increasing limitations of automation tools like IFTTT? 

Let’s be honest: they’re convenient, but nobody wants another monthly subscription. That’s why I combined the latest Raspberry Pi 5 with the highly flexible iPaas "n8n" to build my own "Automatic News Stand"—completely independent of specific SNS platforms or paid services. 

In this post, I’ll share my "filtering secrets" and "AI tips" for managing press releases from 101 different railway companies. 

 

1. Why n8n? (Balancing Cost & Freedom) 

I loved IFTTT for years, but their free tier limits have become too restrictive. On the other hand, n8n can be self-hosted on your own server (like a Raspberry Pi 5). 

  • Unlimited Execution: Since it's a self-hosted server, you can run as many nodes and workflows as you want without worrying about usage limits. 

  • Advanced Logic: From complex conditional branching with JavaScript to seamless integration with the latest AI (Gemini), the sky's the limit. 

  • Low Cost: After the initial investment in the Pi, your only ongoing costs are electricity and pay-as-you-go API fees. 

 

2. Extracting the "Rail Essence": A Two-Tiered Filtering System 

Railway press releases aren't just about new trains; they often include "Real Estate" news like mall openings or apartment sales. To ensure only "high-iron" content reaches the fans, I implemented a two-stage gatekeeper. 

Stage 1: High-Speed Sorting with JavaScript 

First, we filter mechanically using specific keywords. 

  • Include: Trains, Schedules, Stations, New Models, Test Runs, Financial Results. 

  • Exclude: Apartments, Buildings, Real Estate Sales, Hotels. 

JavaScript 

// Implementation Logic Image 
const railKeywords = ["車両""ダイヤ""駅""新型""試運転""決算"]; 
const realEstateKeywords = ["マンション""ビル""分譲"]; 
 
const isRail = railKeywords.some(k => line.includes(k)); 
const isNotRealEstate = !realEstateKeywords.some(k => line.includes(k)); 
 
return isRail && isNotRealEstate ? line : "SKIP"; 
 

Stage 2: Contextual Judgment by Gemini 

For news that is hard to judge by keywords alone, I give Gemini 2.0 Flash the persona of a "Professional Railway Journalist" to make the final call. The trick to maintaining blog quality is to have it return "SKIP" if there’s no real news value. 

 

3. Engagement: Generating "Impactful Titles" with AI 

A title like "News Summary for April 22" won't get any clicks. To fix this, I have the AI generate a catchy title that represents the core of the story. 

[Prompt Engineering Tip] 

"In the first line of your response, output an impactful title that symbolizes the news inside brackets like 【 】. From the second line onwards, output the body in HTML format." 

On the n8n side, I use a Regular Expression to extract only the content inside the brackets: 

{$json.combinedContent.match(/【(.*?)】/)?.[1] || "Today's Railway News Summary" }} 

This results in automated, click-worthy titles like "【Game Changer】 New Rolling Stock Finally Begins Test Runs!" 

 

4. Build Environment & Preventing "AI Hallucinations" 

The heart of this setup is the Raspberry Pi 5 (8GB). 

  • OS: Ubuntu Server / Docker / Portainer 

  • Anti-Hallucination Measures: To prevent the AI from making up "plausible lies," I use a RAG-style approach where n8n feeds the actual text of the press release directly into the AI's context as the "source of truth." 

During testing, I noticed the system kept returning "SKIP" late at night. I realized this wasn't an error—it was working perfectly. Press releases are usually published between 9:00 AM and 3:00 PM, so I optimized the execution schedule to catch the freshest info. 

 

Closing Thoughts: Technical Freedom on Your Own Schedule 

"How high-spec can I make a system without breaking the bank?" 

The combination of n8n and Raspberry Pi is a powerful weapon for any indie developer. 

Next, I’m planning to co-host a "Household Accounting Server" on this same Pi and use Tailscale for secure remote access. 

"If it costs too much, solve it with tech." 

I’ll keep reporting on this exciting "System Schedule Revision" here on the Moricora Diary! 

 

Tech Stack 

  • iPaaS: n8n (Self-hosted) 

  • AI: Gemini 2.0 Flash (via OpenRouter / Low-cost operation) 

  • Infrastructure: Raspberry Pi 5 8GB / Docker 

 

Note: This entire system, from OS installation to final workflow, was built through a collaborative dialogue with Gemini. There is a world of difference between the consumer chat version and the API implementation—it's been a true co-creation process! 

 

コメント

このブログの人気の投稿

東日本旅客鉄道E8系新幹線、相次ぐ補助電源装置故障の深層 — 製造メーカー三菱電機の関与と今後の展望/East Japan Railway E8 Shinkansen, the depths of a series of auxiliary power supply failures — Involvement of manufacturer Mitsubishi Electric and future prospects

令和の発車メロディーについての公式発表/JR East Official announcement about the departure melody of Reiwa

名鉄の存廃問題と廃線の決まった路線(2025年2月時点)/Meitetsu's survival issues and the routes that were decided to be discontinued (as of February 2025)