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 A simple driver that will run a command via telnet
Useful with Rpi's Useful with Rpi's
...@@ -25,7 +25,7 @@ metadata { ...@@ -25,7 +25,7 @@ metadata {
name: "Send Telnet Command", name: "Send Telnet Command",
namespace: "sgrayban", namespace: "sgrayban",
author: "Scott Grayban", 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 { ...@@ -33,7 +33,9 @@ metadata {
capability "Telnet" capability "Telnet"
capability "Switch" capability "Switch"
command "Reboot Device" command "RebootDevice"
command "PowerOff"
command "RestartNut"
} }
attribute "Telnet", "String" attribute "Telnet", "String"
...@@ -42,7 +44,7 @@ metadata { ...@@ -42,7 +44,7 @@ metadata {
input "ip", "text", title: "Target System IP", description: "", required: true, displayDuringSetup: true 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 "port", "text", title: "Target System Telnet Port", description: "", required: true, displayDuringSetup: true
input "username", "text", title: "Username", 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 input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
} }
} }
...@@ -68,13 +70,37 @@ def on() { ...@@ -68,13 +70,37 @@ def on() {
sendEvent(name: "switch", value: "on") sendEvent(name: "switch", value: "on")
def msg = "sudo reboot" def msg = "sudo reboot"
if (logEnable) log.info "Sending msg = ${msg}" 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)) sendHubCommand(new hubitat.device.HubAction("""$msg\r\n""", hubitat.device.Protocol.TELNET))
runIn(5,sendEvent(name: "switch", value: "off")) runIn(5,sendEvent(name: "switch", value: "off"))
} }
def reboot(){
def RebootDevice(){
on() 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) { def parse(String msg) {
if (logEnable) log.debug "Telnet Response = ${msg}" if (logEnable) log.debug "Telnet Response = ${msg}"
if (msg == "permitted by applicable law.") { if (msg == "permitted by applicable law.") {
......
Supports Markdown
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