openhab / openhab-android

openHAB client for Android
https://play.google.com/store/apps/details?id=org.openhab.habdroid
Eclipse Public License 2.0
599 stars 317 forks source link

Monitor state of an item and trigger some action if state changes #40

Closed madon closed 9 years ago

madon commented 9 years ago

What I want to do is simply show the image of a network camera on a wall mounted tablet running habdroid, if the doorbell button is pressed. I can easily use tasker to create a scene with the cam image and an button to open the door, but the problem is to trigger a task to display the scene on a item state change. A possible solution would be a tasker plugin which does a long polling request and receives an update if there is a state change. But I think belvictor is not so excited about integrating a tasker plugin in habdroid. Another solution would be to trigger habdroid through an openhab action to switch to a specific sitemap link, where a webview widget is placed. But there is the problem how to identify the client which should change its display.

I've used an intend, created by tasker, which looks like an discovered NFC tag, to swich to a specific sitemap link. But there is also the problem how to detect the state change of the triggering item.

Polling the state of an item using the REST api is possible but you have to poll the item lets say every 5 seconds or so, which is not the best solution.

Any suggestions?

digitaldan commented 9 years ago

One solution would be to use a dynamic sitemap (https://github.com/openhab/openhab/wiki/Explanation-of-Sitemaps#dynamic-sitemaps) You could have a frame that contains an image widget for the camera and the button. The frame's visibility would be tied to the doorbell item. Put this at the top of each section of your sitemap.

belovictor commented 9 years ago

@madon , what do you think about the solution proposed by @digitaldan ? I'm always eager to fulfill user needs, but navigation controlled from openHAB is something which is not specified in openHAB API. And I'm not against Tasker integration, I just don't have enough time resource to do it myself :-)

cribskip commented 9 years ago

What about GCM (sendNotification) and a custom prefix like "intent://" which would trigger an intent. We should discuss this with the ios developers to get a similar user experience.

Monitoring of state changes on a end user device, even with wifi, would be a bad idea to me as the server push is more efficient.

belovictor commented 9 years ago

Intent to do what? :-) The problem here is that we don't have a mechanism to address certain sitemap page other then URL which can be different in different environments. Anyway, if current options for doing that doesn't fit the task this should be discussed on openHAB level I think.