[Question] SendCommand only if update is significantly different?

Use case: Sync colors; I’m trying to create a rule where if color of one LIFX light updates, apply the same color to an LED strip. LED strip may individually get color update, in which case, do not change the LIFX color. (Unidirectional). LED strip is based on Hyperion, and I’m using Hyperion binding via JAR file.

Problem: I’m running the rule as below. The rule works fine, but it triggers the rule every 3 seconds (polling interval of LIFX) and sends update to LED strip every 3 seconds irrespective of whether the color has changed significantly or not. Also, due to some reason, LIFX would usually get small updates to the color when using HSBType (equal to very small fractions) which would trigger the rule occasionally anyway.

Help Needed: How do I build a rule where SendCommand is executed if and only if the color as HSBType changes significantly on “received update” ( > 1 integer value for any of red, green or blue)? I’m new to development, so please help me with import part of rules file as well.

Rule so far: (please see the comments below)

rule "scene for lights in living room update"
when
	Item lifx_colorlight_yyyyyyyy_color received update
then
	{
	var color_value = lifx_colorlight_yyyyyyyy_color.state as HSBType
// Need something here that does if(Math::abs(color_value_new - color_value) > 0.9 then
	sendCommand(hyperion_serverV1_xxxxxxxx_color,color_value)
// Need something here that does var color_value_new = hyperion_serverV1_xxxxxxxx_color
	}

Help would be much appreciated. Thank you.

Did you try changed instead of received update?

That was my next step. It fixed the first part of the problem: sending every 3 seconds stopped. But I’ll still have to find something that allows me to ignore small changes to the color that send a command anyway.

executed if and only if the color as HSBType changes significantly on “received update” ( > 1 integer value for any of red, green or blue)

You can setup another variable/item to hold the previous value. Your evaluation would compare lifx_colorlight_yyyyyyyy_color to that variable/item (lifx_OldColor).

Then after your if/then evaluation, you would update the previous value with the current value that triggered your rule:

lifx_OldColor == lifx_colorlight_yyyyyyyy_color.state

It’s important that you update the previous value after you do the evaluation, or else you will be comparing the same value. This is pseudo code, but I think you get the idea.

The first step would be to get the previousState. This var is set when the rule was triggered by changed, so we already have it. As the item which triggered the rule is an color item, you will have to split the state to different values, either HSB or RGB. This has to be done for previousState and for Item.state. Please take a look at Example: Convert Color Item Values To RGB (With Explanation).
From this point, I think, it’s a simple task…