Minecraft binding, help with thing declaration

Hi!

I have installed the Minecraft binding so that I can monitor the activity and power down my server when it isn’t used. I followed the instructions described here: link. I have also installed the Spigot plugin.

There is no instruction of how to configure the “thing” so this time I have tried to configure the binding through Paper UI and then linked the channels to predefined items. It works, kinda, but I get a lot of strange activity in the logs and if I am to use the items in rules I would like the activity to be more stable.

Please see the following log messages:

2017-01-10 15:43:30.668 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-10 15:43:30.693 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'ON' for item 'MinecraftServer_Online' to handler for channel 'minecraft:server:online:online', because no thing with the UID 'minecraft:server:online' could be found.
2017-01-10 15:43:30.708 [ItemStateChangedEvent     ] - MinecraftServer_Online changed from OFF to ON
2017-01-10 15:43:33.716 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'OFF' for item 'MinecraftServer_Online' to handler for channel 'minecraft:server:online:online', because no thing with the UID 'minecraft:server:online' could be found.
2017-01-10 15:43:33.728 [ItemStateChangedEvent     ] - MinecraftServer_Online changed from ON to OFF
2017-01-10 15:44:33.714 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-10 15:44:33.729 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'ON' for item 'MinecraftServer_Online' to handler for channel 'minecraft:server:online:online', because no thing with the UID 'minecraft:server:online' could be found.
2017-01-10 15:44:33.756 [ItemStateChangedEvent     ] - MinecraftServer_Online changed from OFF to ON
2017-01-10 15:44:36.757 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'OFF' for item 'MinecraftServer_Online' to handler for channel 'minecraft:server:online:online', because no thing with the UID 'minecraft:server:online' could be found.
2017-01-10 15:44:36.765 [ItemStateChangedEvent     ] - MinecraftServer_Online changed from ON to OFF
2017-01-10 15:45:36.757 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-10 15:45:36.780 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update 'ON' for item 'MinecraftServer_Online' to handler for channel 'minecraft:server:online:online', because no thing with the UID 'minecraft:server:online' could be found.
2017-01-10 15:45:36.788 [ItemStateChangedEvent     ] - MinecraftServer_Online changed from OFF to ON
2017-01-10 15:46:08.126 [INFO ] [craft.handler.MinecraftServerHandler] - Connection to minecraft server opened
2017-01-10 15:46:08.155 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update '0' for item 'MinecraftServer_Players' to handler for channel 'minecraft:server:online:players', because no thing with the UID 'minecraft:server:online' could be found.
2017-01-10 15:46:08.164 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update '8' for item 'MinecraftServer_MaxPlayers' to handler for channel 'minecraft:server:online:maxPlayers', because no thing with the UID 'minecraft:server:online' could be found.

My guess is that if I were to define the thing manually I would have more control and could perhaps avoid the warnings.

Also, there are more channels available according to the README.md but in order for me to utilze these I guess I would have to define the thing manually. The Paper UI will only find three server channels.

Help would be, as always, much appreciated!

I don’t know this binding but it implies that it auto discovers the servers on the network so you should not be defining or configuring the Things anyway.

A Thing represents a device, in this case 1 Minecraft server. A Thing has one or more Channels (usually more than one). An Item gets linked to one or more Channels (usually One). In this case it looks like there are three Channels: Server, Player, and Sign.

What you would do is install the binding. Make any configuration necessary to its cfg. Then check the Inbox in PaperUI for new Things it discovered. I suspect there will be one Thing per Minecraft server on your network. Accept the Thing and now go to the Configuration > Things menu.

Now you can manually link an Item to a channel (if that is how you want to do it) by copying the Channel ID from PaperUI into your Item. For example, if I want to create an Item linked the online channel of my manticore network Thing:

I would create the following Item

Switch ManticoreOnline { channel="network:device:manticore:online" }

To get the ping time I would create the following Item

Number ManticorePingTime { channel="network:device:manticore:time" }

Based on the logs above, it appears you have tried to create a separate Thing for each Channel. With this binding, I would expect there to be just one Thing per server and there is no configuration necessary for the Thing because it was auto-discovered. If there happens to be some configuration possible, it will likely be exposed by pressing the pencil icon on the Thing configuration page.

So, for example, I would expect an Item linked to the online status of a Thing to be something like:

Switch MinecraftOnline { channel="minecraft:server:<unique id of server>:online" }

Where <unique id of server > is some ID generated by the binding when it discovered the Minecraft server. If it is like the zwave binding, you will have the opportunity to change that unique ID when you accept the Thing out of the Inbox.

1 Like

@mattias_markehed, maybe you can help. In any case, it would be great if you could add an example section to the README.md, just like we have it for the other bindings as well!

1 Like

@rlkoshak is correct.
The Server should be auto discovered on the network using Zeroconf.
It is possible to add the server manually as a thing if its not automatically found.

Players and signs with redstone blocks under them will then automatically be discovered when added.
Se attached image.

(Other signs on image bellow)

@Kai I will write a better guide and probably add some features soon.

1 Like

I followed @rlkoshak strategy in defining the items with the channels manually. The warnings regarding thing UID ("...because no thing with the UID 'minecraft:server:online' could be found") are now gone.

However I still have a lot of strange activity regarding the online item, please see the following log:

2017-01-11 22:30:14.938 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-11 22:30:14.988 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from OFF to ON
2017-01-11 22:32:22.318 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from ON to OFF
2017-01-11 22:32:57.733 [ERROR] [.mdns.discovery.MDNSDiscoveryService] - Participant 'org.openhab.binding.minecraft.discovery.MinecraftMDNSDiscoveryParticipant' threw an exception
	at org.openhab.binding.minecraft.discovery.MinecraftMDNSDiscoveryParticipant.getThingUID(MinecraftMDNSDiscoveryParticipant.java:78)[181:org.openhab.binding.minecraft:2.0.0.201612301947]
	at org.openhab.binding.minecraft.discovery.MinecraftMDNSDiscoveryParticipant.createResult(MinecraftMDNSDiscoveryParticipant.java:48)[181:org.openhab.binding.minecraft:2.0.0.201612301947]
2017-01-11 22:32:57.826 [INFO ] [craft.handler.MinecraftServerHandler] - Disposing minecraft server thing
2017-01-11 22:32:57.872 [INFO ] [craft.handler.MinecraftServerHandler] - Initializing MinecraftHandler
2017-01-11 22:32:57.881 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-11 22:32:57.908 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from OFF to ON
2017-01-11 22:32:57.929 [ThingUpdatedEvent         ] - Thing 'minecraft:server:192_168_10_146' has been updated.
2017-01-11 22:32:58.074 [INFO ] [craft.handler.MinecraftServerHandler] - Connection to minecraft server opened
2017-01-11 22:34:38.147 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Players changed from 0 to 1
2017-01-11 22:35:14.012 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Players changed from 1 to 0
2017-01-11 22:35:30.456 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Players changed from 0 to 1
2017-01-11 22:35:39.115 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Players changed from 1 to 0
2017-01-11 22:35:55.078 [INFO ] [.discovery.MinecraftDiscoveryService] - Connection to Minecraft server stopped
2017-01-11 22:35:55.122 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-11 22:36:02.224 [ERROR] [.mdns.discovery.MDNSDiscoveryService] - Participant 'org.openhab.binding.minecraft.discovery.MinecraftMDNSDiscoveryParticipant' threw an exception
	at org.openhab.binding.minecraft.discovery.MinecraftMDNSDiscoveryParticipant.getThingUID(MinecraftMDNSDiscoveryParticipant.java:78)[181:org.openhab.binding.minecraft:2.0.0.201612301947]
2017-01-11 22:38:02.496 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from ON to OFF
2017-01-11 22:39:02.474 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-11 22:39:02.520 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from OFF to ON
2017-01-11 22:41:09.841 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from ON to OFF
2017-01-11 22:42:09.823 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-11 22:42:09.858 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from OFF to ON
2017-01-11 22:44:17.191 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from ON to OFF
2017-01-11 22:45:17.184 [INFO ] [.discovery.MinecraftDiscoveryService] - Start connecting to Minecraft server at: ws://192.168.10.146:10692/stream
2017-01-11 22:45:17.224 [ItemStateChangedEvent     ] - MinecraftBukkitServer_Online changed from OFF to ON

The online update at 22:38:02.496 is correct but events after this time are “wrong”. Also there is an error regarding participant when stopping the server.
While the server is online the events seems to be correct but of course I would like them to be correct also while offline.

I did a log:set DEBUG on the binding but the log seen above is all that is produced.

Some background conditions.
OH2 Snapshot Build #685.
Minecraft server: Spigot 1.11.2 (latest version as of today?)
Server port: 25526 (default Minecraft server port. In contrast to what the binding seems to believe. Don’t know how to change the port definition though. Changing it through Paper UI doesn’t work, the change is lost almost directly.)

Perhaps I should wait for @mattias_markehed updated description of the setup.

What is required for the zeroconf discovery to work? I installed the OHMinecraft plugin and restarted my server (which is on the same subnet as the OH2 server, answering on the default port) but it doesn’t seem like the binding sees it.

Also, the Minecraft log is completely swamped with output from the OHMinecraft plugin. Any way I can control the log level?

I hope it’ll open up my kids eyes to home automation if they could light their bedroom lamps using switches in Minecraft :smile:

2 Likes

For me the discovery worked automagically after having acknowledged the thing through Paper UI.

I defined the items manually using the following syntax:

Switch MinecraftOnline { channel="minecraft:server:192_168_10_146:online" } 

The channel string necessary is actually visible through Paper UI if your thing/server is discovered.

I’m also interested in turning down the debug activity from the plugin, although after having installed also other plugins (Worldedit etc.) I now see a lot of different logs. Perhaps this can be handled by the start command when starting the server jar through java?

Note: I’m still having problems with the server going online and offline even though the server is down. While the server is up the feedback seems to be correct.

Perhaps I should add a condition for the switch which also regards the ping of the server PC before updating the Online item?! An ugly workaround but should work. I’m using the Network binding to monitor network presence. I’m also using the WoL binding to start the server. I’m quite pleased with the setup. :grin:

I’ve actually done everything in my (kinda limited) power to get the discovery working, but it simply doesn’t. Could anyone give me an example on how to declare this Thing manually?

edit: I’ve now done some digging into the workings of mDNS and into your code, @mattias_markehed, trying to find out where things go wrong in my environment. My Minecraft server answers on port 10692, which seems to be the port used. So far so good. But if I understand things correctly the plugin also should register a mDNS record with the name wc-minecraft and somehow this doesn’t seem to work. Using mdns-scan I checked from both my openhab server and from the minecraft server itself and there doesn’t seem to be any such record (the only record I can see at my minecraft server is _workstation._tcp.local). I can’t see the plugin logging any errors though. Any ideas?

@DanielMalmgren try adding it manually

Doh. Kinda feel stupid now. I’d never even noticed that button. I thought the only alternative if the thing didn’t automatically get up in the inbox was to add it using old-style files. Seems to work nice now that I added it manually :slight_smile:

The only problem now is the log level of the plugin. I have a hard time finding the relevant stuff in the log amongst all those lines…

Thanks @rlkoshak, but no. I’m talking about the Minecraft server log and the plugin needed there :wink:

@mattias_markehed: I noticed now that you actually did some changes in the code a couple of weeks ago. The MC server plugin is really much kinder to the log now, it’s appreciated! Do you also have a jar for the oh binding somewhere?

I am new to this whole mindcraft thing, but my son is really interested. I am working on migrating to openHAB 2 and wondered what the possibilities could be for this binding. I think I see how a switch in mindcraft could turn on a light, but is there a way for items in the real world like contact for doors to open close say a mindcraft door?

Firstly, my kids would kill you for saying mindcraft, it really has nothing with mind to do :grin:

Anyway, in the 2.0.0 version there is no way of affecting anything in the game from real world, all you do is get information from the game. If I understand Mattias’ comments in github correctly though, I’d say in his latest version you can trigger commands in Minecraft from the binding. Using commands in Minecraft you can do practically everything in the game, opening a door would be one of those things. So you could actually do an in-game copy of your real house where everything happens just in reality :wink:

There is not any jar for the binding.
You would have to update it through openhab.
One way to do it is to uninstall the plugin and install it again (the is probably a cleaner way to do it).

As @DanielMalmgren said. It is possible in the latest release.

Ok. I wonder if maybe bundle:update in Karaf would do it as well?

Anyway, I tried uninstalling and installing through Paper UI now. It still says the exact same version though (just 2.0.0), how do I spot the difference? Should I see a channel for this new commands thingy?

@DanielMalmgren I tried updating the binding manually like i said and realized that it did not work.
I do not know when the updates to the bindings are released.

I could send you the binding as a jar if you would like to try it out.

Maybe you simply need to be on snapshot (2.1.0) version of openhab to get the snapshot versions of bindings? I’ve seen most other developers of bindings simply put a jar with their latest dev versions somewhere on the web and just post an url here.

I’d be happy to test the new version. I’ve pm:ed you my mail address :slight_smile: