#307 - Added in the minecraft stuff. - Notifications or some sort of automations will follow. Stay tuned.
This commit is contained in:
parent
39aa798be5
commit
a664f8c514
|
@ -23,7 +23,7 @@
|
|||
action:
|
||||
- service: script.notify_engine
|
||||
data_template:
|
||||
who: "parents"
|
||||
who: 'parents'
|
||||
value1: "The {{ trigger.to_state.attributes.friendly_name }} has been {{ (trigger.to_state.state)|replace('_', ' ') }}."
|
||||
|
||||
- service: input_boolean.turn_on
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
"""
|
||||
Sensor to check the status of a Minecraft server.
|
||||
|
||||
"""
|
||||
import logging
|
||||
from homeassistant.helpers.entity import Entity
|
||||
ATTR_PING = 'Ping'
|
||||
ATTR_USERS = 'Users Online'
|
||||
ATTR_MOTD = 'MOTD'
|
||||
ATTR_VERSION = 'Version'
|
||||
ICON = 'mdi:minecraft'
|
||||
REQUIREMENTS = ['mcstatus==2.1']
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Minecraft server platform."""
|
||||
from mcstatus import MinecraftServer as mcserver
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
server = config.get('server')
|
||||
name = config.get('name')
|
||||
|
||||
if server is None:
|
||||
logger.error('No server specified')
|
||||
return False
|
||||
elif name is None:
|
||||
logger.error('No name specified')
|
||||
return False
|
||||
|
||||
add_devices([
|
||||
MCServerSensor(server, name, mcserver)
|
||||
])
|
||||
|
||||
|
||||
class MCServerSensor(Entity):
|
||||
"""A class for the Minecraft server."""
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
def __init__(self, server, name, mcserver):
|
||||
"""Initialize the sensor."""
|
||||
self._mcserver = mcserver
|
||||
self._server = server
|
||||
self._name = name
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the server."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
# pylint: disable=no-member
|
||||
def update(self):
|
||||
"""Update device state."""
|
||||
status = self._mcserver.lookup(self._server).status()
|
||||
query = self._mcserver.lookup(self._server).query()
|
||||
self._state = str(status.players.online) + '/' + str(status.players.max)
|
||||
self._ping = status.latency
|
||||
self._users = query.players.names
|
||||
self._motd = query.motd
|
||||
self._version = query.software.version
|
||||
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_PING: self._ping,
|
||||
ATTR_USERS: self._users,
|
||||
ATTR_MOTD: self._motd,
|
||||
ATTR_VERSION: self._version
|
||||
}
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend."""
|
||||
return ICON
|
|
@ -1,98 +0,0 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides:
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start daemon at boot time
|
||||
# Description: Enable service provided by daemon.
|
||||
### END INIT INFO
|
||||
|
||||
dir="/home/pi/dasher"
|
||||
cmd="DEBUG=* node app.js"
|
||||
user="root"
|
||||
|
||||
name=`basename $0`
|
||||
pid_file="/var/run/$name.pid"
|
||||
stdout_log="/var/log/$name.log"
|
||||
stderr_log="/var/log/$name.err"
|
||||
|
||||
get_pid() {
|
||||
cat "$pid_file"
|
||||
}
|
||||
|
||||
is_running() {
|
||||
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if is_running; then
|
||||
echo "Already started"
|
||||
else
|
||||
echo "Starting $name"
|
||||
cd "$dir"
|
||||
if [ -z "$user" ]; then
|
||||
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
|
||||
else
|
||||
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
|
||||
fi
|
||||
echo $! > "$pid_file"
|
||||
if ! is_running; then
|
||||
echo "Unable to start, see $stdout_log and $stderr_log"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if is_running; then
|
||||
echo -n "Stopping $name.."
|
||||
kill `get_pid`
|
||||
for i in {1..10}
|
||||
do
|
||||
if ! is_running; then
|
||||
break
|
||||
fi
|
||||
|
||||
echo -n "."
|
||||
sleep 1
|
||||
done
|
||||
echo
|
||||
|
||||
if is_running; then
|
||||
echo "Not stopped; may still be shutting down or shutdown may have failed"
|
||||
exit 1
|
||||
else
|
||||
echo "Stopped"
|
||||
if [ -f "$pid_file" ]; then
|
||||
rm "$pid_file"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Not running"
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
if is_running; then
|
||||
echo "Unable to stop, will not attempt to start"
|
||||
exit 1
|
||||
fi
|
||||
$0 start
|
||||
;;
|
||||
status)
|
||||
if is_running; then
|
||||
echo "Running"
|
||||
else
|
||||
echo "Stopped"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
|
@ -12,27 +12,3 @@ group:
|
|||
- binary_sensor.bedroom_plugged
|
||||
- binary_sensor.clock_motion
|
||||
- binary_sensor.clock_plugged
|
||||
|
||||
# automation:
|
||||
#
|
||||
# - alias: 'Enable battery help!'
|
||||
# trigger:
|
||||
# - platform: state
|
||||
# entity_id:
|
||||
# - binary_sensor.clock_plugged
|
||||
# - binary_sensor.bedroom_plugged
|
||||
# to: 'off'
|
||||
# from: 'on'
|
||||
#
|
||||
# - alias: 'Cry when the Battery is about to die. '
|
||||
# trigger:
|
||||
# - platform: state
|
||||
# entity_id:
|
||||
# - input_boolean.clock_snooze
|
||||
# to: 'on'
|
||||
# from: 'off'
|
||||
# action:
|
||||
# - delay:
|
||||
# minutes: 10
|
||||
# - service: input_boolean.turn_off
|
||||
# entity_id: input_boolean.clock_snooze
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#-------------------------------------------
|
||||
# @CCOSTAN
|
||||
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
|
||||
# Neato Support for D7 Connected Botvac - control my [Neato Vacuum](http://amzn.to/2kqnnqu) with Home Assistant.
|
||||
#-------------------------------------------
|
||||
# homeassistant:
|
||||
# customize_glob:
|
||||
# "*.*_sleep_hours":
|
||||
# unit_of_measurement: hours
|
||||
# icon: mdi:sleep
|
||||
#
|
||||
# hidden: False
|
||||
#-------------------------------------------
|
||||
sensor:
|
||||
platform: minecraft
|
||||
name: Bear Stone
|
||||
server: 192.168.10.10
|
||||
#-------------------------------------------
|
||||
# group:
|
||||
# finance:
|
||||
# entities:
|
||||
# - sensor.tesla
|
||||
# - sensor.bitcoin
|
||||
|
||||
##############################################################################
|
||||
### Automations - Detect when things are not right. Like any Good Watchdog.
|
||||
##############################################################################
|
||||
#automation:
|
||||
#Tweets pushed out to twitter.
|
Loading…
Reference in New Issue