toCharArray (SOLVED)

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

I have been trying to get the ToCharArray function to work in an OpenHAB rule but for some reason I am getting the following error.

18:09:43.583 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Update KP’: ‘ToCharArray’ is not a member of ‘org.eclipse.smarthome.core.library.items.StringItem’; line 9, column 11, length 22

I have seen other users post that they’ve used this function but can’t figure out why I am getting this error. I am looking to use it to decode a binary response from my legacy lighting system.

What are your items and rules definitions?

This is what I had up to as I was programming and debugging as I went along.

String KP <light_bulb> (SFloor_Study, Lights)

rule "Update KP"
Item KP changed
var Char[] BinArray;

A rule updates KP which triggers this rule. In Visual Studio Code I don’t see ToCharArray show up when I type KP.

Any reason why you don’t just have :
var Char [] BinArray=KP.toCharArray();

Regardless, notice also the lowercase T. That might help.

Since you are working with an item, you will also need to get it’s state first…


I tried both

var Char [] BinArray=KP.toCharArray();
var Char[] BinArray=KP.state.toCharArray();

but still received the same error message. For whatever reason, my setup is not recognizing the toCharArray java function. I debugged and show that KP.state is indeed a 24 character binary string but I have not found a solution to extracting the digits by position. If anyone has another solution without going the toCharArray route, I am willing to look into it.

So… you want to decode a binary response from your lighting system. In stead of trying to get ToCharArray to work, perhaps you could share what you are trying to decode and what states you are looking for. It could be that someone have an alternative solution? :slight_smile:

Notwithstanding @MartinKo’s question, which I think is a good idea…

You could try

var char[] BinArray=KP.state.toString.toCharArray

Thanks everyone for the help. Mark’s suggestion seems to be the winning one. I guess OH is quite fickle when it comes to lower and upper case. This worked for me.

var char[] BinArray=KP.state.toString.toCharArray

1 Like