Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Raspberry Pi Docker for controlling WS281x LEDs via MQTT

License

Notifications You must be signed in to change notification settings

pilotak/docker-rpi-ws281x-mqtt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Control WS281x connected on Raspberry Pi via MQTT

Docker Build Docker Pulls Docker Size

This image is ready to be used in HomeAssistant - supports MQTT discovery, for all other purposes, please see topics used below.

For supported GPIOs please see rpi-ws281x-python

Environmental variables

Variable Default value Allowed values
LED_GPIO required
LED_COUNT required
LED_CHANNEL optional 0
LED_FREQ_HZ optional 800000 400000 or 800000
LED_DMA_NUM optional 10 0-14
LED_BRIGHTNESS optional 255 1-255
LED_INVERT optional 0 0 or 1
LED_STRIP_TYPE optional GRB BGR, BRG, GBR, GRB, RBG, RGB
MQTT_BROKER optional 'localhost'
MQTT_USER optional None
MQTT_PASSWORD optional None
MQTT_PORT optional 1883 1-65535
MQTT_QOS optional 1 0-2
MQTT_ID optional 'rpi-ws281x'
MQTT_PREFIX optional 'rpi-ws281x'
MQTT_DISCOVERY_PREFIX optional 'homeassistant'

docker-compose.yml

version: "3.6"
services:
  mosquitto:
    container_name: mosquitto
    restart: always
    image: eclipse-mosquitto
    ports:
      - 1883:1883

  rpi_ws281x:
    container_name: rpi_ws281x
    restart: unless-stopped
    image: pilotak/rpi-ws281x-mqtt
    privileged: true
    depends_on:
      - mosquitto
    environment:
      - LED_GPIO=18
      - LED_COUNT=167
      - MQTT_BROKER=mosquitto
      - MQTT_USER=user
      - MQTT_PASSWORD=123456

MQTT topics

To set color

Send to topic: rpi-ws281x/command

Note: color and effect are optional keys, you can send both or just one or none in which case last color selected is used.

{
    "state": "ON",
    "color": {
        "r": 0,
        "g": 255,
        "b": 0
    },
    "effect": "Knight Rider"
}

To turn off

Send to topic: rpi-ws281x/command

{
    "state": "OFF"
}

Last state

Topic: rpi-ws281x/state

{
    "state": "ON",
    "color": {
        "r": 255,
        "g": 109,
        "b": 109
    },
    "effect": "None"
}

Availability

Topic: rpi-ws281x/alive

Response: 1 or 0