Code by Scott שאול בן ישוע
Verified Commit c300d9ef authored by Sha'ul ben Yeshua's avatar Sha'ul ben Yeshua 🎗
Browse files

Fixed incorrect command name and added nut restart

parent b77a5d00
Pipeline #285 passed with stage
in 4 seconds
/*
/*
A simple driver that will run a command via telnet
Useful with Rpi's
......@@ -25,7 +25,7 @@ metadata {
name: "Send Telnet Command",
namespace: "sgrayban",
author: "Scott Grayban",
importUrl: "http://sgrayban.borgnet.online:8081/hubitat-public-repo/drivers/Send%20Telnet%20Command.groovy"
importUrl: "http://sgrayban.borgnet.online:8081/hubitat-public-repo/Send%20Telnet%20Command.groovy"
)
{
......@@ -33,7 +33,9 @@ metadata {
capability "Telnet"
capability "Switch"
command "Reboot Device"
command "RebootDevice"
command "PowerOff"
command "RestartNut"
}
attribute "Telnet", "String"
......@@ -42,7 +44,7 @@ metadata {
input "ip", "text", title: "Target System IP", description: "", required: true, displayDuringSetup: true
input "port", "text", title: "Target System Telnet Port", description: "", required: true, displayDuringSetup: true
input "username", "text", title: "Username", description: "", required: true, displayDuringSetup: true
input "password", "text", title: "Password", description: "", required: true, displayDuringSetup: true
input "password", "password", title: "Password", description: "", required: true, displayDuringSetup: true
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}
}
......@@ -68,13 +70,37 @@ def on() {
sendEvent(name: "switch", value: "on")
def msg = "sudo reboot"
if (logEnable) log.info "Sending msg = ${msg}"
sendEvent(name: "Command Sent", value: msg)
sendHubCommand(new hubitat.device.HubAction("""$msg\r\n""", hubitat.device.Protocol.TELNET))
runIn(5,sendEvent(name: "switch", value: "off"))
}
def reboot(){
def RebootDevice(){
on()
}
def RestartNut() {
initialize()
if (logEnable) log.info "Send Reboot"
//sendEvent(name: "switch", value: "on")
def msg = "sudo service nut-server restart"
if (logEnable) log.info "Sending msg = ${msg}"
sendEvent(name: "Command Sent", value: msg)
sendHubCommand(new hubitat.device.HubAction("""$msg\r\n""", hubitat.device.Protocol.TELNET))
//runIn(5,sendEvent(name: "switch", value: "off"))
}
def PowerOff() {
initialize()
if (logEnable) log.info "Send PowerOff"
sendEvent(name: "switch", value: "on")
def msg = "sudo poweroff"
if (logEnable) log.info "Sending msg = ${msg}"
sendEvent(name: "Command Sent", value: msg)
sendHubCommand(new hubitat.device.HubAction("""$msg\r\n""", hubitat.device.Protocol.TELNET))
runIn(5,sendEvent(name: "switch", value: "off"))
}
def parse(String msg) {
if (logEnable) log.debug "Telnet Response = ${msg}"
if (msg == "permitted by applicable law.") {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment