hektiker1983 / openhab

Automatically exported from code.google.com/p/openhab
0 stars 0 forks source link

Implement XBMC Binding #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Just like the VDR binding an XBMC binding would be really great.

XBMC can be controlled via JSON-RPC API.

http://wiki.xbmc.org/index.php?title=JSON-RPC_API

Original issue reported on code.google.com by christop...@gmail.com on 23 Mar 2013 at 5:03

GoogleCodeExporter commented 9 years ago

Original comment by teichsta on 7 May 2013 at 3:47

GoogleCodeExporter commented 9 years ago
unassigned to make current state more transparent

Original comment by teichsta on 21 May 2013 at 9:17

GoogleCodeExporter commented 9 years ago

Original comment by kai.openhab on 22 May 2013 at 8:19

GoogleCodeExporter commented 9 years ago

Original comment by teichsta on 23 May 2013 at 3:49

GoogleCodeExporter commented 9 years ago
I have just pushed a change to my clone to make it easier to send XBMC UI 
notifications from with rules/scripts. It is a simple wrapper around an HTTP 
POST request. Usage is as follows;

   sendXbmcNotification(host, port, title, message)

Cheers,
Ben

Original comment by ben.jone...@gmail.com on 27 May 2013 at 1:30

GoogleCodeExporter commented 9 years ago
merged Action into default (see 
http://code.google.com/p/openhab/source/detail?r=36cd64e1350e02486ded2fdd34129d7
50c0842a7)

Original comment by teichsta on 27 May 2013 at 2:41

GoogleCodeExporter commented 9 years ago
00:49:06.101 ERROR o.o.m.r.i.engine.RuleEngine[:287]- Error during the 
execution of startup rule 'Test': The name 
'sendXbmcNotification(<XStringLiteralImpl>,<XNumberLiteralImpl>,<XStringLiteralI
mpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.

How is this supposed to work? Do I need import statements? Or put something in 
addons?
Thing is, sometimes it works then it stops working, I wonder if this is not due 
to me changing my .rules at runtime.

Original comment by ant.ber...@gmail.com on 1 Sep 2013 at 10:52

GoogleCodeExporter commented 9 years ago
I assume that the XBMC action bundle is not yet started when the startup rule 
is executed. Does it work as expected if you call it from other kind of rules?

Original comment by kai.openhab on 3 Sep 2013 at 7:05

GoogleCodeExporter commented 9 years ago
Could you please extend the sendXbmcNotification method and add two further 
parameter s 'image' and 'displayTime'?
By using the JSON request 

{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"A 
Title","message":"A message","image":"URL TO AN 
IMAGE","displaytime":5000},"id":1} 

you can for example also show the icon/image from the given URL in the 
notification. In combination with an webcam at your main door you will be able 
to not show only a plain text notification that someone is ringing but also to 
show who is in front of your door.
With the parameter 'displayTime' you would be also able tocontrol the display 
time of the notification. I think this would make this action more comfortable.

Original comment by dongy...@gmail.com on 26 Sep 2013 at 1:35

GoogleCodeExporter commented 9 years ago
Yeah they are good ideas - feel free to make changes to the XBMC action bundle 
yourself. The beauty of Kai's new architecture is the XBMC action is a 
standalone bundle which can be modded away to your hearts content - with no 
effect on core :).

Original comment by ben.jone...@gmail.com on 26 Sep 2013 at 8:19

GoogleCodeExporter commented 9 years ago
#9 we'd love to merge your Pull-Request :-)

Original comment by teichsta on 26 Sep 2013 at 8:33

GoogleCodeExporter commented 9 years ago
I'm currently setting up a new dev environment and will push all changes to my 
clone when I'm done.

Original comment by dongy...@gmail.com on 27 Sep 2013 at 4:13

GoogleCodeExporter commented 9 years ago
Hi, have you started yet implementing new functions ? I was planning to do it 
also on my clone :) I would love to have all the basic control for my XBMC from 
my OH Instance too.

Original comment by Achil...@gmail.com on 27 Sep 2013 at 4:41

GoogleCodeExporter commented 9 years ago
Yes I already started and implementation is finished. Will commit the changes 
today.

Original comment by dongy...@gmail.com on 27 Sep 2013 at 5:55

GoogleCodeExporter commented 9 years ago
A few minutes later :-) and the adaptions are available (check my clone).

Original comment by dongy...@gmail.com on 27 Sep 2013 at 6:03

GoogleCodeExporter commented 9 years ago
merged it!

Original comment by kai.openhab on 28 Sep 2013 at 6:10

GoogleCodeExporter commented 9 years ago
Thanks!
Updating the description in the wiki 
(https://code.google.com/p/openhab/wiki/Actions) would be also good.
Can someone with appropriate permissions do that? 

Original comment by dongy...@gmail.com on 28 Sep 2013 at 9:40

GoogleCodeExporter commented 9 years ago
> Can someone with appropriate permissions do that? 
How about yourself, I have just granted you edit rights :-)

Original comment by kai.openhab on 29 Sep 2013 at 3:46

GoogleCodeExporter commented 9 years ago
Done

Original comment by dongy...@gmail.com on 29 Sep 2013 at 5:45

GoogleCodeExporter commented 9 years ago
Just FYI: I started working on a binding for xbmc. Using a websocket i get 
realtime updates about my xbmc instance to openhab, which combined with some 
dimmable light makes for a pretty cool tricks :)

Right now pretty much all it can report on is the playerstatus, the currently 
playing title and the url for fanart. But since the basic structure is now 
prepared, it should be pretty easy to extend  it to anything mentioned on this 
page: http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6

Right now it says "issue attachment storage quota exceeded", so if anyone wants 
to give it a go, im going to need some help before i can post a snapshot-jar.
Im planning on doing some cleanup on my code tomorrow, maybe even some 
documentation, before opening my changes up for others to help.

Original comment by tlan...@gmail.com on 19 Oct 2013 at 6:43

GoogleCodeExporter commented 9 years ago
Sound great!

Original comment by christop...@gmail.com on 19 Oct 2013 at 6:56

GoogleCodeExporter commented 9 years ago
Cool!
Regarding the attachments: I asked for a higher quota and it was confirmed (see 
https://code.google.com/p/support/issues/detail?id=31068), but somehow it 
didn't work... Will continue asking.

Original comment by kai.openhab on 19 Oct 2013 at 7:26

GoogleCodeExporter commented 9 years ago
So heres my forked repository:
https://github.com/tlanfer/openhab/tree/xbmc-binding
I added a few lines of documentation within the code and did some minor 
refactoring.

To be honest i am not entirely sure if i did not make any bad mistakes 
regarding all that osgi stuff. For example i am using an AbstractActiveBinding, 
although i dont really need active polling, but that was the only one in which 
i could get the item configurations.

Plus as i usually deal with maven, non-osgi projects i just put the 
dependencies in a lib folder. Looking at other addons i think this is the way 
to go, but to me it feels somehow wrong :)

If someone compiles it and wants to try it out, heres how to configure it:

 * (optional) In your openhab.cfg, create entries to map instance names to hostnames:
    xbmc:host.<name>=<hostname>
    e.g
    xbmc.host.livingRoom=192.168.1.3
    xbmc.host.bedRoom=bedroom-pc.local

 * Create item configurations. These can either use one of the named instances by prefixing the name with a #, or have the ip/hostname directly given. This way you dont event have to change your openhab.cfg

String xbmcRunnung  "Status [%s]"   {xbmc="<[#livingRoom|Player.State]"}
String xbmcTitle        "Title [%s]"        {xbmc="<[#bedRoom|Player.Title]"}
String xbmcShowTitle    "Show 
[%s]"   {xbmc="<[some-not-named-hostname|Player.ShowTitle]"}

The general syntax is:
 * Right now there is no outgoing commands, but that may change in the future. <[...] for incoming, >[...] for outgoing stuff (like in other bindings). 
 * First argument in the item is the xbmc-instance to connect to: <[your-hostname-here|...] or <[#your-named-instance-here|...] 
 * Second argument is the property to report on. Currently there are Player.State, Player.Title and Player.ShowTitle. <[#livingRoom|Player.State]

Original comment by tlan...@gmail.com on 20 Oct 2013 at 3:39

GoogleCodeExporter commented 9 years ago
And just for the fun of it, heres a little teaser video: 
http://www.youtube.com/watch?v=N7_5phTVbo0

Original comment by tlan...@gmail.com on 21 Oct 2013 at 5:42

GoogleCodeExporter commented 9 years ago
I guess you have also no problem with this binding if you start openhab from 
within your dev environment. In my case I don't get the item configuration. 
It's always null.

Original comment by dongy...@gmail.com on 25 Oct 2013 at 9:36

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Can you give more details about your configuration, especially the relevant 
sections of your openhab.cfg and items-file? And is there some sort of 
stacktrace in your logs. 
Which version of xbmc are you running? Did i mention Frodo beeing minimum?

Ive been running this for abour a week now on a fresh install of openhab 1.3 on 
my raspberry pi, no dev environment. And at least Player.State should be 
functioning fine. I just notices some problems with Player.Title and 
Player.ShowTitle, will try to fix that now.

Original comment by tlan...@gmail.com on 26 Oct 2013 at 11:55

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'm running openhab on my Macbook (Mavericks) from within Eclipse (Juno).

I added the following line to the end of my openhab.cfg (in dev mode XBMC runs 
also on my Macbook):

############################### XBMC Binding 
####################################
xbmc.host.livingRoom=127.0.0.1

And here are the lines from my items file:

String xbmcRunning      "Status [%s]"   {xbmc="<[#livingRoom|Player.State]"}
String xbmcTitle        "Title [%s]"    {xbmc="<[#livingRoom|Player.Title]"}
String xbmcShowTitle    "Show [%s]"     {xbmc="<[#livingRoom|Player.ShowTitle]"}

When I start now openhab from within Eclipse I see the following exception:

19:57:37.429 DEBUG o.o.b.x.internal.XbmcActivator[:54] - xbmc binding has been 
started.
19:57:58.757 ERROR o.o.b.x.internal.XbmcBinding[:135] - Something went wrong.
org.openhab.model.item.binding.BindingConfigParseException: Found item for 
instance 'livingRoom', which is not defined.
    at org.openhab.binding.xbmc.internal.XbmcBinding.execute(XbmcBinding.java:120)
    at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:176)
    at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:193)
19:57:58.757 ERROR o.o.b.x.internal.XbmcBinding[:135] - Something went wrong.

If I run in debug mode I can see that the object 'config' which is given to the 
method updated(Dictionary config) is always null.

Original comment by dongy...@gmail.com on 27 Oct 2013 at 7:05

GoogleCodeExporter commented 9 years ago
Can you show your OSGI-INF entries?

Original comment by kai.openhab on 27 Oct 2013 at 7:08

GoogleCodeExporter commented 9 years ago
Under OSGI-INF I have two files named binding.xml and 
genericbindingprovider.xml.

The content of binding.xml is:

<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" 
activate="activate" deactivate="deactivate" 
name="org.openhab.binding.xbmc.binding">
    <implementation class="org.openhab.binding.xbmc.internal.XbmcBinding" />

    <service>
        <provide interface="org.osgi.service.event.EventHandler" />
        <provide interface="org.osgi.service.cm.ManagedService" />
    </service>

    <property name="event.topics" type="String" value="openhab/command/*" />
    <property name="service.pid" type="String" value="org.openhab.xbmc" />

    <reference bind="setEventPublisher" cardinality="1..1"
        interface="org.openhab.core.events.EventPublisher" name="EventPublisher"
        policy="dynamic" unbind="unsetEventPublisher" />
    <reference bind="addBindingProvider" cardinality="1..n"
        interface="org.openhab.binding.xbmc.XbmcBindingProvider" name="XbmcBindingProvider"
        policy="dynamic" unbind="removeBindingProvider" />

</scr:component>

And the content of genericbindingprovider.xml is:

<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" 
name="org.openhab.binding.xbmc.genericbindingprovider">
   <implementation class="org.openhab.binding.xbmc.internal.XbmcGenericBindingProvider"/>

   <service>
      <provide interface="org.openhab.model.item.binding.BindingConfigReader"/>
      <provide interface="org.openhab.binding.xbmc.XbmcBindingProvider"/>
   </service>

</scr:component>

Original comment by dongy...@gmail.com on 27 Oct 2013 at 9:10

GoogleCodeExporter commented 9 years ago
Excited to try this out, but I get the same error as well.  Seems to not parse 
the config file?

Original comment by g.g.r...@gmail.com on 31 Oct 2013 at 6:25

GoogleCodeExporter commented 9 years ago
I had a look at this. Looks like i get the same error in my logs, but somehow 
it still works. No idea why.
In the IDE i dont get this error. 
I think we will need someone with more knowledge and/or experience creating 
bindings to help out with this.
Or maybe even someone to have a more general look at what i did in 
XbmcBinding.java, XbmcActivator.java, XbmcGenericBindingProvider.java and 
XbmcBindingProvider.java.

Original comment by tlan...@gmail.com on 2 Nov 2013 at 4:30

GoogleCodeExporter commented 9 years ago
For those who still want to give it a try: You dont have to configure your 
instances in openhab.conf. 
Create an item as for example <[192.168.1.6|Player.State], it should work 
around the existing problem.

Original comment by tlan...@gmail.com on 2 Nov 2013 at 4:32

GoogleCodeExporter commented 9 years ago
Thanks, I tried putting the ip address in the item, but still the error:

14:20:48.223 INFO  o.o.b.x.internal.XbmcBinding[:127]- Creating new 
xbmcConnector for 192.168.9.115
14:20:48.307 ERROR o.o.b.x.internal.XbmcBinding[:135]- Something went wrong.
java.lang.NullPointerException: null
    at org.openhab.binding.xbmc.rpc.calls.PlayerGetItem.processResponse(PlayerGetItem.java:42)
    at org.openhab.binding.xbmc.rpc.RpcCall.execute(RpcCall.java:38)
    at org.openhab.binding.xbmc.rpc.XbmcConnector.requestPlayerUpdate(XbmcConnector.java:98)
    at org.openhab.binding.xbmc.rpc.XbmcConnector.<init>(XbmcConnector.java:62)
    at org.openhab.binding.xbmc.internal.XbmcBinding.execute(XbmcBinding.java:128)
    at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156)
    at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173)

I really appreciate your work on this binding, it will be a great addition!  
Looking forward to some outgoing commands if you get the inclination.

Greg

Original comment by g.g.r...@gmail.com on 2 Nov 2013 at 7:24

GoogleCodeExporter commented 9 years ago
Hey Greg, your NullPointerException should be gone. I put in some more checks, 
so it wont try to update the currently playing item if there is nothing 
currently playing.

Still no idea about that configuration thingy, im still hopelessly lost on that.

Original comment by tlan...@gmail.com on 5 Nov 2013 at 10:42

GoogleCodeExporter commented 9 years ago

Original comment by teichsta on 5 Nov 2013 at 10:47

GoogleCodeExporter commented 9 years ago
Is there a JAR available? I don't have a build environment here, but would love 
to try it.  Thanks.

Original comment by renatori...@gmail.com on 6 Nov 2013 at 5:54

GoogleCodeExporter commented 9 years ago
Unfortunately i still can not add attachements on here, so for now i just built 
a jar and put it on my google drive:
https://drive.google.com/file/d/0B5-265oZ7Zx1UXBNa2pva0Jxek0/edit?usp=sharing

Hope that works. The instance configuration problem from #25, #29 etc. should 
be gone now, too. I hope.

Original comment by tlan...@gmail.com on 6 Nov 2013 at 8:51

GoogleCodeExporter commented 9 years ago
Fantastic!  That jar works great for me!

Original comment by g.g.r...@gmail.com on 7 Nov 2013 at 6:06

GoogleCodeExporter commented 9 years ago
@tlanfer - can you confirm this binding is written for v1.3.0? It might be 
worth upgrading it to 1.4.0 as I think some of the startup routines changed a 
bit. Plus I am running 1.4.0 and would love to get hold of this!!

Original comment by ben.jone...@gmail.com on 7 Nov 2013 at 7:36

GoogleCodeExporter commented 9 years ago
I built and tested it on 1.3.0/1.3.1. I'll have a look at 1.4.0 tomorrow.

Original comment by tlan...@gmail.com on 7 Nov 2013 at 7:39

GoogleCodeExporter commented 9 years ago
This issue has been migrated to Github. If this issue id is greater than103 its 
id has been preserved on Github. You can open your issue by calling the URL 
https://github.com/openhab/openhab/issues/<issueid>. Issues with ids less or 
equal 103 new ids were created.

Original comment by teichsta on 17 Nov 2013 at 8:08

GoogleCodeExporter commented 9 years ago
see above!

Issue has been migrated to Github and should be discussed there.

Original comment by teichsta on 21 Nov 2013 at 1:51