Accessing historicstate of ColorItem not working

openHAB version: 3.2.0

Issue:
I’m looking to create a absence simulation in OH3. Since the precense add on is not available anymore, I just tried by running a rule every 2 minutes, accessing the data of certain items and update the item.
This works perfectly for dimmer, switch and player items. But for color items, no way:
This is may definition:

gPrecenseColoredLights.members.forEach[myitem | 
  myitem.sendCommand(myitem.historicState(now.minusDays(7)).state.toString)
  logInfo(myRuleName,"Abwesenheitssimulation: Das Item <" + myitem.name.toString + "> wurde auf den Wert <" + myitem.historicState(now.minusDays(7)).state.toString + "> gesetzt")
]

The group contains ColorItems where every state change is persisted in a MariaDB.
When running this query, I get the follow error in the logs:

Error: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')

Any idea what to do to make the absence simulation working also for ColorItems?

Thanks Martin

Not all the Item types are persisted by all the persistence services.
You’ve asked for a historicState from your default persistence - which is that?

If you don’t know, it is probably rrd4j.
From docs -

NOTE: rrd4j is for storing numerical data only. It cannot store complex data types. … and Color (only brightness component stored).

so you might expect to only get a single numeric (brightness).

@rossko57

I’m using JDBC with a MariaDB as database.
I just checked the db and the values are in

This is a system setting, if you don’t specify the service to look at, it looks at the default service, not the one you wish it looked at.
-or-
Tell historicState where to look.

The MariaDB is the default one, and even if I explicitly specify the persistence service, this does not work.
And as it works for all the other items where I defined it the same way, I bet it is related to the type ColorItem and the way the values are persisted.

I have the feeling that this could be a bug, as the values are save as string in the database. Looking to the error message it seems that the service tries to do an automatic type conversation to number, because the value starts with somewhat like 20,100,100 and crash once the comma occurs.
But this is just a feeling, I cannot prove it.

Bye Martin

Might well be. The (fairly recently introduced) code that recovers brightness-only value from rrd4j might be accidentally invoked here too.

Well, you seem to have shown the color state gets persisted in full “20,100,100” ?
If
myitem.historicState(now.minusDays(7), "jdbc").state.toString
either breaks or does not return a color state in 20,100,100 format, then it’s broke.

Ok, so I checked the database table with

SHOW COLUMNS FROM item0052;

which returns the following output where item0052 is the database table for the item

Color Light_Hue01_ColoredLED "Office" {channel="hue:0210:ecb5fa850581:3:color"}
|time|timestamp(3)|NO|PRI|current_timestamp(3)|on update current_timestamp(3)|
|---|---|---|---|---|---|
|value|varchar(70)|YES||NULL||

The values in the table are those, e.g.

time                    value
2021-11-09 16:09:25.247	286.1795997619629,36.780136823654175,100.0
2021-11-09 16:09:28.248	285,36,100
2021-11-09 16:09:44.250	285,36,0
2021-11-09 16:09:48.180	285,36,100
2021-11-09 16:10:36.630	285,36,0
2021-11-09 16:10:39.877	285,36,100

Using the statement

myitem.historicState(now.minusDays(7), "jdbc").state.toString

returns the error

Error: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')

For me this is the fact, that the values are not correctly persisted as eigher String or HSBValue.
I guess I should create an issue for this, should I?

Bye Martin

I think so; your database persists color state, but persistence service cannot retrieve it.