Home Automation

Enter Your Electronics & Design Project for a chance to win a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Overview

This is my last post for the Home Automation Project14 event due to time constraints.  My intention was to implement controlling the GPIO connections from P2 on the MATRIX Creator via openHAB, but that is not quite working at this point, so I am moving to just the Everloop control which I already have configured in openHAB.  This control from openHAB is from the Exec Binding calling python scripts using the matrix-lite-py interfaces.   The Basic UI is used from openHAB to send the commands to the MATRIX Creator.

Previous Posts:

OpenHAB 2 with Matrix Creator and RasPi 3 A+: Intro

OpenHAB 2 with Matrix Creator and RasPi 3 A+: MATRIX Lite Python

OpenHAB 2 with Matrix Creator and RasPi 3 A+: OpenHAB 2 MQTT Binding

OpenHAB 2 with Matrix Creator and RasPi 3 A+: OpenHAB 2 Exec Binding

OpenHAB 2 with Matrix Creator and RasPi 3 A+: GPIO and Postmortem

 

MATRIX Lite Python

Using the example that came with the MATRIX Lite Python interfaces, I have created a couple of methods that can turn on and off the Everloop LEDs as well as control the color and brightness.

 

   Python Script uses a Dictionary to sed specific colors.

ledMatrix = {'red': {'ledr' : 1, 'ledg' : 0 , 'ledb' : 0, 'ledw' : 0},
            'green': {'ledr' : 0, 'ledg' : 1 , 'ledb' : 0, 'ledw' : 0},
            'blue': {'ledr' : 0, 'ledg' : 0 , 'ledb' : 1, 'ledw' : 0},
            'white': {'ledr' : 0, 'ledg' : 0 , 'ledb' : 0, 'ledw' : 1},
            'off': {'ledr' : 0, 'ledg' : 0 , 'ledb' : 0, 'ledw' : 0},
            'on': {'ledr' : 1, 'ledg' : 1 , 'ledb' : 1, 'ledw' : 1}
            }


## LED Example ##


def runEverloop(self, color):


self.everloop = hal.everloop()


color = color.lower()


print ("Color: %s" % color)


for i in range(self.everloop.ledCount):


#led = hal.led(0,0,0,0)#led.r led.g led.b led.w


led = hal.led(ledMatrix.get(color, {}).get('ledr'),


ledMatrix.get(color, {}).get('ledg'),


ledMatrix.get(color, {}).get('ledb'),


ledMatrix.get(color, {}).get('ledw'),


)#led.r led.g led.b led.w


self.leds.append(led)


del led


self.everloop.set(self.leds)



 

   Python method to dynamically set LED colors:

## LED Color set ##


def setEverloop(self, colorVal):


self.everloop = hal.everloop()


print ("Color: %s" % colorVal)


colorList = colorVal.split(":")


for i in range(self.everloop.ledCount):


#led = hal.led(0,0,0,0)#led.r led.g led.b led.w


led = hal.led(int(colorList[0], 16),


int(colorList[1], 16),


int(colorList[2], 16),


int(colorList[3], 16)


)#led.r led.g led.b led.w


self.leds.append(led)





del led


del colorList


self.everloop.set(self.leds)


 

Sorry, I am not sure what is happening with the formatting of the code but I do not have time to fix they way the code looks.

openHAB Items config

Switch SetELoopRed "EverLoop Red" { channel="exec:command:eloop_color_red:online" }
Switch SetELoopBlue "EverLoop Blue" { channel="exec:command:eloop_color_blue:online" }
Color SetELoopColor "EverLoop Color" <slider>

 

openHAB Sitemap config

Frame label="EverLoop" {


Switch item=SetELoopRed label="eLoop Red" icon="colorpicker"


Switch item=SetELoopBlue label="eLoop Blue" icon="colorpicker"


}


Frame label="EverLoop Color" {


Colorpicker item=SetELoopColor label="eLoop color" icon="colorpicker"

}

openHAB Rules

import org.eclipse.smarthome.core.library.types.HSBType

var String eLoopCmd = '/usr/bin/python3 /opt/openhab2/conf/scripts/newTempScript.py '
//var String eLoopColor = '/usr/bin/python3 /opt/openhab2/conf/scripts/newTempScript.py ' + '--color' + ' '

rule "Set Eloop Red"
when
    Item SetELoopRed received command
then
    if(receivedCommand == ON) {
        var String eLoopRed = eLoopCmd + '-e' + ' \"'+ 'red' + '\"'
        logInfo("SetELoopRed", "setting everloop to red")
        executeCommandLine(eLoopRed)
    }
    else {
        var String eLoopOff = eLoopCmd + '-e' + ' \"'+ 'off' + '\"'
        logInfo("SetELoopRed", "setting everloop to off")
        executeCommandLine(eLoopOff)
    }
end

rule "Set Eloop Blue"
when
    Item SetELoopBlue received command
then
    if(receivedCommand == ON) {
        var String eLoopBlue = eLoopCmd + '-e' + ' \"'+ 'blue' + '\"'
        logInfo("SetELoopBlue", "setting everloop to blue")
        executeCommandLine(eLoopBlue)
    }
    else {
        var String eLoopOff = eLoopCmd + '-e' + ' \"'+ 'off' + '\"'
        logInfo("SetELoopBlue", "setting everloop to off")
        executeCommandLine(eLoopOff)
    }
end

rule "Set Eloop Color"
when
    Item SetELoopColor received update
then
    logInfo("SetELoopColor", "Get Color")
    var hsbValue    = SetELoopColor.state as HSBType
    var brightness  = hsbValue.brightness.intValue
    var redValue    = ((((hsbValue.red.intValue * 255) / 100) * brightness) / 100).toString 
    var greenValue    = ((((hsbValue.green.intValue * 255) / 100) * brightness) / 100).toString 
    var blueValue    = ((((hsbValue.blue.intValue * 255) / 100) * brightness) / 100).toString 
    logWarn("Red", redValue)
    logWarn("Green", greenValue)
    logWarn("Blue", blueValue)
    var String cmd = eLoopCmd + '-c' + ' ' + '\"' + redValue + ':' + greenValue + ':' + blueValue + ':' + '0' + '\"'
    logInfo("SetELoopColor", cmd)
    executeCommandLine(cmd)

end

 

 

  openHAB Basic UI Everloop Controls

 

Well, that is about it.    This has been interesting, and as always I wished I had more time to get more done, but I at least I was able to this much configured.   There is still a whole host of things that can be done with this config and I will continue to work with it.  I'd like to thank Tariq and element14 for providing me with the MATRIX Creator and Raspberry Pi 3 A+ for the project.