[SOLVED] Need help in HTTP binding with dimmer

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

And Items.

Dimmer Led_R “Red” (FF_Nishit, Lights){http=">[*:GET:http://192.168.0.108:5000/red3/%2$s]"}

I am not getting any response on my server, what are the changes I need to make?

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

it does end in an infinite loop

Best regards,

George

George,
How should I change it?

Why not using this as @rlkoshak himself already laid as a suggestion. I do think he nailed it!

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)

Dimmer Led_R	"Red"	(FF_Nishit, Lights){http=">[*:GET:http://192.168.0.108:5000/red3/%2$s]"}

Rich,
What should I do to avoid looping?

As the Link says:

  1. create a proxy Item
  2. put the Proxy Item on your sitemap
  3. trigger your rule by the Proxy Item
  4. in the rule, send the new state to your HTTP Item.
1 Like

I guess the proxy item and bounding items are just the names and can be named as anything else, Am I right?

Dear @Nishit,

I hope you are doing well! As rude as I may seem, I will not apologize: I already pointed you, how to do it!!!

Best regards,
George

Dear Rich,

You’re a peach!!!

It rhymes coincidentally!

George

1 Like

You can name any Item anything you want.

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.

1 Like

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

and items settings:

Dimmer Led_B   "Blue"   (FF_Nishit, Lights){http=">[*:GET:http://192.168.0.108:5000/blue3/?d=%2$s]"}

can you suggest anything here?

Spreading your problem over two threads is not helping

Try the suggestion to add some formatting in the Item label

It’s not all clear to me where the binding gets the ‘format’ string that %2 is supposed to refer to

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.

I haven’t checked the version of the binding, but I installed it through the paper UI, so I guess it should be the latest version.

I checked the version of my binding, it is 1.9.0