Jalousie (venetian blinds) control even without positioning information

Hi community

This is an approach to control jalousie (venetian blinds, Verbundraffstoren, Lamellenstoren) when your controller can not read the position of the jalousie and its slats. This is unfortunately the case with my KNX controller I have in place.

Requirements:

  • I use my jalousie mostly covering the whole window (jalousie entirely down). But I need to adjust the position of the slats in order to control the brightness in the room.
  • I want to control them manually but need also to have the basis for a complete automated shading of the house according the sun position and intensity (LUX).
  • Manual individual jalousie control (Up/Down/Stop)

Approach:
For every jalousie I defined 3 items:

  1. The rollershutter item for manual individual jalousie control (out of the box)
  2. Shading (Beschattung) switch. If this is set to ON then the jalousie gets down entirely and the slats will be adjusted according to
  3. the Dimmer. The dimmer controls the brightness in the room. Eg. 50% means the slats are in a 45° position.

Solution
For every jalousie 3 items are defined:

Rollershutter J_Wohnen_5                "Süd [%d %%]"               <blinds>        (Wohnen)        {channel="knx:device:bridge:generic:J_Wohnen_5"}
Switch JS_Wohnen_5                      "Süd Beschattung [%s]"      <blinds>        (Wohnen,gShade) //JS=Jalousie Shading
Dimmer JD_Wohnen_5                      "Süd Dimmen [%d %%]"        <light>         (Wohnen,gJDimm) //JD=Jalousie Dimming

They always start with J_, JS_ and JD_

In the rules the following variables are defined:

import java.time.ZonedDateTime // needed for now() etc
//Variables/////////////////////////////////////
var long vJalousieDownTimeNeed = 62E9   //Max Time [nano seconds] needed for every jalousie to go completly down ideal 62s = 62E9 ns
var long vSlats90 = 2.0E9     //Max time [ns] needed for slats going from  horizontal (0°) to vertical (90°) Ideal=2.0s = 2E9ns
var long vSlats0  = 1.6E9	  //Max time [ns] needed for slats going from  vertical (90°) to horizontal (0°) from the time the strings are tightened Ideal=1.6s = 1.6E9ns
var long vSlatStringsTighten = 1.0E9	// Time from slats are vertical until the strings are tightended and slats start to move Ideal=1.0s = 1.0E9ns
////////////////////////////////////////////////

As there are no position information available the control is entirely time based. These variables define the different times. Their values need to be experimental adjusted to your configuration.

The following rules implement the logic:

// Activates the shading of a Jalousie when a corresponding shading switch is set to ON
rule "gShade Activate Shading"
when 
  Member of gShade changed from OFF to ON					//When any shading switch changed to ON
  then
   	var String vShadeSwitchName = triggeringItem.name		//Name of Beschattungs Switch, witch triggered the event - Beschattungs Switch Names Start with "JB_"= JalousieBeschattung
	if (!vShadeSwitchName.startsWith("JS_")) {				//Check if triggering item is name is in correct format and therefore the correct function can be assumed
		logError("org.openhab", "Event triggerItem " + vShadeSwitchName + " does not start with 'JS_', therefore the corresponding items can not be found - rule terminated")
		return
		}	
	var String vShadeDimmerName = vShadeSwitchName.replaceFirst("JS_","JD_")     //Name of the corresponding jalousie slats dimmer - These names start with "JD_" = Jalousie dimming
	var vShadeDimmerItem = ScriptServiceUtil.getItemRegistry.getItem(vShadeDimmerName)
	
	var String vShadeName = vShadeSwitchName.replaceFirst("JS_","J_") 			//Name of the corresponding jalousie - These names start with "J_" = Jalousie
	var vShadeItem = ScriptServiceUtil.getItemRegistry.getItem(vShadeName)
	
	vShadeItem.sendCommand(DOWN)
	createTimer(ZonedDateTime::now.plusNanos(vJalousieDownTimeNeed)) [ | vShadeItem.sendCommand(UP) ]
	var Number vShadeDimValue = (vShadeDimmerItem.state as Number)
	if (!(vShadeDimValue>=0.0 && vShadeDimValue<=100.0)) 
	    {logError("org.openhab", "Shade dimmer item "+ vShadeDimmerItem + "value is not between 0..100. Therefore using for calculation = 50")
		 vShadeDimValue=50
		}
	var long vSlatsTime = (vSlats0 * (vShadeDimValue / 100f)).longValue
	createTimer(ZonedDateTime::now.plusNanos(vJalousieDownTimeNeed + vSlatStringsTighten + vSlatsTime)) [ |	
					if (triggeringItem.state==ON) 
					  {vShadeItem.sendCommand(STOP)  //Avoid stop if Switch is already switched back to off
						 vShadeItem.postUpdate(100)
						} // end if
			        ]
end   //
////////////////////////////////////////////////////////////////////////////////////////////////


//DeActivates the shading of a Jalousie when a corresponding shading switch is set to OFF//////////
rule "gShade Deactivate Shading"
when 
  Member of gShade changed from ON to OFF				//When any shading switch changed to OFF
  then
   	var String vShadeSwitchName = triggeringItem.name		//Name of Beschattungs Switch, witch triggered the event - Beschattungs Switch Names Start with "JB_"= JalousieBeschattung
	if (!vShadeSwitchName.startsWith("JS_")) {				//Check if triggering item is name is in correct format and therefore the correct function can be assumed
		logError("org.openhab", "Event triggerItem " + vShadeSwitchName + " does not start with 'JS_', therefore the corresponding items can not be found - rule terminated")
		return
		}	
	
	var String vShadeName = vShadeSwitchName.replaceFirst("JS_","J_") 			//Name of the corresponding jalousie - These names start with "J_" = Jalousie
	var vShadeItem = ScriptServiceUtil.getItemRegistry.getItem(vShadeName)
	vShadeItem.sendCommand(UP)

end
////////////////////////////////////////////////////////////////////////////////////////////////


//Jalousie dimming - Adjusts the slats of a jalousie when a corresponding  jalousie dimmer is changed
rule "Adjust slats when jalousie dimmer changed"
when 
  Member of gJDimm changed				//When any Jalousie dimmer changed
then
	var vShadeDimmerItem = triggeringItem
	var vShadeDimmerName  = vShadeDimmerItem.name
	if (!vShadeDimmerName.startsWith("JD_")) {				//Check if triggering item is name is in correct format and therefore the correct function can be assumed
		logError("org.openhab", "Event triggerItem " + vShadeDimmerName + " does not start with 'JD_', therefore the corresponding items can not be found - rule terminated")
		return
		}	

	var String vShadeName = vShadeDimmerName.replaceFirst("JD_","J_") 			//Name of the corresponding jalousie - These names start with "J_" = Jalousie
	var vShadeItem = ScriptServiceUtil.getItemRegistry.getItem(vShadeName)

	var Number vShadeDimValue = (vShadeDimmerItem.state as Number)
	if (!(vShadeDimValue>=0.0 && vShadeDimValue<=100.0)) 
	    {logError("org.openhab", "Shade dimmer item "+ vShadeDimmerItem + "value is not between 0..100. Therefore using for calculation = 50")
		 vShadeDimValue=50
		}
	var long vSlatsTime = (vSlats0 * (vShadeDimValue / 100f)).longValue
	vShadeItem.sendCommand(DOWN)
	createTimer(ZonedDateTime::now.plusNanos(vSlats90), [ | vShadeItem.sendCommand(UP)     ])
	createTimer(ZonedDateTime::now.plusNanos(vSlats90 + vSlatStringsTighten + vSlatsTime), [ |	
			vShadeItem.sendCommand(STOP)
			vShadeItem.postUpdate(100)
	        ])
end

For every jalousie the corresponding rollershutter (J_), Shading switch (JS_) and Dimmer (JD_) item are automatically found.

If anyone is interested about the additional rules for an automated shading control based on this and the sun position let me know.

Cheers Thomas

2 Likes

Thanks for posting! I’ve moved the post to the proper category.

Code updated to work with Openhab Version 3.0+. (Should also work with OH 2.5+, but not tested)

1 Like

Thx Thomas for sharing your code. I’ve a similar task just based on a velux klf200 and somfy motor controller. You mentioned in your last post that you updated your code to OH 3.0. Is this code somewhere accessible and if so - where can I find it?

cheers /jeko

Hi Jeko. Yes the code is above in the article. It is updated for OH3.
You see it from the timers, they are now based on ZonedDateTime. BR

Thanks for clarifying that. Then I can start from there.
cheers/jeko