Mapping a string item to a number so it can be graphed

What is the correct way to map a String that is returned from a channel binding to a number, so that it can be graphed?

I have a binding where the underlying value is a String

String TeslaNumberState “nState [MAP(]” {channel=“tesla:models:1:state”}

The map file is simply:


But this keeps the value as a String. Ideally I would like to transform it to a Number and not a String, so that it can be persisted and graphed by rrd4j. I don’t see any easy way to do this.


First create a new “Dummy-Item”.


Number TeslaState_num           "Tesla State as Number[%s]"     

an then create a Rule to make the Transformation.


rule "Tesla State String to Number"
    Item TeslaNumberState changed
  if (TeslaNumberState.state == "online"){
    TeslaState_num.postUpdate (2)
   if (TeslaNumberState.state == "asleep"){
    TeslaState_num.postUpdate (0)

I didn’t test it, but I think it should work.

1 Like

That approach works for me.

I use almost exactly that rule layout.

OFF = 0

ON = 10

Thanks. I did something like that. I was just wondering if there was a way to do it without creating a rule to set a new variable.

Not really. As a String-Item is a String-Item and remains a String-Item. A Number-Item is a Num…:wink:


You’re reliant on the binding supplying channels suitable for Items of this type or that type. Some bindings provide many choices, some few/none.

The new profile feature allows some manipulation between channel and Item, but I do not think it (yet) provides for this kind of mapping or transformation.