Skip to content

Instantly share code, notes, and snippets.

@mwvent
Last active October 17, 2021 18:32
Show Gist options
  • Save mwvent/511606ccacc6e815e3d39bacb5be1858 to your computer and use it in GitHub Desktop.
Save mwvent/511606ccacc6e815e3d39bacb5be1858 to your computer and use it in GitHub Desktop.
Tasmota Rules For Sonoff Mini Piggybacking a cheapie floodlight
A small IR LED Is connected directley to S1/S2 on the mini using the minis internal resistor
it is low power but the led is glued direct to the floodlight and works fine in my use case.
Rules allow changing the LED colour with Event commands - also handles setting the color on startup
as by default the lights do not 'remember' what they were last set to
Also included is an example Nodered function that takes input from https://googlehome.hardill.me.uk/ and translates colour to light given that the input node has the first part of the lights topic set.
codes = {
0xFF0000 : { "Event": "RED1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF720DF","DataLSB":"0xEF04FB","Repeat":0} },
0x00FF00 : { "Event": "GRN1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF7A05F","DataLSB":"0xEF05FA","Repeat":0} },
0x0000FF : { "Event": "BLU1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF7609F","DataLSB":"0xEF06F9","Repeat":0} },
0xFFFFFF : { "Event": "WHT", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF7E01F","DataLSB":"0xEF07F8","Repeat":0} },
0xBFFF00 : { "Event": "GRN1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF7A05F","DataLSB":"0xEF05FA","Repeat":0} },
0xFF9100 : { "Event": "ORG1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF708F7","DataLSB":"0xEF10EF","Repeat":0} },
0xAD670A : { "Event": "ORG2", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF730CF","DataLSB":"0xEF0CF3","Repeat":0} },
0x88EBE4 : { "Event": "CYA1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF7B04F","DataLSB":"0xEF0DF2","Repeat":0} },
0x50C4DE : { "Event": "CYA2", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF78877","DataLSB":"0xEF11EE","Repeat":0} },
0x7600C4 : { "Event": "PUR1", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF750AF","DataLSB":"0xEF0AF5","Repeat":0} },
0xA000C4 : { "Event": "PUR2", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF748B7","DataLSB":"0xEF12ED","Repeat":0} },
0xF7DA48 : { "Event": "YEL", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF728D7","DataLSB":"0xEF14EB","Repeat":0} },
0x486EF7 : { "Event": "BLU2", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF7A857","DataLSB":"0xEF15EA","Repeat":0} },
0xFF00FF : { "Event": "PNK", "IRSend": {"Protocol":"NEC","Bits":32,"Data":"0xF76897","DataLSB":"0xEF16E9","Repeat":0} },
};
if(msg.payload.command == "action.devices.commands.OnOff") {
msg.topic = msg.topic + "/cmnd/power1";
if(msg.payload.params.on) {
msg.payload = "1";
} else {
msg.payload = "0";
}
return msg
}
if(msg.payload.command == "action.devices.commands.ColorAbsolute") {
if("temperature" in msg.payload.params.color) {
tmp = msg.payload.params.color.temperature;
if(tmp > 4000) {
rgb = 0xFFFFFF; // WHT
} else if(tmp > 2000) {
rgb = 0xF7DA48; // YEL
} else if(tmp > 1000) {
rgb = 0xFF9100; // org1
} else {
rgb = 0xAD670A; // org2
}
msg.payload.params.color.spectrumRGB = rgb;
}
colourWants = msg.payload.params.color.spectrumRGB;
wR = (colourWants & 0xFF0000) >> 16;
wG = (colourWants & 0x00FF00) >> 8;
wB = (colourWants & 0x0000FF);
// OR color.temperature
lowestScore = 99999999;
selectedCode = codes[0xFFFFFF];
for(const code in codes) {
cR = (code & 0xFF0000) >> 16;
cG = (code & 0x00FF00) >> 8;
cB = (code & 0x0000FF);
dR = Math.abs(wR - cR);
dG = Math.abs(wG - cG);
dB = Math.abs(wB - cB);
score = dR + dG + dB;
if(score < lowestScore) {
lowestScore = score;
selectedCode = code;
}
}
msg2 = {};
msg2.topic = msg.topic + "/cmnd/rule1";
msg.topic = msg.topic + "/cmnd/event";
msg.payload = codes[selectedCode].Event;
cd = codes[selectedCode].Event;
newRule = "ON Event#LastCol DO " +
"Event " + cd + " ENDON";
msg2.payload = newRule;
return [[msg, msg2]];
}
return msg;
RULE1 ON Event#LastCol DO Event WHT ENDON
RULE2
ON Power1#Boot DO backlog delay 5; Event LastCol; delay 1; Event LastCol; delay 1; Event LastCol; ENDON
ON Power1#state=0 DO Event SOFF ENDON
ON Power1#state=1 DO backlog delay 5; Event SON; Event LastCol ENDON
ON Event#LGTN DO backlog1 Event WHT; Event WHT; Event SOFF; Event SON; Event SOFF; Event SON; Event SOFF; Event SON; Event SOFF; Event SON; Event RED1; Delay 40; Event LastCol ENDON
ON Event#LGTN2 DO backlog1 event son; event WHT; event FADE; event soff; event soff; event son; event WHT; event FADE; event soff; event soff; event son; Event RED1; Delay 40; Event LastCol ENDON
ON Event#BRIU DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF700FF"} ENDON
ON Event#BRID DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7807F"} ENDON
ON Event#FLSH DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7D02F"} ENDON
ON Event#STRB DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7F00F"} ENDON
ON Event#FADE DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7C837"} ENDON
ON Event#SMOO DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7E817"} ENDON
RULE3
ON Event#SOFF DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF740BF"} ENDON
ON Event#SON DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7C03F"} ENDON
ON Event#RED1 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF720DF"} ENDON
ON Event#GRN1 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7A05F"} ENDON
ON Event#BLU1 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7609F"} ENDON
ON Event#CYA1 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7B04F"} ENDON
ON Event#CYA2 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF78877"} ENDON
ON Event#ORG1 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF708F7"} ENDON
ON Event#PUR1 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF750AF"} ENDON
ON Event#PNK DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF76897"} ENDON
ON Event#YEL DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF728D7"} ENDON
ON Event#WHT DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7E01F"} ENDON
ON Event#ORG2 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF730CF"} ENDON
ON Event#BLU2 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF7A857"} ENDON
ON Event#PUR2 DO IRSend {"Protocol":"NEC","Bits":32,"Data":"0xF748B7"} ENDON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment