Item Updates how does it works?

How does it work with the items?

I have an item which is an on/off switch of a lamp. With my Habpanel Dashboard the lamp can be switched on and off without any problems. When you click on the button, it always says On or Off.

If I now switch on the lamp manually on the lamp itself, how can I update the item that the button then changes to On.

Is there any way to define the query of the items? That you e.g. check the status every 5 minutes?

This is my Item.

Switch Lampe "Lampe" { http=">[ON:GET:http://192.168.2.133/relay?state=1] >[OFF:GET:http://192.168.2.133/relay?state=0]" }

Furthermore, sending the above httprequest also has a json response. How can I display the response on my Habpanel?

It’s all in there:

https://docs.openhab.org/addons/bindings/http1/readme.html

Receive repeated updates from a URL (“in” binding):

http="<[<url>:<refreshintervalinmilliseconds>:<transformationrule>]"

You can also use the JsonPath transformation, which allows a direct query of JSON data:

Number Weather_OutTemp "Value: [%.1f °C]" { http="<[http://weewx/now.json:60000:JSONPATH($.stats.current.outTemp)]" }

jsonpath.com is a handy tool to create the JSONPATH transformation.

1 Like

Awesome! It works almost.

This ist my Item.

String LampeWaste "LampeWaste" { http="<[http://192.168.2.133/report:3000:JS(getValue.js)]" }

This is my getValue.js File

JSON.parse(input).power;

But on my HabPanel I always get the Full Response and not only the power value.

{
	"power":	0,
	"relay":	false
}

What I’m doing wrong?

Replace JS(getValue.js
With JSONPATH($.power)

I did. But i still get the whole json repsonse.

String LampeWaste "LampeWaste" { http="<[http://192.168.2.133/report:3000:JSONPATH($.power)]" }

2018-04-04%2019_48_23-HABPanel

Sorry my fault. The jsonPath extension was not installed. :smiley: Now it works!!!

One more question.
I have now built my own widget for an on and off switch.

<div class="switch-content" style="background: #484747; padding: 5px 0 0 0; box-sizing:border-box;" >
	<div>Text</div>
  	<div class="value switch-off">
      <div>
      	<i style="font-size: 30px;" class="glyphicon glyphicon-off" ng-show="itemValue('LampeState') == 'false'" ng-click="sendCmd('Lampe', 'ON')"></i>
        <i style="font-size: 30px; color:#0db9f0;" class="glyphicon glyphicon-record" ng-show="itemValue('LampeState') == 'true'" ng-click="sendCmd('Lampe', 'OFF')"></i>
       </div>
      <div><span ng-show="itemValue('LampeState') == 'false'">OFF</span></div>
      <div><span style="color:#0db9f0;" ng-show="itemValue('LampeState') == 'true'">ON</span></div>
     </div>
</div>

2018-04-05%2016_02_35-HABPanel

If I now click on the button it takes 3 seconds until it changes to ON. That is clear, because I only query the status of the item every 3 seconds. However, there must be an event that directly displays the other status of the switch. Right?

<div class="switch-content" style="background: #484747; padding: 5px 0 0 0; box-sizing:border-box;" >
	<div>Text</div>
  	<div class="value switch-off">
      <div>
      	<i style="font-size: 30px;" class="glyphicon glyphicon-off" ng-show="itemValue('LampeState') == 'false'" ng-click="sendCmd('Lampe', 'ON')"></i>
        <i style="font-size: 30px; color:#0db9f0;" class="glyphicon glyphicon-record" ng-show="itemValue('LampeState') == 'true'" ng-click="sendCmd('Lampe', 'OFF')"></i>
       </div>
      <div><span ng-show="itemValue('Lampe') == 'false'">OFF</span></div>
      <div><span style="color:#0db9f0;" ng-show="itemValue('Lampe') == 'true'">ON</span></div>
     </div>
</div>

Unfortunately, it’s not the answer. Now the text ON OFF is simply no longer there. And after pressing the button it takes again until the colour of the button changes.

How about that?

<div class="switch-content" style="background: #484747; padding: 5px 0 0 0; box-sizing:border-box;" >
	<div>Text</div>
  	<div class="value switch-off">
      <div>
      	<i style="font-size: 30px;" class="glyphicon glyphicon-off" ng-show="itemValue('LampeState') == 'false'" ng-click="sendCmd('Lampe', 'ON')"></i>
        <i style="font-size: 30px; color:#0db9f0;" class="glyphicon glyphicon-record" ng-show="itemValue('LampeState') == 'true'" ng-click="sendCmd('Lampe', 'OFF')"></i>
       </div>
      <div><span ng-show="itemValue('Lampe')"></span></div>
      <div><span style="color:#0db9f0;" ng-show="itemValue('Lampe')"></span></div>
     </div>
</div>

No.

I want an immediate change when I click the button. It works with the 3 seconds waiting time. But I actually only installed this if the lamp is switched on manually and not via the dashboard. This way, the dashboard will still display ON even though it has not been turned on.

Unbenannt-1

And that are the items.

Switch Lampe "Lampe" { http=">[ON:GET:http://192.168.2.133/relay?state=1] >[OFF:GET:http://192.168.2.133/relay?state=0]" }

String LampeState "LampeState" { http="<[http://192.168.2.133/report:3000:JSONPATH($.relay)]" }