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?
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:
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:
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
@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