My adventures with openhab and LSC Smart Connect lightbulb:
Install openhab3
----------------
sudo apt-get install openjdk
wget -qO - 'https://openhab.jfrog.io/artifactory/api/gpg/key/public' | sudo apt-key add -
sudo apt-get install apt-transport-https
echo 'deb https://openhab.jfrog.io/artifactory/openhab-linuxpkg stable main' | sudo tee /etc/apt/sources.list.d/openhab.list
sudo apt-get update && sudo apt-get install openhab
sudo apt-get install openhab-addons
Navigate with a web browser to http://<ip-address>:8080
Install mosquitto
-----------------
sudo opt-get install mosquitto
sudo systemctl mosquitto restart
Install node/npm
----------------
sudo apt-get install nodejs
sudo apt-get install npm
Install tuya-mqtt
-----------------
cd /opt
sudo git clone https://github.com/TheAgentK/tuya-mqtt
sudo cd tuya-mqtt
sudo npm install
sudo cp config.json.sample config.json
nano devices.conf (see next step)
example:
[
{
name: 'LSC-A60-RGB-CCT 1',
id: 'bfa4875da7d3c05f459aof',
key: '7cdbc8a0c742715b',
version: '3.3'
}
]
Install modfied lsc app
-----------------------
Sideload https://mega.nz/file/2V8UlDwC#9f0_M6Af_tMHgXR8lionNA6ScFM82EZUae4YLBiUzy4
Login, select a device, press menu, Device info, get device id and localkey
Add to devices.conf
Install MQQT Binding
--------------------
Open openhab
Add thing, install binding MQQT Binding
Add a MQQT Broker, set ip to 127.0.0.1 (mosquitto)
Run tuya-mqtt in debug
----------------------
cd /opt/tuya-mqtt
DEBUG=tuya-mqtt:* node tuya-mqtt.js
You can now use the app and see the commands + payload
LSC-A60-RGB-CCT
---------------
Add a Generic MQQT Thing eg. LSC-A60-RGB-CCT 1, select MQQT Broker as bridge.
Add folowing channels:
• On/Off (switch)
State: tuya/lsc-a60-rgb-cct_1/dps/20/state
Command: tuya/lsc-a60-rgb-cct_1/dps/20/command
On value: true
Off value: false
• Brightness (number)
State: tuya/lsc-a60-rgb-cct_1/dps/22/state
Command: tuya/lsc-a60-rgb-cct_1/dps/22/command
Min value: 10
Max value: 1000
• Whiteness (number)
State: tuya/lsc-a60-rgb-cct_1/dps/23/state
Command: tuya/lsc-a60-rgb-cct_1/dps/23/command
Min value: 10
Max value: 1000
• Color (string)
First copy RGBToColorString.js and ColorStringToRGB.js to /etc/openhab/transform
colorStringToRGB.js:
(function(i) {
var re = /.*([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{4}).*/i;
var r = i.match(re);
if (r === null||r.length===0)
return i;
var one = Number('0x' + r[1]);
var two = Number('0x' + r[2]) / 10;
var three = Number('0x' + r[3]) / 10;
return one+','+two+','+three;
})(input);
RGBToColorString.js:
function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
(function(i) {
var r = i.split(',');
if (r === null||r.length!==3)
return i;
var one = Number(r[0]) ;
var two = Number(r[1]) * 10;
var three = Number(r[2]) * 10;
return pad(one.toString(16), 4) + pad(two.toString(16), 4) + pad(three.toString(16), 4);
})(input);
State: tuya/lsc-a60-rgb-cct_1/dps/24/state
Command: tuya/lsc-a60-rgb-cct_1/dps/24/command
Transformation Out: JS:RGBToColorString.js
Transformation In: JS:colorStringToRGB.js
• Mode (switch)
Command: tuya/lsc-a60-rgb-cct_1/dps/21/command
State: tuya/lsc-a60-rgb-cct_1/dps/21/state
Off value: colour
On value: white
Has another value: scene
• Scene (string)
State: tuya/lsc-a60-rgb-cct_1/dps/25/state
Command: tuya/lsc-a60-rgb-cct_1/dps/25/command
Install tuya-mqtt as service
----------------------------
cd /lib/systemd/system/
sudo touch tuyaapi-mqtt.service
echo [Unit] | sudo tee -a tuyaapi-mqtt.service
echo Description=tuyaapi-mqtt | sudo tee -a tuyaapi-mqtt.service
echo After=network-online.target | sudo tee -a tuyaapi-mqtt.service
echo Wants=network-online.target | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo [Service] | sudo tee -a tuyaapi-mqtt.service
echo ExecStart=/usr/bin/node /opt/tuya-mqtt/tuya-mqtt.js | sudo tee -a tuyaapi-mqtt.service
echo Restart=always | sudo tee -a tuyaapi-mqtt.service
echo User=openhab | sudo tee -a tuyaapi-mqtt.service
echo Group=openhab | sudo tee -a tuyaapi-mqtt.service
echo Environment=PATH=/usr/bin/ | sudo tee -a tuyaapi-mqtt.service
echo Environment=NODE_ENV=production | sudo tee -a tuyaapi-mqtt.service
echo WorkingDirectory=/opt/tuya-mqtt | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo [Install] | sudo tee -a tuyaapi-mqtt.service
echo WantedBy=multi-user.target | sudo tee -a tuyaapi-mqtt.service
echo Alias=tuyaapi-mqtt.service | sudo tee -a tuyaapi-mqtt.service
sudo chmod 644 /lib/systemd/system/tuyaapi-mqtt.service
sudo systemctl daemon-reload
sudo systemctl enable tuyaapi-mqtt.service
sudo systemctl start tuyaapi-mqtt.service