Group Switch

I’m trying to setup a group switch so that when I turn off the lights in my group I want the dimmer states to be stored in a variable. I placed at the top of my rules file

var Number dimstate1
var Number dimstate2

Here is the rule i created.

> /* Living Room Group On/Off Switch */
> rule "Living Room On/Off"
> 	when
> 		Item Light_LivRoom_AllLights_Sw received command
> 	then

> 		if(receivedCommand==OFF) {

> 			if(Light_LivRoom_Steps_Dim.state instanceof PercentType) dimstate1 = Light_LivRoom_Steps_Dim.state as PercentType
> 			logInfo("Living Room Group Switch", "Variable dimstate1 = " + dimstate1)
> 			if(Light_LivRoom_Candles_Dim.state instanceof PercentType) dimstate2 = Light_LivRoom_Candles_Dim.state as PercentType
> 			logInfo("Living Room Group Switch", "Variable dimstate2 = " + dimstate2)

> 			sendCommand(Light_LivRoom_Steps_Sw, OFF)
> 			sendCommand(Light_LivRoom_Candles_Sw, OFF)
> 			postUpdate(Light_LivRoom_Steps_Sw, OFF)
> 			postUpdate(Light_LivRoom_Candles_Sw, OFF)
> 		}
> 		if(receivedCommand==ON) {		
> 			logInfo("Living Room Group Switch", "Checking variable dimstate1 = " + dimstate1 + " and dimstate2 = " + dimstate2)
> 			sendCommand(Light_LivRoom_Steps_Sw, dimstate1)
> 			sendCommand(Light_LivRoom_Candles_Sw, dimstate2)
> 			postUpdate(Light_LivRoom_Steps_Sw, dimstate1)
> 			postUpdate(Light_LivRoom_Candles_Sw, dimstate2)
> 		}

> end

This is what I am getting in my logfile. To me it seems as though my variables are getting set but it wont let me use them in my sendCommand to me it looks as though it sees them as null even though right when I click on that loginfo says the values are 100. Any input

2015-09-19 00:35:34.086 [INFO ] [openhab.model.script.Dashboard] - Item Light_LivRoom_AllLights_Sw has changed state from ON to: OFF
2015-09-19 00:35:34.246 [INFO ] [o.m.s.Living Room Group Switch] - Variable dimstate1 = 100
2015-09-19 00:35:34.290 [INFO ] [o.m.s.Living Room Group Switch] - Variable dimstate2 = 100
2015-09-19 00:35:34.316 [INFO ] [openhab.model.script.Dashboard] - Item Light_LivRoom_Steps_Sw has changed state from ON to: OFF
2015-09-19 00:35:34.340 [INFO ] [openhab.model.script.Dashboard] - Item Light_LivRoom_Candles_Sw has changed state from ON to: OFF
2015-09-19 00:35:36.182 [INFO ] [openhab.model.script.Dashboard] - Item Light_LivRoom_Steps_Dim has changed state from 100 to: 0
2015-09-19 00:35:36.187 [INFO ] [openhab.model.script.Dashboard] - Item Light_LivRoom_Candles_Dim has changed state from 100 to: 0
2015-09-19 00:36:12.001 [INFO ] [openhab.model.script.Dashboard] - Item Light_LivRoom_AllLights_Sw has changed state from OFF to: ON
2015-09-19 00:36:12.153 [INFO ] [o.m.s.Living Room Group Switch] - Checking variable dimstate1 = 100 and dimstate2 = 100
2015-09-19 00:36:12.183 [WARN ] [.c.i.events.EventPublisherImpl] - given command is NULL, couldn't send command to 'Light_LivRoom_Steps_Sw'
2015-09-19 00:36:12.210 [WARN ] [.c.i.events.EventPublisherImpl] - given command is NULL, couldn't send command to 'Light_LivRoom_Candles_Sw'
2015-09-19 00:36:12.240 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn't post update for 'Light_LivRoom_Steps_Sw'
2015-09-19 00:36:12.269 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn't post update for 'Light_LivRoom_Candles_Sw'

I realized what I did, in the rule I was trying to send a value to an on off switch. This is why you shouldn’t code sometimes at 2AM.

Snort-laugh. Been there more than once.

Been there, done that :smile:

@smar I already see you actually responded and yea it was one of this midnight coding mishaps. All good now :smile:

@Robert_Burgess Great!