FHEM > Codeschnipsel

Python: Status eines Devices abfragen und Kommando absetzen

(1/1)

dero:

--- Code: ---
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()

--- Ende Code ---

Navigation

[0] Themen-Index

Zur normalen Ansicht wechseln