previousState getting -2 and not previous state

Folks,

I have a rule which dims the kitchen when it’s bedtime. This works and works by sending a HSB to the various LEDS of 240,100,10 (Dim blue)
When movement is detected it brightens it up by sending 240,100,100 - this too works.
When the movement timesout I want to set it to the previous value.

Persistence is working well with mysql and logs them. However, when I get previous it seems to get previous -2 and not the previous one.

image

logic in my rule:

	else if (scene == "MOTION_KITCHEN_NIGHT"){
		sendCommand(g_Kitchen_color, new HSBType(new DecimalType(240), new PercentType(100), new PercentType(100)))
	}
	else if (scene == "NO_MOTION_KITCHEN_NIGHT"){
		var String  str = kitchen_colour_proxy.previousState.state.toString()
		var String[] parts
        parts =  str.split(",")

        g_Kitchen_color.sendCommand(HSBType::fromRGB(Integer::parseInt(parts.get(0)), Integer::parseInt(parts.get(1)), Integer::parseInt(parts.get(2))))
	}
	else if (scene == "BRIGHT"){
		sendCommand(g_Kitchen_color,  new HSBType(new DecimalType(240), new PercentType(100), new PercentType(100)))
		sendCommand(g_KitchenCeiling, ON)
	}
	else if (scene == "DARK"){
		sendCommand(g_Kitchen_color,  new HSBType(new DecimalType(30), new PercentType(100), new PercentType(20)))
		sendCommand(g_KitchenCeiling, OFF)
	}
	else if (scene == "BED_ALL"){
		sendCommand(g_Kitchen_color,  new HSBType(new DecimalType(240), new PercentType(100), new PercentType(10)))
		sendCommand(g_KitchenCeiling, OFF)
	}

the proxy item is in the kitchen group and is used to to track what that group does.
When I step through it I can see it logs to mysql the bedtime, then the movement but when there is no movement it picks up the one before bedtime which was a random value I was playing with.

Amy I being daft?

p.s.
I know my sendCommands are the wrong ones. Not yet got round to changing them :slight_smile:

try: kitchen_colour_proxy.previousState().state.toString() → note the ()
if that doesn’t help, please try to insert some debugs like

...
	else if (scene == "NO_MOTION_KITCHEN_NIGHT"){
		var String  str = kitchen_colour_proxy.previousState.state.toString()
		logInfo("kitchen_motion", "previous state: " + kitchen_colour_proxy.previousState().state.toString())
		var String[] parts
...

Well, I am more confused now :slight_smile:

Ok, I can see it does actually get the correct value back

20:36:18.563 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_scene changed from Ready to BED_ALL
20:36:18.580 [WARN ] [pse.smarthome.model.script.loggerName] - found previous state
20:36:18.622 [WARN ] [eclipse.smarthome.model.script.HHHHHH] - BED_ALL
20:36:18.693 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_Kitchen_color' received command 240,100,10
20:36:18.741 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_KitchenCupboards_Colour' received command 240,100,10
20:36:18.769 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_lantern_color' received command 240,100,10
20:36:18.824 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard1_color' received command 240,100,10
20:36:18.854 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard2_color' received command 240,100,10
20:36:18.882 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard3_color' received command 240,100,10
20:36:18.915 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_colour_proxy' received command 240,100,10
20:36:18.938 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_KitchenCeiling' received command OFF
20:36:18.961 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_sw_Breakfast' received command OFF
20:36:18.982 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_sw_Main' received command OFF
20:36:19.003 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_BackHouse' received command OFF
20:36:19.024 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_lantern_color changed from 0,58,94 to 240,100,10
20:36:19.048 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard3_color changed from 0,58,94 to 240,100,10
20:36:19.073 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard1_color changed from 0,58,94 to 240,100,10
20:36:19.098 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from 240,100,10 to UNDEF through g_KitchenCupboards_Colour
20:36:19.133 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from 0,58,94 to UNDEF through kitchen_led_cupboard1_color
20:36:19.160 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from 240,100,10 to UNDEF through kitchen_led_cupboard2_color
20:36:19.189 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard2_color changed from 0,58,94 to 240,100,10
20:36:19.216 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_colour_proxy changed from 0,58,94 to 240,100,10
20:36:19.240 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from UNDEF to 240,100,10 through kitchen_led_cupboard3_color
20:36:19.267 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from UNDEF to 240,100,10 through g_KitchenCupboards_Colour
...snip...
20:36:23.568 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_scene' received command BED_ALL
20:36:30.771 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_scene' received command MOTION_KITCHEN_NIGHT
20:36:30.801 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_scene changed from BED_ALL to MOTION_KITCHEN_NIGHT
20:36:30.891 [WARN ] [pse.smarthome.model.script.loggerName] - found previous state
20:36:30.910 [WARN ] [eclipse.smarthome.model.script.HHHHHH] - MOTION_KITCHEN_NIGHT
20:36:30.966 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_Kitchen_color' received command 240,100,100
20:36:31.010 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_KitchenCupboards_Colour' received command 240,100,100
20:36:31.043 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_lantern_color' received command 240,100,100
20:36:31.077 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_colour_proxy' received command 240,100,100
20:36:31.108 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard1_color' received command 240,100,100
20:36:31.137 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard2_color' received command 240,100,100
20:36:31.164 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from 240,100,100 to UNDEF through g_KitchenCupboards_Colour
20:36:31.189 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard3_color' received command 240,100,100
20:36:31.212 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_colour_proxy changed from 240,100,10 to 240,100,100
20:36:31.236 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_lantern_color changed from 240,100,10 to 240,100,100
20:36:31.367 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard1_color changed from 240,100,10 to 240,100,100
20:36:31.391 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from UNDEF to 240,100,100 through kitchen_colour_proxy
20:36:31.440 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from 240,100,100 to UNDEF through kitchen_led_cupboard1_color
20:36:31.475 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from 240,100,100 to UNDEF through g_KitchenCupboards_Colour
20:36:31.504 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from UNDEF to 240,100,100 through kitchen_led_cupboard3_color
20:36:31.540 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard2_color changed from 240,100,10 to 240,100,100
20:36:31.582 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard3_color changed from 240,100,10 to 240,100,100
20:36:31.611 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from UNDEF to 240,100,100 through g_KitchenCupboards_Colour
20:36:37.465 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_scene' received command NO_MOTION_KITCHEN_NIGHT
20:36:37.510 [WARN ] [pse.smarthome.model.script.loggerName] - found previous state
20:36:37.512 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_scene changed from MOTION_KITCHEN_NIGHT to NO_MOTION_KITCHEN_NIGHT
20:36:37.550 [WARN ] [eclipse.smarthome.model.script.HHHHHH] - NO_MOTION_KITCHEN_NIGHT
20:36:37.602 [INFO ] [smarthome.model.script.kitchen_motion] - Kitchen previous state: 240,100,100
20:36:37.651 [INFO ] [smarthome.model.script.kitchen_motion] - str previous state: 240,100,100
20:36:37.710 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_Kitchen_color' received command 0,58,94
20:36:37.744 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'g_KitchenCupboards_Colour' received command 0,58,94
20:36:37.772 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_lantern_color' received command 0,58,94
20:36:37.805 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_colour_proxy' received command 0,58,94
20:36:37.846 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard1_color' received command 0,58,94
20:36:37.878 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard2_color' received command 0,58,94
20:36:37.908 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'kitchen_led_cupboard3_color' received command 0,58,94
20:36:37.932 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_lantern_color changed from 240,100,100 to 0,58,94
20:36:37.958 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from 0,58,94 to UNDEF through kitchen_led_lantern_color
20:36:37.986 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard1_color changed from 240,100,100 to 0,58,94
20:36:38.011 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from 0,58,94 to UNDEF through kitchen_led_cupboard1_color
20:36:38.038 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard3_color changed from 240,100,100 to 0,58,94
20:36:38.063 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_colour_proxy changed from 240,100,100 to 0,58,94
20:36:38.087 [INFO ] [smarthome.event.ItemStateChangedEvent] - kitchen_led_cupboard2_color changed from 240,100,100 to 0,58,94
20:36:38.114 [INFO ] [home.event.GroupItemStateChangedEvent] - g_KitchenCupboards_Colour changed from UNDEF to 0,58,94 through kitchen_led_cupboard2_color
20:36:38.141 [INFO ] [home.event.GroupItemStateChangedEvent] - g_Kitchen_color changed from UNDEF to 0,58,94 through g_KitchenCupboards_Colour

if I telnet into the LED controller and check what it receives it gets things in order.

BED >> [MQTT] Received home/lights/kitchen/led/cupboard/LED_KITCHEN_CUPBOARD_1/hsv/set => 240,100,10

MOTION >> Received home/lights/kitchen/led/cupboard/LED_KITCHEN_CUPBOARD_1/hsv/set => 240,100,100

NO MOTION >> [MQTT] Received home/lights/kitchen/led/cupboard/LED_KITCHEN_CUPBOARD_1/hsv/set => 0,58,94

That is what is being sent to the controller via mqtt, in order.

In the logs you can see this:

 g_Kitchen_color changed from 240,100,100 to UNDEF through g_KitchenCupboards_Colour

Line 18 and 37. Could it be because of a circular reference?
Still unsure as to where that colour comes from in the first place…

Well, that’s silly…

I am recording the value in hsb and then for some reason I was trying to recreate it in rgb… Doh!

now I’m confused! :wink: is it solved already?
if not - did you place some debug-information with logInfo() to gather more Information on your rule?

Yup - solved…

The persistence is is saving the value as hsb (240,100,100) and previousState returns that.
I was - for reasons I don’t know :blush: know converting those to rgb and setting it like that.

I was mashing it up… :frowning:

1 Like