[Release] Minecraft Server Integration

I've got a Minecraft server that I wanted to write an integration for, to determine when someone came online/left my server.

There's more that I can do with this (who's online, server type, I need to shift it to UDP from TCP...), I just wanted to get it off the ground and eventually use my hub to push status updates to Discord. I don't tend to play games in the summer, so I'm aiming to keep adding more to this leading up to winter.

Currently:

  1. Uses the presence attribute to show if anyone is on the server.
  2. Shows current, max, and peak player counts
  3. Shows the server name

Future Plans:

  1. Show who's online
  2. Show join/depart info
  3. Show server type
  4. Use switch to show if a server is up or not
  5. Get and store handshake info
  6. Shift to UDP (which is what the protocol is supposed to use)

https://raw.githubusercontent.com/adamkempenich/hubitat/master/Drivers/Minecraft%20Server/MinecraftServer.groovy

Example:

New version:

Enable: enable-query=true in your server.properties file

2 Likes

I have a Hubitat Ping device on my HE with an icon on the main dashboard that shows if the host machine is running, but I've been looking for a way to also display if the actual Minecraft server is up. I'll give it a whirl... join \ depart info would be cool as well.

1 Like

Great idea. I could use the switch attribute to show if the server is responsive, too.

So i added the device driver and added a virtual device. i can telnet to 25565 but the initialize \ refresh but I'm seeing an error in the log.

Summary

dev:2072021-07-19 02:07:12.410 pm errorgroovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.util.ArrayList#getAt. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [interface groovy.lang.Range] [interface java.util.Collection] on line 99 (parse)

dev:2072021-07-19 02:07:12.404 pm tracefirstMaxPlayersByte - 22

dev:2072021-07-19 02:07:12.403 pm tracefirstCurrentPlayersByte - 20

dev:2072021-07-19 02:07:12.396 pm trace[-1, 23, 65, 32, 77, 105, 110, 101, 99, 114, 97, 102, 116, 32, 83, 101, 114, 118, 101, 114, -89, 48, -89, 50, 48]

dev:2072021-07-19 02:07:12.383 pm debugParse: FF001700410020004D0069006E006500630072006100660074002000530065007200760065007200A7003000A700320030

dev:2072021-07-19 02:07:12.323 pm debugMinecraft Instance (172.16.0.60): Stopping connectDevice loop. Starting refresh loop

dev:2072021-07-19 02:07:12.309 pm infoMinecraft Instance (172.16.0.60): Connection successfully established

dev:2072021-07-19 02:07:12.299 pm debugMinecraft Instance (172.16.0.60): [-2] was converted. Transmitting: FE

dev:2072021-07-19 02:07:12.226 pm debugMinecraft Instance (172.16.0.60): Stopping connectDevice loop. Starting refresh loop

dev:2072021-07-19 02:07:12.196 pm infoMinecraft Instance (172.16.0.60): Connection successfully established

dev:2072021-07-19 02:07:11.175 pm debugMinecraft Instance (172.16.0.60): Opening Socket Connection.

dev:2072021-07-19 02:07:11.172 pm debugMinecraft Instance (172.16.0.60): Opening Socket Connection.

dev:2072021-07-19 02:07:10.080 pm debugParse:

dev:2072021-07-19 02:07:10.031 pm debugMinecraft Instance (172.16.0.60): Stopping refresh loop. Starting connectDevice loop

dev:2072021-07-19 02:07:10.029 pm debugMinecraft Instance (172.16.0.60): Initializing device.

dev:2072021-07-19 02:07:10.027 pm debugMinecraft Instance (172.16.0.60): Number of failed responses: 2

dev:2072021-07-19 02:07:00.063 pm debugMinecraft Instance (172.16.0.60): socketStatus: send error: Broken pipe (Write failed)

dev:2072021-07-19 02:07:00.049 pm debugMinecraft Instance (172.16.0.60): [-2] was converted. Transmitting: FE

dev:2072021-07-19 02:07:00.047 pm debugMinecraft Instance (172.16.0.60): Number of failed responses: 1

dev:2072021-07-19 02:06:50.048 pm debugMinecraft Instance (172.16.0.60): [-2] was converted. Transmitting: FE

dev:2072021-07-19 02:06:50.045 pm debugMinecraft Instance (172.16.0.60): Number of failed responses: 0

dev:2072021-07-19 02:06:42.412 pm debugMinecraft Instance (172.16.0.60): Stopping connectDevice loop. Starting refresh loop

dev:2072021-07-19 02:06:42.400 pm infoMinecraft Instance (172.16.0.60): Connection successfully established

@adamkempenich
When I saw this pop up as a release I thought it was the Hubitat version of this:

1 Like

Fixed :slight_smile:

Don't tempt me :joy: I was looking over the messaging integration earlier and considering adding notification support.

New code added, shows the following in the system log:

Summary
Name Value Unit Description Text Source Type Date
serverName A Minecraft Server DEVICE 2021-07-19 02:56:37.516 PM CDT
maxPlayers 20 DEVICE 2021-07-19 02:56:37.515 PM CDT
currentPlayers 0 DEVICE 2021-07-19 02:56:37.515 PM CDT
presence not present DEVICE 2021-07-19 02:56:37.514 PM CDT
switch off DEVICE 2021-07-19 02:56:35.250 PM CDT
switch off DEVICE 2021-07-19 02:56:34.027 PM CDT
switch off DEVICE 2021-07-19 02:56:10.021 PM CDT

as well as the following when I view the virtual device

Summary

Nobody playing so I think all is well.

Let me know once you have the Switch feature etc.. and I'll be happy to test.

Also, like the Hubitat Ping, is it possible to use a DNS name instead of IP, so that if the pc running the minecraft server gets a new DHCP address I dont need to change the HE config?

DNS name might already work, actually. If it's not, I can probably make it work.

When I use the name, i get the following, which appears to be a failure:

Summary

dev:2072021-07-19 03:05:02.620 pm debugMinecraft Instance (MINI): [-2] was converted. Transmitting: FE

dev:2072021-07-19 03:05:02.612 pm debugMinecraft Instance (MINI): Next initialization attempt in 10 seconds.

dev:2072021-07-19 03:05:02.608 pm debugMinecraft Instance (MINI): Error attempting to establish socket connection to device.

dev:2072021-07-19 03:05:02.589 pm debugMinecraft Instance (MINI): Opening Socket Connection.

dev:2072021-07-19 03:05:01.555 pm debugMinecraft Instance (MINI): Stopping refresh loop. Starting connectDevice loop

dev:2072021-07-19 03:05:01.553 pm debugMinecraft Instance (MINI): Initializing device.

dev:2072021-07-19 03:05:01.551 pm debugMinecraft Instance (MINI): Number of failed responses: 9

dev:2072021-07-19 03:05:01.093 pm debugMinecraft Instance (MINI): Next initialization attempt in 10 seconds.

dev:2072021-07-19 03:05:01.086 pm debugMinecraft Instance (MINI): Error attempting to establish socket connection to device.

dev:2072021-07-19 03:05:01.084 pm debugMinecraft Instance (MINI): [-2] was converted. Transmitting: FE

dev:2072021-07-19 03:05:01.081 pm debugMinecraft Instance (MINI): Next initialization attempt in 10 seconds.

dev:2072021-07-19 03:05:01.079 pm debugMinecraft Instance (MINI): Error attempting to establish socket connection to device.

dev:2072021-07-19 03:05:01.078 pm debugMinecraft Instance (MINI): Opening Socket Connection.

dev:2072021-07-19 03:05:01.077 pm debugMinecraft Instance (MINI): Next initialization attempt in 10 seconds.

dev:2072021-07-19 03:05:01.075 pm debugMinecraft Instance (MINI): Error attempting to establish socket connection to device.

dev:2072021-07-19 03:05:01.048 pm debugMinecraft Instance (MINI): Opening Socket Connection.

dev:2072021-07-19 03:05:01.031 pm debugMinecraft Instance (MINI): Opening Socket Connection.

dev:2072021-07-19 03:05:00.018 pm debugMinecraft Instance (MINI): Stopping refresh loop. Starting connectDevice loop

dev:2072021-07-19 03:05:00.017 pm debugMinecraft Instance (MINI): Initializing device.

However using IP it looks good:

Summary

dev:2072021-07-19 03:05:13.770 pm infoMinecraft Instance (172.16.0.60): Connection successfully established

dev:2072021-07-19 03:05:13.601 pm tracemax players 20

dev:2072021-07-19 03:05:13.598 pm tracecurrent Players - 0

dev:2072021-07-19 03:05:13.595 pm traceName - A Minecraft Server

dev:2072021-07-19 03:05:13.589 pm tracefirstMaxPlayersByte - 22

dev:2072021-07-19 03:05:13.587 pm tracefirstCurrentPlayersByte - 20

dev:2072021-07-19 03:05:13.578 pm trace[-1, 23, 65, 32, 77, 105, 110, 101, 99, 114, 97, 102, 116, 32, 83, 101, 114, 118, 101, 114, -89, 48, -89, 50, 48]

dev:2072021-07-19 03:05:13.540 pm debugParse: FF001700410020004D0069006E006500630072006100660074002000530065007200760065007200A7003000A700320030

dev:2072021-07-19 03:05:13.415 pm debugMinecraft Instance (172.16.0.60): [-2] was converted. Transmitting: FE

dev:2072021-07-19 03:05:13.412 pm debugMinecraft Instance (172.16.0.60): Number of failed responses: 0

dev:2072021-07-19 03:05:12.763 pm debugMinecraft Instance (172.16.0.60): Opening Socket Connection.

dev:2072021-07-19 03:05:12.131 pm debugMinecraft Instance (172.16.0.60): Stopping connectDevice loop. Starting refresh loop

dev:2072021-07-19 03:05:12.091 pm infoMinecraft Instance (172.16.0.60): Connection successfully established

dev:2072021-07-19 03:05:11.572 pm debugParse:

dev:2072021-07-19 03:05:11.525 pm debugMinecraft Instance (172.16.0.60): Stopping refresh loop. Starting connectDevice loop

dev:2072021-07-19 03:05:11.524 pm debugMinecraft Instance (172.16.0.60): Initializing device.

dev:2072021-07-19 03:05:11.520 pm debugMinecraft Instance (172.16.0.60): Number of failed responses: 10

dev:2072021-07-19 03:05:11.053 pm debugMinecraft Instance (172.16.0.60): Opening Socket Connection.

1 Like

Thanks for checking into that! I'll see if it works when I shift over to the correct protocol.

I'm wondering if we can pull Daytime/Nighttime info from the game, too. Would be really cool to be able to get CCT/Luminosity from the game (possibly even weather) and integrate that into an automation routine.

I like that idea as well. Let me ask the minecraft expert in the house if there's anything else he'd like to see on the dashboard. Not sure what metrics you can pull, but it'd be interesting to get as much data as you can.

What's cool is that now, when another player joins\leaves the server I can have Alexa announce them. Are you able to get joining \ departing player names?

Yes :slight_smile: That's on my list.

There's an extended list of info I can grab with a little more work... essentially I have to get and store a key, and send it in a little bit of a different way with each request, but that's my idea for it.

Excellent. Let me know when you need testing, happy to help out. Oh, and not sure how hard package manager is to setup and use, but if you're going to be making frequent changes it'd probably be an easier upgrade path for most.

Not trying to assign you more work, I just suspect that some might have an easier time if it were in a pick list in HPM versus pasting Gihub code... just my $0.02

Thanks for this!

One other question - you are using Presence to indicate if anyone is on the server, are you planning to use the Switch for if the IP\DNS Name returns a ping, or if the Minecraft port is responding?

Presence indicates if anyone is on. Switch will indicate if the device responds to a ping :slight_smile:

Updated this to not use a persistent connection, and to display server status via Switch.

Just to clarify, that Switch is showing if the IP of the server is replying to a ping, or if the minecraft TCP port is answering?

Updated the code (love the ASCII art), refreshed the virtual switch, it shows switch ON on the right

However trying to add a Switch style tile to the dashboard

It's not working, the switch shows like this...

Should I be adding it differently?

This one :slight_smile:

I see why the dashboard isn't working. I forgot to add the switch capability to the driver. Give me a moment...

edit: Updated

Download the Hubitat app