Getestet mit TL-SG108PE 3.0 und TL-SG116E 2.0
[psw] beim Attribut sid01Data inklusive der eckigen Klammern durch das richtige Passwort ersetzen!
defmod SWITCH3 HTTPMOD http://192.168.0.100/
attr SWITCH3 enableCookies 1
attr SWITCH3 get01Name PortSettingRpm
attr SWITCH3 get01Poll 1
attr SWITCH3 get01PollDelay 300
attr SWITCH3 get01URL http://192.168.0.100/PortSettingRpm.htm
attr SWITCH3 get02Name SystemInfoRpm
attr SWITCH3 get02Poll 1
attr SWITCH3 get02PollDelay 300
attr SWITCH3 get02URL http://192.168.0.100/SystemInfoRpm.htm
attr SWITCH3 get03Name PortStatisticsRpm
attr SWITCH3 get03Poll 1
attr SWITCH3 get03PollDelay 300
attr SWITCH3 get03URL http://192.168.0.100/PortStatisticsRpm.htm
attr SWITCH3 oldreadings Link_Status_[0-9]+,Port_State_[0-9]+
attr SWITCH3 reAuthRegex logonInfo
attr SWITCH3 reading01Name MAC_Address
attr SWITCH3 reading01Regex macStr\:\[\n?\"([0-9A-Fa-f\:]+)\"\n?\]
attr SWITCH3 reading02Name IP_Address
attr SWITCH3 reading02Regex ipStr\:\[\n?\"([0-9.]+)\"\n?\]
attr SWITCH3 reading03Name Firmware
attr SWITCH3 reading03Regex firmwareStr\:\[\n?\"([0-9a-zA-z. ]+)\"\n?\]
attr SWITCH3 reading04Name Hardware
attr SWITCH3 reading04Regex hardwareStr\:\[\n?\"([\w -.]+?)\"\n?\]
attr SWITCH3 reading05Name Name
attr SWITCH3 reading05Regex descriStr\:\[\n?\"([\w\-]+)\"\n?\]
attr SWITCH3 reading06Name Netmask
attr SWITCH3 reading06Regex netmaskStr\:\[\n?\"([0-9.]+)\"\n?\]
attr SWITCH3 reading07Name Gateway
attr SWITCH3 reading07Regex gatewayStr\:\[\n?\"([0-9.]+)\"\n?\]
attr SWITCH3 reading08Name State
attr SWITCH3 reading08Regex state\:\n?\"?(\[[0-9,]+\])\"?\n?
attr SWITCH3 reading09Name Link_Status
attr SWITCH3 reading09Regex link_status\:\n?\"?(\[[0-9,]+\])\"?\n?
attr SWITCH3 reading10Name Pakets
attr SWITCH3 reading10Regex pkts\:\n?\"?(\[[0-9,]+\])\"?\n?
attr SWITCH3 set15Hint 0,1
attr SWITCH3 set15Name SetPortStatus1
attr SWITCH3 set15URL http://192.168.0.100/port_setting.cgi?portid=1&state=$val&speed=1&flowcontrol=0&apply=Apply
attr SWITCH3 set16Hint 0,1
attr SWITCH3 set16Name SetPortStatus2
attr SWITCH3 set16URL http://192.168.0.100/port_setting.cgi?portid=2&state=$val&speed=1&flowcontrol=0&apply=Apply
attr SWITCH3 set17Hint 0,1
attr SWITCH3 set17Name SetPortStatus3
attr SWITCH3 set17URL http://192.168.0.100/port_setting.cgi?portid=3&state=$val&speed=1&flowcontrol=0&apply=Apply
attr SWITCH3 room Netzwerk
attr SWITCH3 sid01Data username=%%user%%&password=%%password%%&cpassword=&logon=Login
attr SWITCH3 sid01IgnoreRedirects 1
attr SWITCH3 sid01URL http://192.168.0.100/logon.cgi
attr SWITCH3 stateFormat Link_Status
attr SWITCH3 replacement01Mode key
attr SWITCH3 replacement01Regex %%user%%
attr SWITCH3 replacement01Value user
attr SWITCH3 replacement02Mode key
attr SWITCH3 replacement02Regex %%password%%
attr SWITCH3 replacement02Value password
set SWITCH3 storeKeyValue user admin
set SWITCH3 storeKeyValue password 1234568
05.01.2022
Reading05 gemäß Info von Jostar angepasst.
04.05.2022
Anpassungen durchgeführt:
- storeKeyValue - Replacement genutzt
- Link_Status (https://forum.fhem.de/index.php/topic,121875.msg1220433.html#msg1220433)
10.05.2022
set15-17, Ports Ein/Ausschalten hinzugefügt
Klappt soweit. Mit
attr SWITCH3 reading05Regex descriStr\:\[\n?\"([\w\-]+)\"\n?\]
klappt auch der Standardname (mit Minuszeichen).
Link_Status
Funktion um den Link_Status in einzelne Readings zu bekommen:
## ReadingArrayToReadings
## Device
## ReadingName
## Value e.g.: "link_status:[5,5,5,6,0,0,0,6,0,0]"
sub ReadingArrayToReadings($$$) {
my ($device, $reading, $value) = @_;
my @values = ( $value =~ /(\d)/g );
my $i = 0;
readingsBeginUpdate( $hash );
foreach(@values) {
my $old_val = ReadingsVal($device, "${reading}_${i}", "-");
if ($old_val ne $_) {
readingsBulkUpdate( $hash, "${reading}_${i}", ${_} );
}
$i += 1;
}
readingsEndUpdate( $hash, 1 );
## evtl weitere vorhandene Einträge löschen (wenn Array kleiner wird)
}
Link_Status der Ports aufdröseln:
defmod NTFY_SWITCH_LinkStatus notify SWITCH[0-9]+:Link_Status:.* {\
my $LinkStatus = ReadingsVal($NAME, "Link_Status", "-");;\
ReadingArrayToReadings($NAME, "Link_Status", $LinkStatus);;\
}
Telegramnachricht bei Änderung des Link_Status:
defmod TelegramMessage05_SWITCH_Link_Status notify SWITCH[0-9]+:Link_Status_[0-9]+.* {\
my $message = "${SELF}\n";;\
my $switch_hardware = ReadingsVal($NAME, "Hardware", "-");;\
my @port_state = ("Link Down","Auto","10Half","10Full","100Half","100Full","1000Full");;\
\
##$message .= "${NAME}\n";;\
##$message .= "${switch_hardware}\n";;\
##$message .= "EVENT: ${EVENT}\n";;\
\
my @y = split / /, $EVENT;;\
##$message .= "dec: ${y[1]}\n";;\
\
if ( $EVENT =~ /_(\d+)/) {\
my $port = $1;;\
my $port_state = $y[1];;\
##$message .= "state: ${port_state[$port_state]}\n";;\
$message .= "#${NAME}\n";;\
$message .= "${switch_hardware}\n";;\
$message .= "Port ${port} changed state to: ${port_state[$port_state]}\n";;\
\
fhem("set myTelegramBot _msg $message");;\
}\
\
}
Hallo,
leider bekomm ich keine readings von dem Swich TL-SG108PE.
So wie ich es interpretiere scheint das passwort nicht zu passen.
Im ersten post steht das sid01Data das Passwort zu ersetzen ist auch eckige Klammern...die sehe ich nicht.
Wie sollte die Zeile richtig heißen?
username=%%user%%&password=%%password%%&cpassword=&logon=Login
2022.09.12 21:43:07 4: SWITCH3: BodyDecode is not decoding the response body (charset not found, bodyDecode defaults to none)
2022.09.12 21:43:07 4: SWITCH3: checking for redirects, code=200, ignore=0
2022.09.12 21:43:07 4: SWITCH3: no redirects to handle
2022.09.12 21:43:07 4: SWITCH3: CheckAuth decided new authentication required
2022.09.12 21:43:07 4: SWITCH3: Authentication still required but no retries left - did last authentication fail?
2022.09.12 21:43:07 4: SWITCH3: Read response to get03 didn't match any Reading
Wie sollte die Zeile auschauen wenn das unten mein Passwort ist:
geheim
set SWITCH3 storeKeyValue password [s]geheim[/s]
oder
set SWITCH3 storeKeyValue password geheim
Die Zeile ist richtig und darf nicht geändert werden:
attr SWITCH3 sid01Data username=%%user%%&password=%%password%%&cpassword=&logon=Login
danach speicherst du den Benutzer JohnDoe mit dem Passwort geheim:
set SWITCH3 storeKeyValue user JohnDoe
set SWITCH3 storeKeyValue password geheim
Das mit [ s][ /s] ist natürlich falsch und ich habe es in meinem ersten Post korrigiert. Das war die HTML Formatierung für durchgestrichen und das wird in der in den Code Staements nicht formatiert.
Ansonsten setzt du verbose auf 5 und schickst mal den ganzen Log den dein Device erzeugt samt einem list deines device.
danke für die Rückmeldung.
set SWITCH3 storeKeyValue user admin
set SWITCH3 storeKeyValue password xxxxxxxx
leider scheint es noch nicht zu funtionieren.
switch.txt - log auszug (hoffe das reicht)
list.SWITCH.txt - list SWITCH3
Sorry, Fehler in meiner Vorlage :(.
Führe das aus und alles läuft.
attr SWITCH3 replacement01Value user
Anhänge im Thread und verbose im Device kannst löschen.
super danke! Jetzt geht es!