Skip to content

ShutterBox and wLightBox control

JakubSzabat edited this page Jul 8, 2016 · 9 revisions

#Blebox's wLightbox and ShutterBox control, using OpenHab 2.0 on RaspberryPi 3

File .rules

Here you need to write IP addresses of your devices (change IP variables)

import org.joda.time.*
import org.openhab.core.library.types.*

var string IP_SHUTTER = "192.168.9.65"
var string IP_LIGHT = "192.168.9.73"

var HSBType hsbValue
var string  redValue = "00"
var string  greenValue = "00"
var string  blueValue = "00"
var string  whiteValue = "00"
var int     fade = 255
var Timer timer = null

Rule's sending different get request every time when Shutter received command

rule "Set RollerShutter value"
    when
            Item DemoShutter received command
	then
			if 		(receivedCommand==UP)	sendHttpGetRequest("http://"+IP_SHUTTER+"/s/u")
			else if	(receivedCommand==DOWN)	sendHttpGetRequest("http://"+IP_SHUTTER+"/s/d")
			else if (receivedCommand==STOP)	sendHttpGetRequest("http://"+IP_SHUTTER+"/s/s")
end

This rule is changing color of RGB diode (set on colorpicker wheel) or fading speed (Arrow UP/DOWN buttons), depending of received command

rule "Set RGBLight value"
    when
            Item RGBLight received command
    then
			if (receivedCommand==INCREASE){
				if(fade<255)	fade=fade+5
				else		fade=255
				sendHttpPostRequest("http://"+IP_LIGHT+"/api/rgbw/set","text/plain","{\"rgbw\":{\"fadeSpeed\":"+fade+"}}")
				logInfo("posty", "inc:" + fade)
				postUpdate("Speed",Integer::toString(fade))
			}
			else if(receivedCommand==DECREASE){
				if(fade>0)	fade=fade-5
				else		fade=0
				sendHttpPostRequest("http://"+IP_LIGHT+"/api/rgbw/set","text/plain","{\"rgbw\":{\"fadeSpeed\":"+fade+"}}")
				logInfo("posty", "dis:" + fade)
				postUpdate("Speed",Integer::toString(fade))
			}
			else{
				hsbValue = RGBLight.state as HSBType
			
				if((hsbValue.red*2.55).intValue > 15){
					redValue = Integer::toHexString((hsbValue.red*2.55).intValue)
				}
				else{
					redValue = "0" + Integer::toHexString((hsbValue.red*2.55).intValue)
				}
			
				if((hsbValue.green*2.55).intValue > 15){
					greenValue = Integer::toHexString((hsbValue.green*2.55).intValue)
				}
				else{
					greenValue = "0" + Integer::toHexString((hsbValue.green*2.55).intValue)
				}
			
				if((hsbValue.blue*2.55).intValue > 15){
					blueValue = Integer::toHexString((hsbValue.blue*2.55).intValue)
				}
				else{
					blueValue = "0" + Integer::toHexString((hsbValue.blue*2.55).intValue)
				}

				logInfo("RGB", "R:" + redValue + " G:" + greenValue + " B:" + blueValue + " W:" + whiteValue)
			
				sendHttpGetRequest("http://"+IP_LIGHT+"/s/"+redValue+greenValue+blueValue+whiteValue)
			}
    end

This rule is changing brightness of white diode (set by a dimmer)

rule "Set WhiteLight value"
    when
            Item DimmedLight received command
    then
			var Number percent = 0
    		if(DimmedLight.state instanceof DecimalType) percent = DimmedLight.state as DecimalType 
			
			if(percent*2.55 > 15){
				whiteValue = Integer::toHexString((percent*2.55).intValue)
			}
			else{
				whiteValue = "0" + Integer::toHexString((percent*2.55).intValue)
			}
			
			logInfo("RGB", "R:" + redValue + " G:" + greenValue + " B:" + blueValue + " W:" + whiteValue)
			
			sendHttpGetRequest("http://"+IP_LIGHT+"/s/"+redValue+greenValue+blueValue+whiteValue)
end

##File .items In .items you have to use your ShutterBox IP in place of {IP_SHUTTER} to control current position of roller shutter (HTTP binding and JSON transformation needed)

Color  RGBLight                 "RGB Diodes"       		<slider>		
Rollershutter DemoShutter       "RollerShutter [%d]"	<rollershutter>	{http="<[http://{IP_SHUTTER}/api/shutter/state:1000:JSONPATH($.currentPos)]"}
Number Speed            		"Fade Speed [%d]"    	<slider>

##File .sitemaps Definition of interface icons and frame

Frame label="BleBox" {
				Slider item=DimmedLight switchSupport
				Colorpicker item=RGBLight icon="slider"
				Switch item=DemoShutter
				Text   item=Speed
			}

##How to use it and how it looks like userinterface

  • "Fade speed" is a indicator which shows fade speed from maximum (255 = instant) to minimum (0 = about 1 hour)
  • "RGB Diode" allows us to change color of diodes using color-picker ( palette button) and fade speed (UP/DOWN arrows)
  • "RollerShutter" can close or open our roller shutter (UP/DOWN arrows), operation can be stopped in any moment (X button)
  • "White Diode" allows us to change brightness of white diodes (slider button)
Clone this wiki locally