Autor Thema: Python: Status eines Devices abfragen und Kommando absetzen  (Gelesen 6040 mal)

Offline dero

  • Full Member
  • ***
  • Beiträge: 246

import telnetlib

control_host= <host>
control_port= <telnet port> (7072)
control_password= <telnet password>

def FHEM_Value(dvc):
tn= telnetlib.Telnet( control_host, control_port, 5 )
tn.read_until( "Password: " )
tn.write( control_password + "\n" )
tn.write( "{'=' . Value('" + dvc + "')}\n" )
tn.read_until( "=" )
res= tn.read_until( "\r" )[ :-1 ]
tn.close()
return res

def FHEM_Cmd(cmd):
tn= telnetlib.Telnet( control_host, control_port, 5 )
tn.read_until( "Password: " )
tn.write( control_password + "\n" )
tn.write( cmd + "\n" )
# the following makes sure that we don't close the connection before the cmd was executed... (synchronization point)
tn.write( "{ '=' }\n" )
tn.read_until( "=" )
tn.close()
« Letzte Änderung: 11 November 2013, 15:19:56 von dero »
Hilfreich Hilfreich x 1 Liste anzeigen

 

decade-submarginal