Skip to content
BotServBotServ
OllamaIntegrationn8nNode-REDHome Assistant

Integrate Ollama into Automation

Integrate Ollama into automation workflows. n8n, Node-RED, Home Assistant, Nextcloud, Paperless-ngx guides.

S

schutzgeist

8 min read
Integrate Ollama into Automation

Integrating Ollama into Automation

What This Article Covers

  • How to integrate Ollama into various automation tools.
  • Connecting n8n, Node-RED, Home Assistant, Nextcloud, and Paperless-ngx with Ollama.
  • Practical examples for document processing, smart home, and team collaboration.
  • Best practices for API security, performance, and reliability.
  • Building your own integrations with the Ollama API.

Introduction: Understanding Ollama Integrations

Ollama is a local model server with a REST API. Any software capable of sending HTTP requests can use Ollama. This makes Ollama a universal AI backend for automation tools. Instead of relying on cloud APIs, you connect your tools to Ollama and keep all data locally.

This article is for users who want to integrate Ollama into their existing tools. You should understand how Ollama works and what Function Calling is. Programming basics are available at IRC-Coding.de.

Why Do You Need Ollama Integrations?

Imagine you use n8n for workflow automation, Home Assistant for smart home, and Nextcloud for documents. Each tool is useful on its own. With Ollama as your AI backend, you can connect all tools with local AI: n8n classifies emails, Home Assistant processes voice commands, Nextcloud summarizes documents. Everything stays local, no cloud, no API costs.

Ollama Integrations Explained

Ollama offers a REST API that any client can use. Automation tools like n8n and Node-RED send HTTP requests to Ollama. Smart home systems like Home Assistant use Ollama via add-ons. Document systems like Nextcloud and Paperless-ngx connect Ollama through plugins or scripts.

The core principle is simple: Ollama is the AI backend, and every tool is a client.

Who Should Read This Article?

  • Automation enthusiasts integrating Ollama into existing tools.
  • Self-hosters adding local AI to their infrastructure.
  • Smart home users leveraging AI in Home Assistant.
  • Teams embedding AI into Nextcloud or Paperless-ngx.

Familiarity with Ollama and basic API usage is helpful.

Key Terms

  • Ollama - Local model server. Use when: you need an AI backend.
  • REST API - HTTP interface. Use when: tools need to communicate with Ollama.
  • n8n - Workflow automation. Use when: building complex workflows.
  • Node-RED - Visual flow editor. Use when: you prefer visual workflows.
  • Home Assistant - Smart home platform. Use when: automating your smart home.
  • Nextcloud - Self-hosted cloud. Use when: managing documents.
  • Paperless-ngx - Document management. Use when: classifying documents.
  • Function Calling - Structured AI responses. Use when: enabling tool use.
  • Docker - Container platform. Use when: running tools in isolation.

Ollama API Basics

All integrations rely on the Ollama REST API:

# Chat
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.1",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": false
}'

# Embeddings
curl http://localhost:11434/api/embeddings -d '{
  "model": "nomic-embed-text",
  "prompt": "Text for embedding"
}'

# Function Calling
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.1",
  "messages": [{"role": "user", "content": "What is the weather?"}],
  "tools": [{"type": "function", "function": {"name": "get_weather", "parameters": {"city": {"type": "string"}}}}],
  "stream": false
}'

See Ollama REST API for details.

Integration 1: Ollama with n8n

n8n is a workflow automation tool that can use Ollama via HTTP request nodes.

Setup

  1. Ollama runs on http://localhost:11434.
  2. Add an HTTP request node to your n8n workflow.
  3. Configure it:
    • Method: POST
    • URL: http://localhost:11434/api/chat
    • Body: JSON
    {
      "model": "llama3.1",
      "messages": [{"role": "user", "content": "{{$json.prompt}}"}],
      "stream": false
    }

Practical Example: Email Classification

// In n8n Function node
const email = $input.item.json;
const response = await this.helpers.httpRequest({
  method: 'POST',
  url: 'http://localhost:11434/api/chat',
  body: {
    model: 'llama3.1',
    messages: [
      { role: 'system', content: 'Classify into: support, sales, billing, spam.' },
      { role: 'user', content: `Subject: ${email.subject}\nContent: ${email.body}` }
    ],
    stream: false
  },
  json: true
});
return { category: response.message.content };

See n8n Guide for details.

Integration 2: Ollama with Node-RED

Node-RED is a visual flow editor that can use Ollama via HTTP request nodes.

Setup

  1. Drag an inject node into the flow.
  2. Add a function node:
    msg.payload = {
      model: "llama3.1",
      messages: [{ role: "user", content: msg.payload }],
      stream: false
    };
    msg.headers = { "Content-Type": "application/json" };
    return msg;
  3. Add an http request node:
    • Method: POST
    • URL: http://localhost:11434/api/chat
    • Return: parsed JSON
  4. Connect: inject → function → http request → debug.

See Node-RED for details.

Integration 3: Ollama with Home Assistant

Home Assistant is a smart home platform that can use Ollama via add-ons or RESTful sensors.

Setup with RESTful Sensor

# configuration.yaml
sensor:
  - platform: rest
    name: "AI Response"
    resource: http://localhost:11434/api/chat
    method: POST
    payload: |
      {
        "model": "llama3.1",
        "messages": [{"role": "user", "content": "What is the weather?"}],
        "stream": false
      }
    value_template: "{{ value_json.message.content }}"

Practical Example: Voice Assistant

# Shell command for Ollama
shell_command:
  ollama_chat: >
    curl -s http://localhost:11434/api/chat -d '{"model": "llama3.1", "messages": [{"role": "user", "content": "{{ question }}"}], "stream": false}' | jq -r .message.content

# Automation
automation:
  - alias: "AI Voice Assistant"
    trigger:
      - platform: conversation
        command: "ask ai [question]"
    action:
      - service: shell_command.ollama_chat
        data:
          question: "{{ trigger.question }}"
      - service: notify.mobile_app
        data:
          message: "{{ states('sensor.ai_response') }}"

Integration 4: Ollama with Nextcloud

Nextcloud is a self-hosted cloud platform that can use Ollama via apps or scripts.

Setup with Nextcloud App

Community apps exist to integrate Ollama into Nextcloud. Alternatively, you can use scripts:

// Nextcloud script (external app or occ command)
function callOllama($prompt) {
    $client = \OC::$server->getHTTPClientService()->newClient();
    $response = $client->post('http://localhost:11434/api/chat', [
        'json' => [
            'model' => 'llama3.1',
            'messages' => [['role' => 'user', 'content' => $prompt]],
            'stream' => false
        ]
    ]);
    return json_decode($response->getBody(), true)['message']['content'];
}

Practical Example: Document Summarization

#!/usr/bin/env python3
# Nextcloud script: document summarization
import requests
import sys

def summarize_document(content):
    response = requests.post(
        "http://localhost:11434/api/chat",
        json={
            "model": "llama3.1",
            "messages": [
                {"role": "system", "content": "Summarize the document in 5 sentences."},
                {"role": "user", "content": content[:4000]}
            ],
            "stream": False
        }
    )
    return response.json()["message"]["content"]

if __name__ == "__main__":
    content = sys.stdin.read()
    print(summarize_document(content))

Integration 5: Ollama with Paperless-ngx

Paperless-ngx is a document management system that can leverage Ollama for classification and summarization.

Setup via Custom Script

# paperless-ngx custom script
import requests

def ollama_classify(document_text):
    response = requests.post(
        "http://localhost:11434/api/chat",
        json={
            "model": "llama3.1",
            "messages": [
                {"role": "system", "content": "Classify as: invoice, contract, customer, other."},
                {"role": "user", "content": document_text[:2000]}
            ],
            "stream": False
        }
    )
    return response.json()["message"]["content"].strip().lower()

# In paperless-ngx configuration
# PAPERLESS_CONSUMER_RECURSIVE=true
# PAPERLESS_CONSUMER_SCRIPT=/path/to/ollama_classify.py

Practical Example: Automatic Tag Assignment

def ollama_tags(document_text):
    response = requests.post(
        "http://localhost:11434/api/chat",
        json={
            "model": "llama3.1",
            "messages": [
                {"role": "system", "content": "Assign 3-5 tags for this document. Respond as a JSON array."},
                {"role": "user", "content": document_text[:2000]}
            ],
            "format": "json",
            "stream": False
        }
    )
    return response.json()["message"]["content"]

Building Custom Integrations

If no ready-made plugin exists, you can build custom integrations using the Ollama API:

import requests

class OllamaClient:
    def __init__(self, base_url="http://localhost:11434"):
        self.base_url = base_url

    def chat(self, model, messages, stream=False):
        response = requests.post(
            f"{self.base_url}/api/chat",
            json={"model": model, "messages": messages, "stream": stream}
        )
        return response.json()

    def embeddings(self, model, prompt):
        response = requests.post(
            f"{self.base_url}/api/embeddings",
            json={"model": model, "prompt": prompt}
        )
        return response.json()

    def chat_with_tools(self, model, messages, tools):
        response = requests.post(
            f"{self.base_url}/api/chat",
            json={"model": model, "messages": messages, "tools": tools, "stream": False}
        )
        return response.json()

# Usage
client = OllamaClient()
response = client.chat("llama3.1", [
    {"role": "user", "content": "Hello"}
])
print(response["message"]["content"])

Security Considerations

  • Secure Ollama: Do not expose Ollama to the internet without authentication. See API Keys.
  • Network Isolation: Use Docker networks to restrict Ollama access to local tools only. See Network Isolation.
  • Avoid Sensitive Data in the Cloud: Ollama runs locally, but verify whether connected tools transmit data externally.
  • Audit Logging: Log all Ollama requests. See Audit Logging.
  • Rate Limiting: Ollama lacks built-in rate limits. Protect against resource exhaustion.

Common Pitfalls

  • Ollama unreachable: Verify that Ollama is running and the URL is correct.
  • Wrong model: Check that the model is loaded (ollama list).
  • Context length exceeded: Large documents must be chunked.
  • Missing error handling: Tools should not crash if Ollama becomes unavailable.
  • Forgotten security: Running Ollama without authentication is a risk.

Further Reading

Key Takeaways:

  • Ollama provides a REST API that any tool can use.
  • Integrations: n8n, Node-RED, Home Assistant, Nextcloud, Paperless-ngx.
  • All integrations run locally without cloud dependencies.
  • Security: Secure Ollama, use network isolation, enable audit logging.
  • Build custom integrations using the Ollama API.

FAQ

What tools can I integrate with Ollama?

Any tool that can send HTTP requests. Popular choices include n8n, Node-RED, Home Assistant, Nextcloud, and Paperless-ngx. You can build custom integrations using the Ollama API.

How do I connect tools to Ollama?

Via the Ollama REST API. Tools send POST requests to http://localhost:11434/api/chat with the model, messages, and options. The API returns JSON.

How do I integrate Ollama into n8n?

Use an HTTP Request node. URL: http://localhost:11434/api/chat, Method: POST, Body: JSON with model and messages. See the n8n guide for details.

How do I use Ollama in Home Assistant?

Via RESTful sensors or shell commands. Send HTTP requests to Ollama and use the response in automations.

How do I use Ollama in Nextcloud?

Via community apps or custom scripts. Send HTTP requests to Ollama and use the response for document summarization or classification.

How do I use Ollama in Paperless-ngx?

Via custom scripts. Define a script that uses Ollama for classification or tag assignment. Paperless-ngx runs the script when new documents arrive.

How do I secure Ollama?

Do not expose Ollama to the internet without authentication. Use Docker network isolation, enable audit logging, and implement rate limiting.

How do I build a custom integration?

Use the Ollama REST API. Send POST requests to /api/chat, /api/embeddings, or /api/generate. The API returns JSON that you process in your tool.

Which model should I use?

For classification, llama3.1:8b is sufficient. For summarization, qwen2.5:32b. For embeddings, nomic-embed-text. For function calling, llama3.1 or mistral.

What does it cost to operate?

Only hardware costs. Ollama is open source, and the models are freely available. You need a machine with sufficient VRAM for your chosen model.

Sources and further reading

Back to Blog
Share:

Related Posts