Light controlled by Zwave + Hue + Kodi

Hello,

I’m using the following devices:

  • Z-Wave ZME_UZB1 Me USB Stick
  • Fibaro FIBEFGMS-001-ZW5 5G 4-in-1 Multisensor
  • Hue Starter Kit 3 RGBW + 2 Osram Plug
  • Kodi Multimedia Center

All those devices (things) were recognized and added by OpenHab. I also already defined some items using the PaperUI.

Now I’d like to create the following scenario:

1.) If the TV running, the Lights need to be controlled in dependence of the surrounding (details as follows) and switched off 3 minutes after the TV is turned off. (going to bed etc.)
2.) While the TV is running and the light sensor signals decreasing light, the Hue 3 RGBW shall compensate the decreased light by dimming up.
3.) As soon as the Hues are at 60% (maybe more - 80?) the additional 2 Lamps (connected to the Osram Plug) shall turn on.
4.) In the Morning this should work vice versa. Say the sun rises, so the 2 Lamps turn off and as it gets brighter, the Hues are dimmed down until they are off.

Will it work with my hardware, or do I need to get an outdoor sensor? If so, which one?

How could a rule look like - is there an example already?

Thank you!

Astro binding should do it http://docs.openhab.org/addons/bindings/astro/readme.html
You should also consider [Deprecated] Design Pattern: Time Of Day

Lot’s of in

or

O.k now here my first try to create this as an rule

import org.eclipse.xtext.xbase.lib.Functions

var Number nHueLevel

// Todo Hue kapseln in Lamda funtion
val Functions$Function4<DecimalType, GenericItem, GenericItem, GenericItem, String> LightLevel= [ 
	DecimalType Lux,
	GenericItem Kodi_online,
	GenericItem gLivingRoomDimmer,
	GenericItem gLivingRoomExtra|
    
    logInfo("LichtLamda","Starten brechnung!")	
    //Todo avg auf 5 minuten?
    //Todo wert noch auf Ganzahl runden
    var Number nHueLevel = 100 - ((Lux / 300) * 100)
    if (nHueLevel > 0 && Kodi_online.state == ON && gLivingRoomDimmer.state != nHueLevel) {
        
        logInfo("Rule-Licht-Dimmen","Setze neuen berechneten Wert in Hue!")	
	    sendCommand(gLivingRoomDimmer, nHueLevel)
	    
	    if(gLivingRoomExtra.state == OFF && nHueLevel > 70){
	        sendCommand(gLivingRoomExtra, ON)
	    }else if (gLivingRoomExtra.state == ON && nHueLevel < 70){
	        sendCommand(gLivingRoomExtra, OFF)
	    }	   
	    
    } else if(gLivingRoomDimmer.state > 0) {
        sendCommand(gLivingRoomDimmer, 0)
    }

    logInfo("lambdaHueLevel", nHueLevel.toString)
    //s.state.toString + " logged"
    nHueLevel.toString(); //return????
]


// ab 300 lux lampen hoch dimmen
rule "Licht dimmen wenn Fernseher an"
when
	Item Zwave_Outdoor_Lux changed
then
    //Wir berechnen den aktullen Lichtwert und damit den Hue Wert
    LightLevel.apply(Zwave_Outdoor_Lux.state as DecimalType, Kodi_online, gLivingRoomDimmer, gLivingRoomExtra)
    
    logInfo("Kodi-online.state", Kodi_online.state.toString())
end

rule "Kodi event on"
when
  Item Kodi_online changed from OFF to ON
then
    logInfo("Rule-Licht-Dimmen","Licht an ! Kodi_online is ON!")	
    LightLevel.apply(Zwave_Outdoor_Lux.state as DecimalType, Kodi_online, gLivingRoomDimmer, gLivingRoomExtra)   
end


rule "Kodi event off"
when
	Item Kodi_online changed from ON to OFF
then
    // todo irgenwie anlassen wenn es manuell war?
    logInfo("Rule-Licht-Dimmen","Licht aus! Kodi_online is OFF!")	
    sendCommand(gLivingRoomDimmer, 0)
    sendCommand(gLivingRoomExtra, OFF)
end

The Items are:

Switch Kodi_online                                { channel="network:device:kodi:online" }
Group:Switch:OR(ON, OFF) gLivingRoom	"Wohnzimmerlicht" ["Switching"]
Group:Dimmer gLivingRoomDimmer		    "Dimmer"
Group:Color gLivingRoomColor			"Farbe"
Group:Dimmer gLivingRoomColorTemp       "Color temp"
Number  Zwave_Outdoor_Lux            "Motion Sensor [%.2f Lux]"   <sun>          (Zwave_Outdoor, gChart)  { channel="zwave:device:0332b7c8:node2:sensor_luminance" }

Questions:
Kodi_online as networt item, because i don´t know how to gets the state of an thing (online/offline) inside an rule?

Also this line:
var Number nHueLevel = 100 - ((Lux / 300) * 100)
return an BigDecimal, how to round it to int)

How to get an avg from an Item?
Persitence is rrd4j databases, every minute but :

Zwave_Outdoor_Lux.averageSince(now.minusMinutes(5)) 

return 0

Thanks!