Dynamic light scene - Is my rule OK or is there an easier way to do it?

Hi to all,

I have created some dynamic light scenes and I struggled with many problems before getting it to work. I would really be happy for some hints to make things easier or if not possible confirmation that this is a good way to do it.

I have two Ikea lamps on a feet that are like a long tube with 3 zones with bulbs, let's say bottom, middle and top. The dynamic scene I present here will start with a moon color (4000k) with 90% intensity in the middle and sun color (2200K) with 15% intensity in the bottom and top zone.

The dynamic changes are:
First the top color and intensity change on a defined time period (3 minutes) to 4000:90 while the middle color changes in the same time to 2200:15. This makes the bright moon color wandering very softly from the middle to the top. Then the moon color wanders to the bottom field and then to the middle again (back to initial states). This cycle repeats endless until stopped. I use private boolean to assure that only one instance of the rule runs.

As I installed multiple dynamic scene rules, I use a hub variable to know the scene that runs, or zero if no scene runs and so on. I also use this to assure that a scene is stopped if I start another one. A rule on lights turning OFF setting this variable to 0 assures that the scene stops and does not turn the light on again.

The hub variable is : vDynamicSceneTVlamp

The rule variables are the following:


I use these local variables for internal rule requirements (scene/SlotChanged) but also to be able to change color temperatures, dimmers and time the easy way without any changes in the rule itself.

Here is the rule

IF (Private Boolean(true) is false(F) [FALSE]) THEN
	Exit Rule
END-IF
Set Private Boolean(true) False
Comment: ==================> Initialize states and variables
Color Temperature: Ikea Bulb Lampadaire (01) gauche bas, Ikea Bulb Lampadaire (03) gauche haut, Ikea Bulb Lampadaire (04) droite bas, Ikea Bulb Lampadaire (06) droite haut: cSunColor(2200): LowIntensity(15)
Color Temperature: Ikea Bulb Lampadaire (05) droite milieu, Ikea Bulb Lampadaire (02) gauche milieu: cMoonColor(4000): High Intensity(90)
Set Scene to 1
Set SlotChanged to true
Set vDynamicSceneTVlamp to 1
Comment: ==================> Loop and check every 10 seconds for changes
Repeat every 0:00:10 (stoppable)
	Comment: =================> If Scene is deactivated - Turn Timers OFF and Exit
	IF (Variable vDynamicSceneTVlamp(0) != 1(T) [TRUE]) THEN
		Cancel Timed Actions: **This Rule**
		Set Private Boolean(true) True
		Log: 'Moonrise : Check for stop was run'
		Exit Rule
	END-IF
	Comment: ==================> Check for required scene change and initiate it
	IF (Ikea Bulb Lampadaire (03) gauche haut colorTemperature(2801) >= cMoonColor(4000) (F) [FALSE]) THEN
		Set SlotChanged to true
		Set Scene to 2
	END-IF
	IF (Ikea Bulb Lampadaire (01) gauche bas colorTemperature(2801) >= cMoonColor(4000) (F) [FALSE]) THEN
		Set SlotChanged to true
		Set Scene to 3
	END-IF
	IF (Ikea Bulb Lampadaire (02) gauche milieu colorTemperature(2801) >= cMoonColor(4000) (F) [FALSE]) THEN
		Set SlotChanged to true
		Set Scene to 1
	END-IF
	Comment: ==================> Start initiated scene changes
	IF (Variable Scene(3) = 1(F)  AND 
	Variable SlotChanged(false) = true(F) [FALSE]) THEN
		Set SlotChanged to false
		Change Ikea Bulb Lampadaire (05) droite milieu, Ikea Bulb Lampadaire (02) gauche milieu down to cSunColor(2200) over TimeSlot(3) minutes with 10.0 seconds interval
		Fade Ikea Bulb Lampadaire (05) droite milieu, Ikea Bulb Lampadaire (02) gauche milieu down to LowIntensity(15) over TimeSlot(3) minutes with 10.0 seconds interval
		Change Ikea Bulb Lampadaire (03) gauche haut, Ikea Bulb Lampadaire (06) droite haut up to cMoonColor(4000) over TimeSlot(3) minutes with 10.0 seconds interval
		Fade Ikea Bulb Lampadaire (03) gauche haut, Ikea Bulb Lampadaire (06) droite haut up to High Intensity(90) over TimeSlot(3) minutes with 10.0 seconds interval
	END-IF
	IF (Variable Scene(3) = 2(F)  AND 
	Variable SlotChanged(false) = true(F) [FALSE]) THEN
		Set SlotChanged to false
		Change Ikea Bulb Lampadaire (04) droite bas, Ikea Bulb Lampadaire (01) gauche bas up to cMoonColor(4000) over TimeSlot(3) minutes with 10.0 seconds interval
		Fade Ikea Bulb Lampadaire (04) droite bas, Ikea Bulb Lampadaire (01) gauche bas up to High Intensity(90) over TimeSlot(3) minutes with 10.0 seconds interval
		Change Ikea Bulb Lampadaire (03) gauche haut, Ikea Bulb Lampadaire (06) droite haut down to cSunColor(2200) over TimeSlot(3) minutes with 10.0 seconds interval
		Fade Ikea Bulb Lampadaire (03) gauche haut, Ikea Bulb Lampadaire (06) droite haut down to LowIntensity(15) over TimeSlot(3) minutes with 10.0 seconds interval
	END-IF
	IF (Variable Scene(3) = 3(T)  AND 
	Variable SlotChanged(false) = true(F) [FALSE]) THEN
		Set SlotChanged to false
		Change Ikea Bulb Lampadaire (04) droite bas, Ikea Bulb Lampadaire (01) gauche bas down to cSunColor(2200) over TimeSlot(3) minutes with 10.0 seconds interval
		Fade Ikea Bulb Lampadaire (04) droite bas, Ikea Bulb Lampadaire (01) gauche bas down to LowIntensity(15) over TimeSlot(3) minutes with 10.0 seconds interval
		Change Ikea Bulb Lampadaire (05) droite milieu, Ikea Bulb Lampadaire (02) gauche milieu up to cMoonColor(4000) over TimeSlot(3) minutes with 10.0 seconds interval
		Fade Ikea Bulb Lampadaire (05) droite milieu, Ikea Bulb Lampadaire (02) gauche milieu up to High Intensity(90) over TimeSlot(3) minutes with 10.0 seconds interval
	END-IF
END-REP

When I did a rule that changed bulb states constantly, I used similar logic. I suspect that doing this via an app might be easier on the hub, but can’t say for sure… When I had my rule running, the hub soon complained of high processor usage. I would be worried of overwhelming the Zigbee radio or mesh, but if it works for you, than it should be okay. I’m sure others that have done something similar will chime in.

On the rule itself, there are a only two minor things that stand out to me:

  1. Within your Repeat, in your first if statement, you could also use a “Stop Repeat Action” command instead of the “Cancel Timed Actions” command.
  2. Within this same statement, you don’t need the “Exit Rule” command. The rule will be exited regardless as there are no follow-up commands after your end-rep.

How did you output and/or save that formatted text version of your rule? Looks nice.

Are you sure that this will work? Even exiting the rule without stopping the timed actions ended up in a weird behaviour with the bulbs turning on again with wrong values. I suppose that switching the bulbs off changed the values to zero and the timed actions added a value to them.

My impression was that the timed actions run in a kind of subtask that continues to run when the main rule is killed.

Opened the rule, clicked on the actions to get the editor, selected all the text, pasted it in the topic, selected all and clicked on the code button in the header :wink:

1 Like

I did some testing and it should, but not with your rule. If you want to test it, make a copy (clone) of the rule and test it with that.