# Node-RED Automation Platform

> Low-code automation with Node-RED, MQTT broker, InfluxDB storage, and Grafana dashboards.

- Category: Home Lab & Self-Hosting
- Difficulty: intermediate
- Components: node-red, mosquitto, influxdb, grafana
- Tags: node-red, automation, low-code, mqtt, iot
- Source: https://docker.recipes/homelab/node-red-automation

## Overview

Node-RED is a visual programming tool developed by IBM that enables users to wire together hardware devices, APIs, and online services through a browser-based flow editor. Built on Node.js, it uses a drag-and-drop interface where users connect nodes to create automation flows, making it particularly valuable for IoT applications, home automation, and industrial monitoring without requiring extensive coding knowledge. This automation platform combines Node-RED with Mosquitto MQTT broker for lightweight messaging, InfluxDB for time-series data storage, and Grafana for creating rich visualization dashboards. The stack creates a complete data pipeline where sensors and devices publish data via MQTT, Node-RED processes and routes this information to InfluxDB for storage, while Grafana provides real-time monitoring and historical analysis through customizable dashboards. This combination is ideal for makers, system integrators, and organizations looking to implement comprehensive IoT automation solutions. The visual programming approach of Node-RED makes complex automation accessible to users with varying technical backgrounds, while the time-series capabilities of InfluxDB and visualization power of Grafana provide enterprise-grade monitoring and analytics capabilities typically found in much more expensive commercial solutions.

## Features

- Visual flow-based programming with 300+ pre-built nodes for common automation tasks
- MQTT broker with WebSocket support for real-time IoT device communication
- InfluxDB 2.7 with Flux query language for advanced time-series data analysis
- Grafana dashboard templating with variables for dynamic multi-device monitoring
- Node-RED palette manager for installing community-contributed automation nodes
- Mosquitto persistence and retained message support for reliable IoT messaging
- InfluxDB data retention policies for automatic old data cleanup
- Grafana alerting with multiple notification channels including Slack and email

## Use cases

- Home automation systems collecting sensor data and controlling smart devices
- Industrial IoT monitoring for equipment performance and predictive maintenance
- Weather station data collection with automated alerts for extreme conditions
- Energy monitoring systems tracking solar panel output and consumption patterns
- Greenhouse automation with temperature, humidity, and irrigation control
- Network monitoring solutions collecting SNMP data and system metrics
- Building management systems for HVAC control and occupancy tracking

## Prerequisites

- Docker Engine 20.10+ and Docker Compose V2 for container orchestration
- Minimum 2GB RAM (1GB for InfluxDB, 512MB for Grafana, remainder for Node-RED and Mosquitto)
- Available ports 1880 (Node-RED), 1883/9001 (MQTT), 3000 (Grafana), and 8086 (InfluxDB)
- Basic understanding of MQTT publish/subscribe messaging patterns
- Familiarity with time-series data concepts for effective InfluxDB usage
- Knowledge of JSON data structures for Node-RED flow configuration

## docker-compose.yml

```yaml
services:
  nodered:
    image: nodered/node-red:latest
    environment:
      TZ: ${TZ}
    ports:
      - "1880:1880"
    volumes:
      - nodered_data:/data
    depends_on:
      - mosquitto
    networks:
      - automation-net
    restart: unless-stopped

  mosquitto:
    image: eclipse-mosquitto:latest
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - mosquitto_data:/mosquitto/data
    networks:
      - automation-net
    restart: unless-stopped

  influxdb:
    image: influxdb:2.7
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUX_USER}
      DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUX_PASSWORD}
      DOCKER_INFLUXDB_INIT_ORG: ${INFLUX_ORG}
      DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUX_BUCKET}
    ports:
      - "8086:8086"
    volumes:
      - influxdb_data:/var/lib/influxdb2
    networks:
      - automation-net
    restart: unless-stopped

  grafana:
    image: grafana/grafana:latest
    environment:
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
    ports:
      - "3000:3000"
    volumes:
      - grafana_data:/var/lib/grafana
    depends_on:
      - influxdb
    networks:
      - automation-net
    restart: unless-stopped

volumes:
  nodered_data:
  mosquitto_data:
  influxdb_data:
  grafana_data:

networks:
  automation-net:
    driver: bridge
```

## .env

```bash
# Timezone
TZ=UTC

# InfluxDB
INFLUX_USER=admin
INFLUX_PASSWORD=secure_influx_password
INFLUX_ORG=automation
INFLUX_BUCKET=nodered

# Grafana
GRAFANA_PASSWORD=secure_grafana_password
```

## Usage notes

- Node-RED editor at http://localhost:1880
- Install additional nodes from palette manager
- Use MQTT nodes for IoT integration
- Visualize data in Grafana

## Troubleshooting

- Node-RED flows not connecting to Mosquitto: Verify MQTT broker configuration node uses 'mosquitto' as hostname, not localhost
- InfluxDB authentication errors: Check DOCKER_INFLUXDB_INIT_* environment variables match values used in Node-RED InfluxDB output nodes
- Grafana showing 'No data points' for InfluxDB queries: Ensure InfluxDB data source uses Flux language and correct bucket name from environment variables
- MQTT clients cannot connect: Create mosquitto.conf file with 'listener 1883' and 'allow_anonymous true' for basic setup
- Node-RED palette installation fails: Container needs internet access and sufficient disk space in nodered_data volume
- Grafana dashboards not persisting: Verify grafana_data volume is properly mounted and container has write permissions

