Temperature Setpoint

I have defined the following string item to control a pellet stove

Questions:

  1. Is it possible to limit the range to a certain interval ?
  2. Is it possible to specify steps of 0.5 instead of 1.0 ?

Note: I can change the itemtype to number:temperature if needed. Currently it is defined as string to avoid conversions when I send the command string to the device (using http binding).

Hi Hugo,
This should be quite easy. In ā€˜settingsā€™ ā†’ ā€˜itemsā€™ select in the search bar your item.

Add meta data and select default list item. Then choose as widget ā€˜stepper list itemā€™.

Now select in your item underneath ā€˜Metadataā€™ the ā€˜default list item widgetā€™ (which should refer to ā€˜oh-stepper-itemā€™). Now you can edit ā€˜minā€™, ā€˜maxā€™ and ā€˜stepā€™.

Hope this helps.

By the way: in my setup I set the item to ā€˜number:temperatureā€™. Maybe this is an issue in your definition if above isnā€™t working.

1 Like

Iā€™ve defined a new number:temperature item to test and Iā€™ve followed your instructions. But they seem to have no effect.

Iā€™m on OH 4.1.1 using Firefox. Could this be a bug ?

I just checked and I also have ā€˜state descriptionā€™ set. Just ā€˜add metadataā€™ ā†’ ā€˜state descriptionā€™ and also set here the min/max/step and donā€™t forget to set the pattern to ā€˜%0.1fā€™. Then save but also go back to the item overview. Somehow you need to do this before this is activated.

If you now select the item (search bar) you should be able to have a stepping setpoint.

In short:

  • define item als ā€˜temperature:setpointā€™,
  • set semantic class as setpoint and semantic property as temperature
  • set state description
  • set default list item widget

and then magic should happen. :slight_smile:
Iā€™m on 4.0.2 and waiting to go to 4.1.1 (probably next weekend). If this is a bug (I donā€™t think so however), I am curious to know.

What did the trick, apart from your suggestion of specifying the state description, was removing the old item and creating a new one. Updating the old item did not work (maybe a OH 4.1.1 bug).

Now I have another problem (Iā€™m afraid Iā€™m not a java expert) ā†’ I use this JS script transformation to send the command to the device:

(function(i) {
    var resultado = "idOperacion=1019&temperatura=" + i;
    return resultado.trim();
})(input)

It worked when i was a string (only one decimal is allowed, and 20 should be sent as 20.0). Now itā€™s a number:temperature and probably I need some sort of conversion.

Hi Hugo,

Glad I could help. Howeverā€¦ here I have no experience. Maybe someone else?

What type of binding is this? If itā€™s MQTT you can use the ā€œoutgoing value formatā€ instead of a transformation.

idOperacion=1019&temperatura=%.1f

If not, see the toFixed() method on numbers. Parse I into a float and use toFixed() website it has one decimal place.

Thanks Rich. Itā€™s the HTTP binding. Iā€™ve tried

  - id: temp_obj
    channelTypeUID: http:string
    label: Set Temperature
    description: null
    configuration:
      mode: READWRITE
      stateContent: idOperacion=1002
      commandTransformation: idOperacion=1019&temperatura=%.1f
      stateExtension: /recepcion_datos_4.cgi
      commandExtension: /recepcion_datos_4.cgi
      stateTransformation: JS:getEcoforestTempObj.js

but I get

2024-01-14 18:26:53.244 [WARN ] [ransform.CascadedValueTransformation] - Transformation ignored, failed to parse idOperacion=1019&temperatura=%.1f: The transformation pattern must consist of the type and the pattern separated by a colon

Not transformation, ā€œoutgoing value formatā€, which http doesnā€™t support.

Are you spending this as arguments to the URL? Then use HTTP - Bindings | openHAB

Thanks, but as Iā€™m using the POST method it does not work that way.

This code works when the item is defined as string:

Thing definition

channels:
  - id: temp_obj
    channelTypeUID: http:string
    label: Set Temperature
    description: null
    configuration:
      mode: READWRITE
      stateContent: idOperacion=1002
      commandTransformation: JS:cmdEcoforestTempObj.js
      stateExtension: /recepcion_datos_4.cgi
      commandExtension: /recepcion_datos_4.cgi
      stateTransformation: JS:getEcoforestTempObj.js

cmdEcoforestTempObj.js

(function(i) {
    var resultado = "idOperacion=1019&temperatura=" + i;
    return resultado.trim();
})(input)

getEcoforestTempObj.js

(function(i) {
    var array = i.split("\n");
    if (array.length > 6) {return array[6].split("=")[1];}
})(input)

If I define the item as number:temperature, I get the actual value from the device but I cannot set it. I would prefer to define the item as number:temperature, but if I canā€™t transmit the desired value to the device I will keep the item as string.

The problem is this line of code var resultado = "idOperacion=1019&temperatura=" + i;. i is a string when the item is string, but is something else when the item is number:temperature, and in this case needs to be converted to a string.

Hi Hugo, I have some NodeRed scripts running, but, as mentioned, no OH js experience. In NodeRed it can be done converting to string by appending toString(). So it would be i.toString() . You could try this, but else I am out of ideas.

1 Like

Iā€™ve tried this and failed.

Right. input is always going to be a String in a transformation.

So first you need to parse the String to a number:

var num = parseFloat(i);

And then use toFixed(), like I mentioned above, to limit it to one decimal placeā€¦

return ā€œidOperacion =1019&temperatura=ā€+ num.toFixed(1);

(function(i) {
  var num = parseFloat(i);
  return "idOperacion=1019&temperatura-"_num.toFixed(1);
})(input)
1 Like

Nice try, but still does not work. How can I log the value of i upon entry to the function ?

Does not work how? Those three words encompass an infinity of possibilities. Errors in the log?

Same as in a rule. You have full access to everything in the Helper Library even in a transformation .

console.log(i);
1 Like

Thank you very much. I know that you chase issues until they are solved, and Iā€™m happy that now it is solved.

The key was when you told me to use console.log(i); this allowed me to make several tests, and the conclusion is:

  1. If, in the http binding, the channel is defined as http:string, this implies that the item must be a string type
  2. but if the channel is defined as http:number, the item can be number:temperature.

I was linking a http:string channel to a number:temperature item and the cmdEcoforestTempObj.js was not event called. Iā€™ve corrected it now in my code.

1 Like