Thank you for your help, @rlkoshak and @ubeaut !
I just recently started with OH. And with rules just a couple of days ago (until now I used node red), so I appreciate your support and you may better understand the following (which otherwise might seem quite stupid, my recent experiences with OH sure make me feel that way…)
- I didn’t know so far that I can refer to an item with an expression like items[“LeuchteHuegross_Farbe”]; it’s certainly more easier to read. Are there other advantages (like speed)?
- the conversion to string helped, something like this basically seems to work (at least once, see later):
var testx = itemRegistry.getItem("LeuchteHuegross_Farbe").getState().toString().split(",");
testx = testx[2]; // <-- works
events.sendCommand("v_string",testx); //<-- works - and then again, it doesnt any more
- the .getBrightness()-function should be the ideal version for what I want to do, but so far I didn’t get that running which leads to the core of my problem
I seem to have a fundamental problem with my OH-installation (tried to describe it here: OH freezing - until reboot - #3 by Ursusprimus); one of the problems is, that OH seems to break but I don’t notice immediately. Probably because it still runs in the browser. So I do some coding and wonder why nothing happens with the addressed-items, thinking I made a mistake. After a while I check (by now I got used to it and to it regularly) by trying to open OH in another tab, when it’s not opening, I reboot and then at least I can continue. But as it takes some minutes, it’s quite annoying/frustrating …
However, with some of my rules (as above) a reboot doesn’t help so I thought it must be a problem of the code. Strangely, it sometimes (at least once, as written above) it changed the item, later it didn’t any more. Not even after a reboot. This leaves me somewhat confused/irritated.
As of how to find if an item has changed, I see these options/problems:
- developer sidebar: Pinned objects (doesn’t update regularly); code tools with “=items.name.state” (doesn’t seem to be updating regularly either)
- looking at the item in settings/items/ ← quite cumbersome but here at least I notice when the window doesn’t update that I might have to reboot, so that’s what I’m doing at the moment.
- karaf console (new to me, checked it because you mentioned “logger”): openhab:status itemname
- maybe tailgate (:9001)
So I have a combination of a fundamental problem (OH-not working like it should), a concrete problem (it value not changing consistently) and a lack of experience/knowledge (programming and error-finding).
To clarify things, here some screenshots.
- Using OH, I set the lamps brightness to 83 (which worked on the lightbulb and the item):
- trying the code doesn’t update v_string regularly (it sometimes does, right now it doesn’t, even after reboot; tried several versions, now as //comment)
Here the definition of v_string:
anzahl = 0;
//var testx = items["LeuchteHuegross_Farbe"] //<-- works as a replacement for item.Registry
var testx = itemRegistry.getItem("LeuchteHuegross_Farbe").getState().toString().split(",");
testx = testx[2]; // <-- works
events.sendCommand("v_string",testx); //<-- works - and then again, it doesnt any more
//var testx=items["LeuchteHuegross_Farbe"].getBrightness(); //doesnt seem to work, strange? - maybe it would work
//testx = itemRegistry.getItem("LeuchteHuegross_Farbe").getBrightness(); /doesnt work either
//events.sendCommand("v_string",testx);
/* don't know where/how to find logger info -- not in fronttail (:9001) and in karaf console I don't know the command to see the output of "info"
var test = itemRegistry.getItem("LeuchteHuegross_Farbe").getState().toString().split(",");
logger.info("Test " + test);
logger.info("Test0" + test[0]);
logger.info("Test1" + test[1]);
logger.info("Test2" + test[2]);
I’m not sure where to see the logger info:
- karaf console? which command to access this?
- tailgate? didn’t find anything related when filtering for test:
And two last screenshots showing different values:
Maybe you have an idea what I could try …