[SOLVED] Light patterns

Hello,

I currently use two main patterns for adjusting light levels:

  1. Adjusting lights that are currently ON based on time of day (Astro is not a good idea in Norway as we have few non-sunny hours in the summer and few sunny hours during the winter).
  2. For some motion triggered lights (for example in the bathroom) I have special rules which, when motion is detected, turns some lights on or not based on time of day and adjusts the light to different levels than those in #1.

What I am missing now is some way of dimming lights which are turned on and are not in the #2-umbrella to (for example) the PresetDimLevel.

Something like:

rule "Some light switched to ON. Set the changed light to correct dimlevel"
when gLight changed
    //Figure out which light it was that changed to ON
    //Set this light to the correct dimlevel
end

Is there a common pattern for this which I can re-use?

My “patterns”
Pattern 1: Adjusting dimlevels for lights that are already on

Items:
Group gDimmer
Number Dimmer1 (gDimmer) {....}
Number Dimmer2 gDimmer) {....}

Number PresetDimLevel
Switch UpdateLightLevels

Rules:
rule "6:30, weekday - night is over,  adjust to early morning light"
when
    Time cron "0 30 6 ? * * *"
then
PresetDimLevel.postUpdate(20)
    Thread::sleep(500)
    UpdateLightLevels.sendCommand(ON)
end

rule "React on UpdateLightLevels switch, send target percentage"
when
    Item UpdateLightLevels changed to ON
then
    UpdateLightLevels.postUpdate(OFF)
    gDimmer.members.forEach[ item | 
      if (item.state > 0) {
             logInfo("lightingschedule.rules", "Item state: " + item.state) 
             item.sendCommand(FF_AllLights_PresetPercNormal.state as Number) 
       }                         
}

Pattern 2: Turning on lights by motion detection

Items:
Contact Bathroom_Motion
Switch Bathroom_Dimmable_Light {....,expire=....}
Bathroom_Small_Lights {...}
Bathroom_Strong_Light {...}

rule "Bathroom_Motion received update"
when
	Item Bathroom_Motion received update
then
	if (Bathroom_Dimmable_Light.state==ON){
		Bathroom_Dimmable_Light.postUpdate(ON) //Delay expire
	}
	else{
       val CurrentHour = now.getHourOfDay
	   if (CurrentHour > 6 && CurrentHour < 11){
				Bathroom_Dimmable_Light.sendCommand(70)
				Bathroom_Small_Lights.sendCommand(ON)
	   }
       else if (CurentHour....)..
end

Edit: The Solved-post gave the right answer and another post show my actual implementation which includes this solution.

Would this be what you are looking for:

rule "Some light switched to ON. Set the changed light to correct dimlevel"
when
    Member of gLight changed
then
    triggeringItem.sendCommand(dimlevel)
end
1 Like

Yes! I did not know about the triggeringItem.

In order to make this as general as possible (and in order to be able to turn off lights - which I don’t think will be possible with the rule above), one would need to check for something like:

when
Member of gLight changed from 0
then

end

But documentation has it that this should work just fine!

Thanks!

Hmmm, it seems like it should have worked and I get the following logged:

“2018-10-25 19:35:26.595 [ome.event.ItemCommandEvent] - Item ‘FF_Sov2_Light_Dimmer’ received command 20”

So the rule correctly sends the command and I get the “received command”-event, but not the two “predicted to become”- and “changed to”-events which I get if I use the openhab-console to send the command for example. And the light is not dimmed to 20 as hoped.

Here is the debug-log:

2018-10-25 19:35:26.056 [vent.ItemStateChangedEvent] - FF_Sov2_Light_Dimmer changed from 0 to 19
2018-10-25 19:35:26.062 [GroupItemStateChangedEvent] - gDimmer changed from 12.00000000 to 13.90000000 through FF_Sov2_Light_Dimmer
2018-10-25 19:35:26.065 [vent.ItemStateChangedEvent] - FF_Sov2_Light_Switch changed from OFF to ON
2018-10-25 19:35:26.085 [INFO ] [model.script.Lightningschedule.rules] - The dimmable item FF_Sov2_Light_Dimmer turned on. Dim to correct level.
2018-10-25 19:35:26.595 [ome.event.ItemCommandEvent] - Item 'FF_Sov2_Light_Dimmer' received command 20
2018-10-25 19:35:28.043 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 10 00 04 00 07 0A 60 0D 01 01 31 05 04 22 00 11 88
2018-10-25 19:35:28.048 [DEBUG] [nal.protocol.ZWaveTransactionManager] - processReceiveMessage input 0&lt;&gt;128 : Message: class=ApplicationCommandHandler[4], type=Request[0], dest=7, callback=0, payload=00 07 0A 60 0D 01 01 31 05 04 22 00 11
2018-10-25 19:35:28.051 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Received msg (0): Message: class=ApplicationCommandHandler[4], type=Request[0], dest=7, callback=0, payload=00 07 0A 60 0D 01 01 31 05 04 22 00 11
2018-10-25 19:35:28.054 [DEBUG] [nal.protocol.ZWaveTransactionManager] - lastTransaction null
2018-10-25 19:35:28.057 [DEBUG] [nal.protocol.ZWaveTransactionManager] - NODE 7: Application Command Request (ALIVE:DONE)
2018-10-25 19:35:28.059 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: resetResendCount initComplete=true isDead=false
2018-10-25 19:35:28.062 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: Decapsulating COMMAND_CLASS_MULTI_CHANNEL
2018-10-25 19:35:28.065 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: Incoming command class COMMAND_CLASS_SENSOR_MULTILEVEL, endpoint 1
2018-10-25 19:35:28.067 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: SECURITY NOT required on COMMAND_CLASS_SENSOR_MULTILEVEL
2018-10-25 19:35:28.070 [DEBUG] [tocol.commandclass.ZWaveCommandClass] - NODE 7: Received COMMAND_CLASS_SENSOR_MULTILEVEL V4 SENSOR_MULTILEVEL_REPORT
2018-10-25 19:35:28.072 [DEBUG] [ss.ZWaveMultiLevelSensorCommandClass] - NODE 7: Sensor Type = Power(4), Scale = 0
2018-10-25 19:35:28.077 [DEBUG] [ss.ZWaveMultiLevelSensorCommandClass] - NODE 7: Sensor Value = 1.7
2018-10-25 19:35:28.079 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 7: Got an event from Z-Wave network: ZWaveMultiLevelSensorValueEvent
2018-10-25 19:35:28.081 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 7: Got a value event from Z-Wave network, endpoint = 1, command class = COMMAND_CLASS_SENSOR_MULTILEVEL, value = 1.7
2018-10-25 19:35:28.084 [DEBUG] [erter.ZWaveMultiLevelSensorConverter] - NODE 7: Sensor conversion not performed for POWER.
2018-10-25 19:35:28.085 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 7: Updating channel state zwave:device:512:node7:sensor_power1 to 1.7 [DecimalType]
2018-10-25 19:35:28.091 [DEBUG] [nal.protocol.ZWaveTransactionManager] - NODE 7: Commands processed 1.
2018-10-25 19:35:28.093 [DEBUG] [nal.protocol.ZWaveTransactionManager] - NODE 7: Checking command org.openhab.binding.zwave.internal.protocol.ZWaveCommandClassPayload@a6d001.
2018-10-25 19:35:28.095 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Transaction completed - outstandingTransactions 0
2018-10-25 19:35:28.097 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Transaction completed - outstandingTransactions 0
2018-10-25 19:35:28.099 [DEBUG] [nal.protocol.ZWaveTransactionManager] - ZWaveReceiveThread queue empty
2018-10-25 19:35:28.101 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Transaction SendNextMessage 0 out at start. Holdoff false.
2018-10-25 19:35:31.030 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 10 00 04 00 07 0A 60 0D 01 01 31 05 04 22 00 11 88
2018-10-25 19:35:31.036 [DEBUG] [nal.protocol.ZWaveTransactionManager] - processReceiveMessage input 0&lt;&gt;128 : Message: class=ApplicationCommandHandler[4], type=Request[0], dest=7, callback=0, payload=00 07 0A 60 0D 01 01 31 05 04 22 00 11
2018-10-25 19:35:31.039 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Received msg (0): Message: class=ApplicationCommandHandler[4], type=Request[0], dest=7, callback=0, payload=00 07 0A 60 0D 01 01 31 05 04 22 00 11
2018-10-25 19:35:31.041 [DEBUG] [nal.protocol.ZWaveTransactionManager] - lastTransaction null
2018-10-25 19:35:31.044 [DEBUG] [nal.protocol.ZWaveTransactionManager] - NODE 7: Application Command Request (ALIVE:DONE)
2018-10-25 19:35:31.045 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: resetResendCount initComplete=true isDead=false
2018-10-25 19:35:31.047 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: Decapsulating COMMAND_CLASS_MULTI_CHANNEL
2018-10-25 19:35:31.049 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: Incoming command class COMMAND_CLASS_SENSOR_MULTILEVEL, endpoint 1
2018-10-25 19:35:31.051 [DEBUG] [ng.zwave.internal.protocol.ZWaveNode] - NODE 7: SECURITY NOT required on COMMAND_CLASS_SENSOR_MULTILEVEL
2018-10-25 19:35:31.053 [DEBUG] [tocol.commandclass.ZWaveCommandClass] - NODE 7: Received COMMAND_CLASS_SENSOR_MULTILEVEL V4 SENSOR_MULTILEVEL_REPORT
2018-10-25 19:35:31.055 [DEBUG] [ss.ZWaveMultiLevelSensorCommandClass] - NODE 7: Sensor Type = Power(4), Scale = 0
2018-10-25 19:35:31.057 [DEBUG] [ss.ZWaveMultiLevelSensorCommandClass] - NODE 7: Sensor Value = 1.7
2018-10-25 19:35:31.058 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 7: Got an event from Z-Wave network: ZWaveMultiLevelSensorValueEvent
2018-10-25 19:35:31.060 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 7: Got a value event from Z-Wave network, endpoint = 1, command class = COMMAND_CLASS_SENSOR_MULTILEVEL, value = 1.7
2018-10-25 19:35:31.062 [DEBUG] [erter.ZWaveMultiLevelSensorConverter] - NODE 7: Sensor conversion not performed for POWER.
2018-10-25 19:35:31.064 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 7: Updating channel state zwave:device:512:node7:sensor_power1 to 1.7 [DecimalType]
2018-10-25 19:35:31.066 [DEBUG] [nal.protocol.ZWaveTransactionManager] - NODE 7: Commands processed 1.
2018-10-25 19:35:31.068 [DEBUG] [nal.protocol.ZWaveTransactionManager] - NODE 7: Checking command org.openhab.binding.zwave.internal.protocol.ZWaveCommandClassPayload@154131.
2018-10-25 19:35:31.070 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Transaction completed - outstandingTransactions 0
2018-10-25 19:35:31.071 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Transaction completed - outstandingTransactions 0
2018-10-25 19:35:31.073 [DEBUG] [nal.protocol.ZWaveTransactionManager] - ZWaveReceiveThread queue empty
2018-10-25 19:35:31.075 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Transaction SendNextMessage 0 out at start. Holdoff false.

Post the rule as well?

Yeah, not a bad idea, thanks:

    rule "Some dimmable light switched to ON. Set the changed light to correct dimlevel"
    when
        Member of gDimmer changed from 0
    then
        logInfo("Lightningschedule.rules", "The dimmable item " + triggeringItem.name + " turned on. Dim to correct level.")
        Thread::sleep(500)
        triggeringItem.sendCommand(FF_AllLights_PresetPercNormal.state)
    end

Assuming FF_AllLights_PresetPercNormal is a Dimmer, try:

triggeringItem.sendCommand((FF_AllLights_PresetPercNormal.state  as DecimalType).intValue)

I have not tried that actual construct, but this works:

var int BvoolState = (SqueezeBoxBoomsVolume.state as DecimalType).intValue

if (Cstate > 0) {
    BvoolState += 10
} else {
    BvoolState -= 10
}
SqueezeBoxBoomsVolume.sendCommand(BvoolState);

BTW see my example in handling triggeringItem in bottom half here. Nice feature.

1 Like

That worked perfectly!

  1. Remove the Thread:sleep it serves no purpose and locks the thread for 1/2 a second
  2. triggeringItem.sendCommand(FF_AllLights_PresetPercNormal.state as Number) should suffice
2 Likes

Thanks. “as Number” is what I have used elsewhere too.

Nice. One always learn something browsing this forum :slight_smile:

Adding asDecimalType (deprecated) and then transforming into and int is adding to the execution time and adding a lot of time at parsing time.
Try not to use primitives (int, floats…) unless really necessary

Could you say why?

it is adding to the execution time and adding a lot of time at parsing time.

I’m using the Astro binding for sun-rise/set with location set to Oslo without any issues for over a year now.
What was you problem?
Are you even further north perhaps?

I live in Oslo as well, but using astro sounds like a very bad idea to me. The sunrise July 1st is at like 4AM, too early for all lights to be way bright imo, and now it’s at 8.15 or something which is too late.

If my kids wake up at 5AM to go pee, I want them to feel it’s night and go back to bed, preferably without waking us up, both in the winter and the summer.

So, for regular work days, all lights are dimmed way down until 6 or 6.30 and are way bright from 7 when the day has started. And all lights start dimming slowly down from 7PM onward.

My outdoor lights are astro-timed though and that works well.

Ah, my bad, I thought you were talking about the outdoor lights all along.
This is indeed the only thing I use it for also.