Logic Machine Forum
Lutron send command - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Lutron send command (/showthread.php?tid=5446)



Lutron send command - Hadeel - 31.05.2024

Hi!
I have a project with Lutron integration and I follwed the thread below to setup LM.

https://forum.logicmachine.net/showthread.php?tid=414&highlight=lutron

While LM successfully works as listener and I can see everry log from Lutron device and button,
any Lutron command that I send does not seem to be reaching and nothing will be shown in the log.

My event script is pretty simple as below. (I have lutron user script and resident script as shown in the forum thread above)
Code:
require('user.lutron')

tcp, err = lutron_login()
if not tcp then
  log('no connection to device', err)
end
tcp:send('#DEVICE,5001,1,3\r\n')

Other things that I tried;
・I used ping command of LM network utility and checked if LM can reach Lutron interface and it was successfull.
・I confirmed lutron_login function returns response "QNET>" which proves login to the Lutron interface is successful.
・I installed telnet command on my PC (which is located in the same network as LM) and tried executing Lutron commands and it was successful.

Could you think of any reason that I cannnot execute command from LM event script?


RE: Lutron send command - admin - 31.05.2024

Modify lutron_login() in the user library to log the data that is sent to LM.
Code:
function lutron_login()
  local tcp, tcp_err = lutron_connect()

  if not tcp then
    return nil, tcp_err
  end

  local res, err

  res, err = tcp:receive(7)
  log(res, err)
  
  tcp:send(user..'\r\n')
  
  res, err = tcp:receive(10)
  log(res, err)

  tcp:send(password..'\r\n')
  
  res, err = tcp:receive(9)
  log(res, err)

  if res == nil or res == 'bad login' then
    tcp:close()
    return nil, res
  end

  return tcp
end

Add log(lutron_receive(tcp)) at the end of your script to check the reply.


RE: Lutron send command - Hadeel - 05.06.2024

Dear admin,
Appreciate your advice so much,
I am not sure what happened but when I added "lutron_receive(tcp)" at the end of the script everyting started to work!
Thank you so much for your advice as always!