Need some assistance on my lua script-> python for lutron

My script will turn on certain lights on my old lutron setup. Taken from my Vera installation. I don’t think I can use that in HA? I think I need to convert it to python. My try below the LUA :slight_smile: Any hints is appreciated.

local socket = require “socket”
local lutron_tcp

function connectLutron()
lutron_tcp = assert(socket.tcp())
lutron_tcp:settimeout(0.5)
lutron_tcp:connect(“192.168.0.50”, 23)
end

function sendLutron(cmd)
lutron_tcp:send(cmd … “\r”)
sleepLutron()
end

function disconnectLutron()
lutron_tcp:close()
end

function sleepLutron()
luup.sleep(500)
end

function powerOnLutron()
sendLutron(“password”)
sleepLutron()
end

connectLutron()
powerOnLutron()
sendLutron("#DEVICE,0x000b0eb9,141,7,0")
sendLutron("#DEVICE,0x000b11a7,141,7,0")
disconnectLutron()

My try on Python:
import telnetlib
HOST = 192.168.0.50"
password = “nwk”
tn = telnetlib.Telnet(HOST, “23”)
tn.read_until(“login: “)
tn.write(password + “\n”)
tn.read_until(“connection established”)
tn.write(”#DEVICE,0x000b0eb9,141,7,0\n”)
tn.write("#DEVICE,0x000b11a7,141,7,0\n")
tn.write(“exit\n”)
tn.read_all()

Pretty sure the exit part don’t work. Will try to see if I can test this outside HA first.

Thanks in advance!