Package: lumimqtt
MQTT agent for Xiaomi Lumi gatewayDescriptionThe service allow controlling gateway LEDs, button, and illuminance
sensor over MQTTDefault config should be located in/etc/lumimqtt.jsonor
can be overridden withLUMIMQTT_CONFIGenvironment variable.InteractionDefault devicesActionTopicPayloadExpected valuesRead light statelumi/<ID>/light{"state": "ON", "brightness": 255, "color": {"r": 255, "g": 0, "b": 0}}Switch lightlumi/<ID>/light/set{"state": "ON"}Set light colorlumi/<ID>/light/set{"color": {"r": 255, "g": 0, "b": 0}}Set brightnesslumi/<ID>/light/set{"brightness": 255}Set color or brigthness with 10 seconds transitionlumi/<ID>/light/set{"color": {"r": 255, "g": 0, "b": 0}, "brightness": 100, "transition": 10}Read illuminancelumi/<ID>/illuminance0-1000Buttonlumi/<ID>/btn0/actionsingle, double, triple, quadruple, many,hold, double_hold, triple_hold, quadruple_hold, many_hold,releaseBinary sensors (soldered to GPIO points)ActionTopicExpected valuesRead GPIO sensorlumi/<ID>/<SENSOR_NAME>ON/OFFRun applicationExample run command:LUMIMQTT_CONFIG=./lumimqtt.jsonpython3-mlumimqttThe configuration file is a JSON with the following content:{"mqtt_host":"localhost","mqtt_port":1883,"mqtt_user":"","mqtt_password":"","topic_root":"lumi/{device_id}","auto_discovery":true,"sensor_retain":false,"sensor_threshold":50,"sensor_debounce_period":60,"light_transition_period":1.0}Every line is optional. By default, LumiMQTT will use the connection
to localhost with the anonymous login.device_idif not providedwill be automatically replaced by a hex number
representing a MAC address of the first network interface.auto_discoveryset tofalseto disable creating autodiscovery topics that
are user by Home Assistant to discover entities.sensor_retainis option to enable storing last sensor value on the brokersensor_thresholdis a threshold to avoid sending data to MQTT on small
changessensor_debounce_periodvalue in seconds to send data despite the thresholdlight_transition_periodvalue in seconds to set default transition for light
switching or light change. Use0to remove the transition.SSL connectionTo use SSL connection, you need to setmqtt_certandmqtt_key, and optionalmqtt_cawith corresponding paths to files.Custom sensorsYou can also use GPIO(s) as binary sensor(s). Add this to configuration:{<yourconfiguration>,"binary_sensors":{"<sensor name>":{"gpio":"<gpio number>","device_class":"<device class>","topic":"<sensor name>"}}}Values in<>must be replaced.gpiois required,device_classandtopicare optional. By defaulttopicis sensor's name.List of GPIOs.List of device classes.Custom commandsYou can add an extra section with custom commands that are executed with
mqtt topics. Every command is exported as a switch entity in Home Assistant.
If json is passed to the set topic, the command will be interpolated with
the values. Plain text is passed as {text} variable{<yourconfiguration>,"custom_commands":{"blink":"for i in 0 255 0 255 0 255 0; do echo $i > /sys/class/leds/{color}/brightness; sleep 1; done","tts":"echo \"Test TTS without MPD component for home assistant\" | python3 -c 'from urllib.parse import quote_plus;from sys import stdin;print(\"wget -O /tmp/tts.mp3 -U Mozilla \\\"http://translate.google.com/translate_tts?q=\"+quote_plus(stdin.read()[:100])+\"&ie=UTF-8&tl=en&total=1&idx=0&client=tw-ob&prev=input&ttsspeed=1\\\" && amixer set Master 200 && mpg123 /tmp/tts.mp3\")' | sh 2> /dev/null","tts_interpolate":"echo \"{text}\" | python3 -c 'from urllib.parse import quote_plus;from sys import stdin;print(\"wget -O /tmp/tts.mp3 -U Mozilla \\\"http://translate.google.com/translate_tts?q=\"+quote_plus(stdin.read()[:100])+\"&ie=UTF-8&tl=en&total=1&idx=0&client=tw-ob&prev=input&ttsspeed=1\\\" && amixer set Master {volume} && mpg123 /tmp/tts.mp3\")' | sh 2> /dev/null","restart_lumimqtt":"/etc/init.d/lumimqtt restart","reboot":"/sbin/reboot"}}Usage examplesActionTopicPayloadRun command "blink"lumi/<ID>/blink/set{"color": "red"}Run command "tts"lumi/<ID>/tts/set<ANYTHING>Run command "tts_interpolate"lumi/<ID>/tts_interpolate/set{"text": "Hi, it is a test", "volume": 200}Run command "restart_lumimqtt"lumi/<ID>/restart_lumimqtt/set<ANYTHING>Run command "reboot"lumi/<ID>/reboot/set<ANYTHING>OpenWrt installationopkgupdateopkginstallpython3-pippython3-asynciopython3-evdev
pip3install-UlumimqttTo upgrade you can just runpip3install-UlumimqttExample run command:lumimqttor (in background):lumimqtt&Autorun:To run lumimqtt on start you need a file/etc/init.d/lumimqttwith the following content:#!/bin/sh /etc/rc.commonSTART=98USE_PROCD=1start_service(){procd_open_instanceprocd_set_paramenvLUMIMQTT_CONFIG=/etc/lumimqtt.jsonprocd_set_paramcommandlumimqttprocd_set_paramrespawnprocd_set_paramstdout1procd_set_paramstderr1procd_close_instance}To install this file on the gateway you can runwgethttps://raw.githubusercontent.com/openlumi/lumimqtt/main/init.d/lumimqtt-O/etc/init.d/lumimqtt
chmod+x/etc/init.d/lumimqtt
/etc/init.d/lumimqttenable/etc/init.d/lumimqttstart