Integer conversion in commandExtension

Hi, I’m trying to send a http request with the http binding and I need to transform the command to a 3-digit integer:

baseURL: http://linhk.fritz.box:8000
commandExtension: pck?c=>M000005.R8M6%2$03d

But the integer conversion is not accepted:
[WARN ] [nding.http.internal.HttpThingHandler] - Creating request for 'http://linhk.fritz.box:8000/pck?c=>M000005.R8M6%2$03d' failed: d != java.lang.String

Am I doing something wrong or is the conversion to string a must? If the latter, is there an easy way to pad zeros to a string?

Thanks in advance!

All transformations return a String so if you’ve a command transformation then by the time you get to the commandExtension all you have is a String.

It’s not clear exactly what you are doing here so :person_shrugging:

What is the type of the Item?
What commands are sent to the Item?
What transformation is applied to the command?
Could you use a String Item with zero padded commands in the first place so no transformation or formatting is required in the first place? Maybe a Map transform to map what ever is sent to the Item to the zero padded number needed by the command extenstion.

Thanks.

The item is a Rollershutter type, so the command is a value designating the position of the rollershutter (I’m currently using a slider on the frontend). I also configured UP, DOWN and STOP but I wouldn’t need them if positioning through a value would work.

A string as return value of a transformation is exactly what I would expect as this is being appended to the URL. So my challenge is to cast a number between 0 and 100 to a string, eg. “027” or “004”.

UID: http:url:6e34a860a8
label: RollershutterMotorposition
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://linhk.fritz.box:8000
  delay: 0
  stateMethod: GET
  refresh: 30
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
channels:
  - id: Rollershutter1
    channelTypeUID: http:rollershutter
    label: Rollershutter
    description: ""
    configuration:
      stateExtension: replacestate?src=motorposition.json
      upValue: ZU
      escapedUrl: false
      commandExtension: pck?c=>M000005.R8M6%2$03d
      stateTransformation: JSONPATH:$.Module_11_Roll_Relais_78
      downValue: AU
      stopValue: ST

Use a command transform to add the zero padding.

In JS Scripting it would look something like this:

(function(input){
  var pad = "";
  if(input.length < 1)  return '000';
  if(input.length == 1) return '00' + input;
  if(input.length == 2) return '0'+ input;
  return input;
})(input)

I’m certain there are more clever ways to go about it but this is simple enough.

1 Like