Skip to content
BotServBotServ
Home AssistantLocal AISmart HomeVoice AssistantAutomation

Home Assistant with Local AI

Use Home Assistant with local AI. Voice assistant, automations, smart control, all on-premises.

S

schutzgeist

5 min read
Home Assistant with Local AI

Home Assistant with Local AI

What this article covers

  • Connecting Home Assistant to local AI (Ollama).
  • How a local voice assistant works.
  • Building intelligent automations with AI.
  • Practical examples for lighting, climate, security, and energy.
  • Best practices for privacy and performance.

Introduction: Home Assistant with AI explained

Home Assistant controls your smart home. Add local AI and it becomes intelligent: “Make it cozy” becomes “Turn on lights, set temperature to 22°, play music”. The AI understands context and makes decisions, all locally, no cloud required.

This article is for Home Assistant users looking to integrate AI. For background, check out Smart Home Automation and Ollama.

Why do you need Home Assistant with AI?

Standard automation: “If temperature exceeds 25°, turn on AC”. With AI: “It’s warm and I have guests coming over, cool things down and ventilate the space”. The AI grasps context, not just thresholds.

Home Assistant with AI in a nutshell

Ollama works as a conversation agent in Home Assistant. Assist (the voice assistant) uses Ollama for understanding, Whisper for speech recognition, and Piper for speech synthesis. AI in automations enables smarter decision-making.

The core idea: local AI as your smart home’s brain.

Who this article is for

  • Home Assistant users who want to add AI to their setup.
  • Privacy-conscious users who don’t want cloud-based voice assistants.
  • Smart home enthusiasts building intelligent automations.
  • Self-hosters who prefer everything running locally.

Key terminology

  • Home Assistant - Smart home platform. Use when: you need a central hub.
  • Assist - HA’s voice assistant. Use when: you want voice control.
  • Ollama - Local model server. Use when: you need the AI backend.
  • Whisper - Speech-to-text. Use when: accepting voice input.
  • Piper - Text-to-speech. Use when: generating voice output.
  • Node-RED - Complex workflows. Use when: building advanced logic.

Setup

1. Ollama in Home Assistant

# configuration.yaml
ollama:
  url: http://ollama:11434

Or via the UI: Settings → Devices & Services → Add Integration → Ollama → URL: http://ollama:11434

2. Configure Assist

# Assist uses Ollama as the conversation agent
conversation:
  intents:
    # Custom intents here

In the UI:

  1. Settings → Voice Assistants → Assist
  2. Conversation Agent: Ollama
  3. STT: Whisper (local)
  4. TTS: Piper (local)

3. Docker stack

version: "3.8"

services:
  homeassistant:
    image: homeassistant/home-assistant:latest
    ports:
      - "8123:8123"
    volumes:
      - ha_config:/config

  ollama:
    image: ollama/ollama:latest
    ports:
      - "11434:11434"
    volumes:
      - ollama_data:/root/.ollama

  whisper:
    image: rhasspy/wyoming-whisper:latest
    ports:
      - "10300:10300"
    command: --model small --language de

  piper:
    image: rhasspy/wyoming-piper:latest
    ports:
      - "10200:10200"
    command: --voice de_DE-thorsten-high

volumes:
  ha_config:
  ollama_data:

Practical example 1: Natural language commands

automation:
  - alias: "AI light control"
    trigger:
      - platform: conversation
        command:
          - "Turn the light [in the] {room} [on|off]"
    action:
      - service: light.toggle
        target:
          area_id: "{{ trigger.slots.room }}"

Practical example 2: Intelligent climate control

automation:
  - alias: "AI climate"
    trigger:
      - platform: time_pattern
        minutes: "/15"
    action:
      - service: ollama.generate
        data:
          prompt: |
            Data:
            - Outside temperature: {{ states('sensor.aussentemperatur') }}°C
            - Inside temperature: {{ states('sensor.innentemperatur') }}°C
            - Occupancy: {{ states('person.max') }}
            - Time: {{ now().strftime('%H:%M') }}

            What should the heating/cooling system do?
            Reply with: heat, cool, off, or ventilate + brief reason
        response_variable: ki_decision
      - choose:
          - conditions: "{{ 'heat' in ki_decision.text }}"
            sequence:
              - service: climate.set_hvac_mode
                data:
                  hvac_mode: heat

Practical example 3: Morning briefing

automation:
  - alias: "AI morning briefing"
    trigger:
      - platform: time
        at: "07:30:00"
    action:
      - service: ollama.generate
        data:
          prompt: |
            Create a morning briefing:
            - Weather: {{ states('weather.home') }}
            - Temperature: {{ states('sensor.aussentemperatur') }}°C
            - Calendar: {{ states('calendar.personal') }}
            - Electricity rate: {{ states('sensor.strompreis') }} cents/kWh

            Keep it brief and friendly, 3 sentences.
        response_variable: briefing
      - service: notify.notify
        data:
          title: "Morning briefing"
          message: "{{ briefing.text }}"

Practical example 4: Security analysis

automation:
  - alias: "AI security"
    trigger:
      - platform: state
        entity_id: binary_sensor.bewegung
        to: "on"
    condition:
      - condition: time
        after: "23:00"
        before: "06:00"
    action:
      - service: ollama.generate
        data:
          prompt: |
            Motion detected at night:
            - Sensor: {{ trigger.entity_id }}
            - Time: {{ now().strftime('%H:%M') }}
            - People home: {{ states('group.personen') }}

            Is this suspicious? Reply with: normal or suspicious + reason
        response_variable: analyse
      - choose:
          - conditions: "{{ 'suspicious' in analyse.text }}"
            sequence:
              - service: notify.notify
                data:
                  title: "Security alert"
                  message: "{{ analyse.text }}"

Security considerations

  • Everything local: Whisper, Ollama, Piper, no cloud needed.
  • Validation: Verify AI decisions for critical actions (unlocking doors). See Human approval.
  • Fallback: If AI fails, critical automations should continue running in HA.
  • Logging: Record AI decisions. See Logging.

Common pitfalls

  • Model too slow: Large models (over 13B parameters) are slow for real-time use. Use llama3.1:8b instead.
  • Whisper model choice: small is good for most use cases. large is more accurate but slower.
  • German voice: For Piper, use de_DE-thorsten-high for good quality.
  • Context overflow: Too many entities in your prompt overload the model. Filter for what’s relevant.
  • AI misinterprets: “Turn on light” might affect multiple entities. Write precise prompts.

Further reading

Key takeaways:

  • Home Assistant plus Ollama gives you a fully local voice assistant.
  • Whisper for speech-to-text, Ollama for understanding, Piper for speech synthesis.
  • Use AI in automations for intelligent decision-making.
  • Everything stays local, no cloud, no data leaves your network.
  • Small models (8B) for real-time use, larger ones for analysis.

FAQ

How do I connect Ollama to Home Assistant?

Use the Ollama integration: Settings → Devices & Services → Add Integration → Ollama → enter URL. Or add it to configuration.yaml.

Can I run the voice assistant completely locally?

Yes. Whisper for speech-to-text, Ollama for understanding, Piper for speech synthesis. Everything runs locally, no cloud required.

Which Ollama model is best for a smart home?

llama3.1:8b or phi3:mini for fast voice commands. For complex analysis, use a larger model.

How fast is the voice control?

Whisper small: 1-2 seconds. Ollama 8B: 2-5 seconds. Total: 3-7 seconds from speech to action. Use smaller models for faster responses.

Does my data stay private?

Completely. Whisper, Ollama, and Piper run locally. Your voice data never leaves your network.

What hardware do I need?

For Whisper small plus llama3.1:8b: about 10 GB VRAM. An RTX 3060 with 12GB is sufficient. CPU-only works but is slower.

What if the AI misunderstands a command?

AI can misinterpret commands. For critical actions (unlocking doors), require confirmation before execution.

Home Assistant with Ollama or Alexa?

HA with Ollama for privacy and control. Alexa for ease and music streaming. HA is more complex but fully local.

Sources and further reading

Back to Blog
Share:

Related Posts