Hi
I thought I’d share a rule I’ve just created to turn the 83 addressable SPI LEDs I have around a mirror into a 12 hour clock.
Showing 10:25 in this picture.
The pixels start at the top, go around the mirror clockwise (Which wasn’t intentional, just the way I happened to make it, but it made programming this rule much easier).
The clock starts and stops by monitoring a virtual switch in OH2 named “Lounge_Clock”
The set of variables at the top of the rule set up the colour choices for the Hour and Minute and pixel allocations.
Pixel allocation for 12 hours (24 pixels) Hconfig
Pixel allocations for 60 minutes (59 pixels) Mconfig
val dmxActions = getActions("dmx","dmx:artnet-bridge:68ba04f1")
var Hcolour = "10,10,255"
var Mcolour = "255,25,25"
var Hconfig = "16/6,37/6,58/6,79/6,100/6,121/6,139/6,160/6,181/6,205/6,226/6,247/3,1/3"
var Mconfig = "4/12,22/15,43/15,64/15,85/15,106/15,127/12,145/15,166/15,187/18,211/15,232/15"
rule "Clock switch OFF"
when
Item Lounge_Clock changed to OFF
then
say("Lounge Clock turned off", "marytts:cmuslthsmm", "webaudio")
dmxActions.sendFade("1:1/249","500:0,0,0:-1", false)
end
rule "Clock switch turned ON"
when
Item Lounge_Clock changed to ON or Time cron "0 0/1 * * * ?" // every minute
then
val Number currentHourST = String::format( "%1$tI", new java.util.Date ) // as 12 hour clock hour
// val Nunber currentHourST = String::format( "%1$tH", new java.util.Date ) // as 24 hour clock hour
val Number currentMinuteST = String::format( "%1$tM", new java.util.Date ) // as 2 digit minute
var currentHour = Float::parseFloat(String::format("%s",currentHourST))
var currentMinute = Float::parseFloat(String::format("%s",currentMinuteST))
// say("Current Time is "+currentHour+" hours and "+currentMinute+" Minutes", "marytts:cmuslthsmm", "webaudio")
// logInfo("Test Time", "Test: current Hour = [{}]",currentHour)
// logInfo("Test Time", "Test: current Minute = [{}]",currentMinute)
if (Lounge_Clock.state == ON) {
// val String currentTime = String::format( "%1$tH:%1$tM", new java.util.Date )
// say("Current Time is "+currentTime, "marytts:cmuslthsmm", "webaudio")
var h = 0
var DMXcommandH = ""
while ((h=h+1) < currentHour ) {
DMXcommandH = DMXcommandH + "0,0,0,0,0,0,"
}
DMXcommandH = DMXcommandH + Hcolour + "," + Hcolour
while ((h=h+1) < 13 ) {
DMXcommandH = DMXcommandH + ",0,0,0,0,0,0"
}
// logInfo("Lounge Clock debug", "Clock Hour command = [{}]",DMXcommandH)
var m = 0
var DMXcommandM = ""
while ((m=m+1) < currentMinute) {
DMXcommandM = DMXcommandM + "0,0,0,"
}
DMXcommandM = DMXcommandM + Mcolour
while ((m=m+1) <61){
DMXcommandM = DMXcommandM + ",0,0,0"
}
// logInfo("Lounge Clock debug", "Clock Minute command = [{}]",DMXcommandM)
// dmxActions.sendFade("1:1/249","10000:128,0,0:-1", false)
// dmxActions.sendFade("1:16/6,37/6,58/6,79/6,100/6,121/6,139/6,160/6,181/6,205/6,226/6,247/3,1/3","2000:"+DMXcommandH+":-1", false) // Hour
// dmxActions.sendFade("1:4/12,22/15,43/15,64/15,85/15,106/15,127/12,145/15,166/15,187/18,211/15,232/15","2000:"+DMXcommandM+":-1", false) // Minute
dmxActions.sendFade("1:"+Hconfig,"2000:"+DMXcommandH+":-1", false) // Hour
dmxActions.sendFade("1:"+Mconfig,"2000:"+DMXcommandM+":-1", false) // Minute
}
end