Set Tradfri Brightness using a rule

Hello all,
I’m trying to create scenes for different brightness and colour warmth combinations in OH2 using rules but I can’t get the brightness to work no matter what I do. Here’s the rule:

rule "Bedroom Scene"
	when
		Item Light_Bedroom_Scene changed
	then
	if (Light_Bedroom_Scene.state == 0)
	{
		sendCommand(Light_Bedroom_Clr, 0)
		sendCommand(Light_Bedroom_Br,100)
	}
	else
	if (Light_Bedroom_Scene.state == 1)
	{
		sendCommand(Light_Bedroom_Clr, 100)
		sendCommand(Light_Bedroom_Br,2)
	}
end

The web interface changes to reflect the number i.e. 2% or 100% but the brightness remains unchanged.

What am I doing wrong?

Please use code fences

```
code goes here
```

Add logging to your rule to see whether the rule is being triggered. If it is triggered then logging statements to see where in the rule it is failing.

Are there errors in the log when you load the rules file or when the rule executes?

I had added

logInfo( "Status is ", "x");

To test and the rule is being triggered and the commands are executed. For example, the colour changes from 0 to 100 and back. It’s only the brightness that doesn’t seem to work

Here’s an example from the events.log file (corrected)

[ItemCommandEvent ] - Item ‘Light_Bedroom_Scene’ received command 0
[ItemStateChangedEvent ] - Light_Bedroom_Scene changed from 1 to 0
[ItemCommandEvent ] - Item ‘Light_Bedroom_Clr’ received command 0
[ItemCommandEvent ] - Item ‘Light_Bedroom_Br’ received command 100
[ItemStateChangedEvent ] - Light_Bedroom_Clr changed from 100 to 0
[ItemStateChangedEvent ] - Light_Bedroom_Br changed from 71 to 100
[ItemStateChangedEvent ] - Light_Bedroom_Br changed from 100 to 71
[ItemStateChangedEvent ] - Light_Bedroom_Br changed from 71 to 100

It seems to change the brightness to 100 (as expected) but then back to the original value then again to 100. Very odd!

That is events.log. What does it say in openhab.log.

Nothing. Just tested it.

So you do not even see your X log statement?

Yes I do but I’ve commented it out since I only used it to check that the rule was being triggered.

what are your tradfri-bulbs? http://docs.openhab.org/addons/bindings/tradfri/readme.html
may i see your item definitions?

Switch Light_Bedroom_Sw {channel=“tradfri:0220:Tradfri:bulb:brightness”}
Dimmer Light_Bedroom_Br {channel=“tradfri:0220:Tradfri:bulb:brightness”}
Dimmer Light_Bedroom_Clr {channel=“tradfri:0220:Tradfri:bulb:color_temperature”}

and this one?

Item Light_Bedroom_Scene

Number Light_Bedroom_Scene “Ceiling Scene”

Sitemap entry

Selection item=Light_Bedroom_Scene mappings=[ 0=“Scene 0”,
1=“Scene 1”]

:slight_smile: no idea, but i like your rule: bright & cold as hell or dark & warm as mothers breast

just try at least 10 or 20 percent in

sendCommand(Light_Bedroom_Br,2)

lol
Tried 80 for scene 0 and 20 for scene 1

The web interface changes to reflect the value albeit after I hit F5 to refresh the page but nothing happens except the colour. Do you think this is something to do with the binding itself? It works fine if I use a slider on the OH webpage to change.

Been there, done that :slight_smile: