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