From f79195e9a575fc97bd2c892ae9f8b707254d4641 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 23 Jan 2021 10:05:18 +0100 Subject: [PATCH] Status of first row color added to MQTT --- Readme.md | 3 +++ mqtt.lua | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index e06bd90..4bce2b1 100644 --- a/Readme.md +++ b/Readme.md @@ -41,6 +41,7 @@ Optinal: ### Status * **basetopic**/brightness **Current brightness in percent** * **basetopic**/background **Current background color** +* **basetopic**/row1 **Current background color** ### Commands * **basetopic**/cmd/single @@ -51,6 +52,8 @@ Optinal: * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** * **basetopic**/cmd/telnet * ignored **Stop MQTT server and start telnetserver at port 23** +* **basetopic**/cmd/row1 + * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** ## OpenHAB2 Tested MQTT with binding-mqtt 2.5.x diff --git a/mqtt.lua b/mqtt.lua index 32b6ae4..ad82d94 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -37,7 +37,10 @@ function handleSingleCommand(client, topic, data) end -function parseBgColor(data) +-- Parse MQTT data and extract color +-- @param data MQTT information +-- @param row string of the row e.g. "row1" used to publish current state +function parseBgColor(data, row) local red=nil local green=nil local blue=nil @@ -49,6 +52,7 @@ function parseBgColor(data) red, green, blue = string.match(data, "(%d+),(%d+),(%d+)") end if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then + m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0) return string.char(green * briPercent / 100, red * briPercent / 100, blue * briPercent / 100) else return nil @@ -77,7 +81,7 @@ function registerMqtt() mydofile("telnet") startTelnetServer() elseif (string.match(topic, "row1$")) then - row1bgColor = parseBgColor(data) + row1bgColor = parseBgColor(data, "row1") end end end