openhab / org.openhab.ui.habpanel

OUTDATED repo - HABPanel has moved to the openhab-webui repo!
https://github.com/openhab/openhab-webui
Eclipse Public License 1.0
97 stars 92 forks source link

Wiring HABPanel with openHAB rules - HABPanel actions #71

Closed kubawolanin closed 7 years ago

kubawolanin commented 7 years ago

I'm playing around with my local HABPanel and just came up with this crazy idea. It would be great if we could integrate it with native openHAB rules. Imagine that you have a rule like this:

rule "Switch dashboard to front camera when doorbell rings"
when
    Item Doorbell changed
then
    habpanelChangeDashboard("cameras")
end

or even some voice command like

rule "Show me the charts"
when
    Item VoiceCommand received command
then
    if (command.contains("show me the charts")) {
        habpanelChangeDashboard("charts")
    }
end

That would require implementing HABPanel action preferably inside add-on. On the backend side there would be a need to handle the action logic. On the frontend, however, we would require a way to react on these events coming from rule engine.

What do you think?

watou commented 7 years ago

Could the effect be achieved by posting updates to a String item, with a UI configuration that listens to changes on that item to determine which dashboard to show?

kubawolanin commented 7 years ago

Hi @watou Wow, honestly, I didn't even think about it! Now I see that it doesn't make sense to create actions if there's already a way to do it.

HABPanel.postUpdate("cameras")

Thank you!

@ghys feel free to close this issue :-)

korg1000 commented 7 years ago

Could you post a example to this HabPanel.postupdate? Its on openhab side or habpanel side? This example for Doorbell-camera is exactly what i need thanks

kubawolanin commented 7 years ago

@korg1000 I think you only need to create a string item in your *.items file, like this:

 String HABPanel "Dashboard"

and then in HABPanel ( http://youropenhab:8080/habpanel/index.html#/settings ) you just select this item under "Switch dashboard with item value" option.

Then a simple rule will change your dashboard:

rule "Switch dashboard to front camera when doorbell rings"
when
    Item Doorbell changed to ON
then
    HABPanel.postUpdate("cameras")
    Thread::sleep(3000)
    HABPanel.postUpdate("")
    Doorbell.postUpdate(OFF)
end

Edit: Note that items value must match your dashboard's name - it's case sensitive. So it won't work for "Cameras".

"cameras" is obviously a dashboard name. Hope that helps!

ghys commented 7 years ago

That's right! Right now you have to define your items yourself - good for keeping retrocompatibility with OH 1.8 - but in the future we could imagine a new HABPanel instance registering itself as a Thing in openHAB 2 with a channel ("current dashboard"), so the item could be linked and bound automatically. Same thing with the item used for TTS. What do you think?

On Sun, Nov 27, 2016 at 2:16 PM, Kuba Wolanin notifications@github.com wrote:

@korg1000 https://github.com/korg1000 I think you only need to create a string item in your *.items file, like this: String HABPanel "Dashboard"

and then in HABPanel ( http://youropenhab:8080/ habpanel/index.html#/settings ) you just select this item under "Switch dashboard with item value" option.

Then a simple rule will change your dashboard:

rule "Switch dashboard to front camera when doorbell rings" when Item Doorbell changed then HABPanel.postUpdate("cameras") end

"cameras" is obviously a dashboard name. Hope that helps!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openhab/org.openhab.ui.habpanel/issues/71#issuecomment-263121707, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6Us7RFtvamGIJlFu1GcI08giOVbWMzks5rCYLFgaJpZM4K9GjD .

-- Yannick Schaus mailto:yannick@schaus.net

kubawolanin commented 7 years ago

@ghys i think that's awesome! Because right now if you post an update to this String HABPanel item and change the dashboard by yourself, there's no state updated. I've edited my code in previous response - workaround would be resetting HABPanel value after some time.

kaikreuzer commented 7 years ago

in the future we could imagine a new HABPanel instance registering itself as a Thing in openHAB 2 with a channel

I am not sure if this is a good idea - I don't like mixing UIs with bindings too much. I would rather think of a rule action that can be used within rules to take control of the dashboard. But also here, I'd suggest to wait for the new rule engine to be stable enough and go for this directly.

ghys commented 7 years ago

Okay, I wasn't too sure about that approach either anyway :) We'll come up with something more polished using the new rules engine then. Thanks for your input.

On Sun, Nov 27, 2016 at 3:18 PM, Kai Kreuzer notifications@github.com wrote:

in the future we could imagine a new HABPanel instance registering itself as a Thing in openHAB 2 with a channel

I am not sure if this is a good idea - I don't like mixing UIs with bindings too much. I would rather think of a rule action that can be used within rules to take control of the dashboard. But also here, I'd suggest to wait for the new rule engine to be stable enough and go for this directly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openhab/org.openhab.ui.habpanel/issues/71#issuecomment-263124766, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6Usyz1s1DdR_I7H_RuBn2aNhelOZBYks5rCZE7gaJpZM4K9GjD .

-- Yannick Schaus mailto:yannick@schaus.net

zacofany commented 7 years ago

Is there any way to run linux command on the machine running habpanel? I mean I'd like wake up screen by "xset s reset" on remote RPi running habpanel when camera is showing up on screen. Exec binding seems to be too slow.

ghys commented 7 years ago

@zacofany you can't run commands from a web browser, sorry. I don't know how to implement your use case yet, if I come up with an idea I'll let you know.

Closing this issue since the initial question has been answered.