Use of DMX item state in a IF function

I’ve got a question, is it possible to check DMX (2.x binding) item states in a rule?
I can’t get it to work.

Example of my problem:


Bridge dmx:sacn-bridge:mybridge [ mode="unicast", address="", universe=2 ] {
 color  rgb    [dmxid="1/3", fadetime=1000, dimtime=10000 ]
 chaser rgb_preset  [dmxid="1/3", steps="100:255,0,0:-1" ] 

I have a “color” thing to change the color and I have a “chaser” thing (on the same DMX channels) to set a preset color in the RGB strip.


Color MyColorItem "My Color Item" { channel="dmx:color:mybridge:rgb:color" }
Switch MyChaserItem "My Chaser Item" { channel="dmx:chaser:mybridge:rgb_preset:switch" }

my initial rule:

rule "DMX preset on"
   Time is midnight

This work fine, but when the LED strip is already on (for example by the colorwheel) then the preset has not to be set on the LED strip. so I change the rule to:

rule "DMX preset on"
   Time is midnight
   if (MyColorItem.state == OFF) MyChaserItem.sendCommand(ON)

But this is not working, LEDs are off and the preset is not set on the LED strips.
Is this the wrong way to do this? Is the state of all the different things/items changing when I change one of them? (chaser and color are using the same DMX channels, when the chaser item is ON, is also the color item ON???)
Or do I need to use the things ans not the Items???

Switch types have ON/OFF states. Color Items do not, as I understand they are essentially a set of three numbers representing RGB values.

I’m not sure what values you might expect the Color Item to have, but you can test those in a rule.

You can do this but there is a special way. ColorItems can receive ON/OFF commands, but they store their state as an HSBType.

So if you want to check if a ColorItem is ON, you either need to look at the HSBType directly (i.e. if it isn’t 0,0,0 the light is ON) or you can use the following:

if(MyColorItem.getStateAs(OnOffType) == ON)

Similarly, if you want to check just the brightness you can use:

if(MyColorItem.getStateAs(PercentType) > 50)

thank you, the:

if(MyColorItem.getStateAs(OnOffType) == ON)

seems to work perfect.

I indeed use the .state == OFF because it worked to send ON OFF states to the color item.

where can I find info/solutions/work-arounds like MyColorItem.getStateAs(OnOffType)? (is there a good website about it?) and why is this not standard in the binding?

Because it has nothing to do with the binding. It is a core OH thing. And I could go into a really long explanation about how Object Oriented Programming works and inheritence and a bunch of complicated explanation. But instead you will have to trust me, making is so you can use if(MyColorItem.state == ON) would be a good deal of work and no one has volunteered to do so.

It depends on the problem. You can look in the docs where most of the stuff it captured about how OH works. You can look at this forum for examples. The DP postings are particularly useful. And you can look at the source code.

I don’t think getStateAs is an official part of what is expected to be used from Rules so I don’t think it has been written up in the docs yet.

For type conversions, the best place is Cheap Bluetooth antenna with raspberry pi zero