I recently started working on translating my old DSL rules to Jython. So far, I have managed to get most things working through trial and error and the documentation (the community has put in a huge amount of work).
Some things are missing though (or I couldn’t find the right pages).
I have a Color item (let’s say test_color) and a String item (let’s say test_string).
When the item test_string receives a command like “240,105,80”, it used to be split into an array and then an HSBType object was created and used as state for a postUpdate command to test_color.
The postUpdate command fails, saying that it can’t coerce the 1st argument to item or string (I have also tried events.postUpdate(items[“test_color”], HSBvalue) but I get the same problem.
test_color is an HSBType. How can I update it (or send a command to it)?
First of all, thanks! That did it. I It makes no sense to me (converting a complex object to string), but it works, so…
I was betting on the angle of events.postUpdate(Item, State), where State would be an HSBType object.
I found a lot of info on jrs223, like a very detailed installation guide and some simple examples, as well as a “shallow” reference of the objects on the page you sent. There’s also a helpful guide by @rlkoshak. Granted, much more is needed, but I wanted to acknowledge the work that was already put in.
But what you used was events.postUpdate(string, ... and if the first argument is a string, then postUpdate expects the second to be a string as well. It’s just the way postUpdate works.
Given that the incoming command is a String of the format “H,S,B” and the toString() of an HSBType is a String of the format “H,S,B” and events.postUpdate() requires the second argument to be a String, you don’t even need to parse the String and create the HSBType. The whole Rule could be:
items["test_color"] gives you the State of the Item test_color, not the Item itself. If you want the Item itself you need to pull it from the Item Registry.
Actually, I don’t think that would work in this case. The command is an “RGB” string and I need to send an “HSB” string. Also, I’m normalising the values, because of the dirt-cheap LEDs that I have around the house
Thanks for clearing up the difference between item[…] and ir.getItem[…]. I was confused about that, too.