How to transfor a value in binding configuration

Hi all,

The dimmer of my home domotic system accepts and returns value between 0 and 255. I created two transformation maps

  • dimmerin.map (0=0 … 100=255)
  • dimmerout.map (0=0 … 255=100)

This item definition works to set the dimmer and to retrieve the correct output. However to function correctly I should convert the input argument %2$s with the dimmerin.map. Does somebody know how this can be done?

Dimmer DE_Bureau "Dimmer"  (gE_Bureau) {http=">[*:GET:http://localhost:8888/icontrol.dll?ccmd=dim.1.out1.set.%2$s.3] <[http://localhost:8888/icontrol.dll?ccmd=dim.1.out1&terse:10000:MAP(dimmerout.map)]"}

Why I have to use the second argument (%2$s) is a mistery to me but this is less important (I copied this from an example and it works).

Thx, Jan

First of all, it would have been a lot more efficient use of your time to use a JS transform along the lines of:

(function(i) {
    return Math.round(255/i)   
})(input)

As far as I can tell this cannot be done inline in your Item definition. You will probably need to create a Proxy Item to represent this Dimmer and separate the incoming and outgoing parts along these lines:

Dimmer DE_Bureau "Dimmer" (gE_Bureau)
Dimmer DE_Bureau_Input { http="<[http://localhost:8888/icontrol.dll?ccmd=dim.1.out1&terse:10000:MAP(dimmerout.map)]" }
Dimmer DE_Bureau_Output
rule "DE_Bureau received command"
when
    Item DE_Bureau received command
then
    val value = Math::round(255 * DE_Bureau.state as Number)
    sendHttpGetRequest("http://localhost:8888/icontrol.dll?ccmd=dim.1.out1.set." + value.toString+".3")
end

rule "DE_Bureau_Input changed"
when
    Item DE_Bureau_Input changed
then
    DE_Bureau.postUpdate(DE_Bureau.state as Number)
end

It is always to check the docs when you have a mystery like this. It’s always a great place to look for all your binding related questions.

The binding currently adds these parameters to the String.format() automatically:

  1. the current date (as java.util.Date)
  2. the current Command or State
1 Like

Hi Rich,

Tried to copy your example but no success (it’s the first time I create a rules file). It seems that there is a syntax error in the rules file but my knowledge is too limited. I would also expect to have to Multiply by 255/100 i.s.o. 255, but this doesn’t solve the syntax problem.

import java.lang.Math

rule "DE_Bureau received command"
when
    Item DE_Bureau received command
then
    val value = Math::round(255 * DE_Bureau.state as Number)
    sendHttpGetRequest("http://localhost:8888/icontrol.dll?ccmd=dim.1.out1.set." + value.toString + ".3")
end

rule "DE_Bureau_Input changed"
when
    Item DE_Bureau_Input changed
then
    DE_Bureau.postUpdate(DE_Bureau.state as Number)
end

Resutls in following errors in log file

2017-09-16 10:57:48.701 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'Oude67.rules'
2017-09-16 10:57:48.725 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Oude67.rules' is either empty or cannot be parsed correctly!
2017-09-16 10:57:50.314 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Oude67.rules'
2017-09-16 11:08:31.490 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'Oude67.rules'
2017-09-16 11:08:31.501 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Oude67.rules' is either empty or cannot be parsed correctly!
2017-09-16 11:08:32.954 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Oude67.rules'

I made the transformation maps with Excel so this didn’t took so much time. Your solution is much nicer though. I’ll try to copy it :slight_smile:

Thx, Jan

@Jan_Mechelen these errors are an artefact; they especially occur when you use samba to edit the files. The reason was explained elsewhere in this forum, essentially, the openHAB tries to access the files when they are still written, which results in the error. However, and this is the critical part, openHAB loads the files again when the writing process ended, and this is the line that just say loaded. So you can ignore the “files is empty or cannot be parsed correctly” if it is followed by “loading model…” without any error.
Hope that helps