Dear All,
I want to send the value of dimmer to my http server via http binding,
Here are my current rules and items settings
Rules:
Rule “RED LED”
when
Item Led_R received command
then
var Number b = 0
if(Led_R.state instanceof DecimalType) b = Led_R.state as DecimalType
if(receivedCommand==INCREASE) b = b + 10
if(receivedCommand==DECREASE) b = b - 10
if(b<0) b = 0
if(b>100) b = 100
sendCommand(Led_R, b)
end
Please use code fences. The fifth icon from the right will insert code fences in your post and you put your code between them. this leaves your code properly indented and syntax highlighted.
It is a bit more intuitive to instead check for NULL. Also, you will have fewer problems if you cast the state to a Number rather than DecimalType. Number plays better with calculations and the like.:
if(Led_R.state != NULL) b = Led_R.state as Number
It is usually better to use the method rather than the Action.
Led_R.sendCommand(b)
OK. The first problem I see is this will enter an infinite loop. Led_R receives a command, you calculate a new value, then you send a command to Led_R which triggers the rule again and so on forever.
Rich,
Yes it enters in an infinite loop and loads the cpu of Raspberry pi up to 90%, so what should I change there?
And What about Item setting? are they ok?
Hi,
As stated by @rlkoshak, the loop is obvious!
To conclude: [quote=“Nishit, post:1, topic:30678”]
Rule “RED LED”
when
Item Led_R received command
[/quote]
and then changing the Led_R state in the same rule
George,
I read that thread, and understood the example of dimmer, but how should I send that value of variable via http binding?
Are my item setting for it OK??(Just the binding part, as I would add a proxy item with it)
You said at one point, if I remember correctly, that you have been using OH 1 for some time. Your questions make we wonder if you do not have as much experience as needed.
I recommend reading the Beginner’s Tutorial, if you truely have experience with Oh 1, the Migration Tutorial, and the Introduction and Concepts sections of the Manual. You might also get some benefit by activating the demo and looking at the demo configs.
There is clearly a disconnect between your experience and knowledge of how OH works and my expectations of what you should know as someone who has used OH 1 for some time.
Now, if I’m wrong and it was someone else who said that then I apologize. Regardless you should read the above resources.
Yes,
I have used OH1 in past, but then due to hardware failure I had to concentrate on learning linux and python so I lost the command over OH, but I will read your suggestions, thanks for the help.
Rich,
I tried some rules,
but with my current settings of rules and items, the http binding sends the whole link like this ‘192.168.0.108:5000/red3/?d=%2$s’
where as it should send the value sent by the rule/ the python script returns: 'could not convert string to float’
Here are my rules settings:
rule "blue led"
when
Item Led_B received command
then
if (receivedCommand == DECERASE){
Led_B.sendCommand((Led_B.state as DecimalType) - 5)
}
else if (receivedCommand == INCREASE){
Led_B.sendCommand((Led_B.state as DecimalType) + 5)
}
end
Rossoko,
I also tried udo’s suggestion, but I only get the value update in the sitemap(in UI app), but the same value is not transmitted to my http server.
What binding version are you using? Dimmer type support in the binding only appeared in Nov 2016. I do not know which OH versions that will have got into.