🔦 Tasmota über HTTP-WEB-API, WebRequests schalten und pollen, HTTPMOD

Begonnen von Torxgewinde, 10 August 2026, 23:05:34

Vorheriges Thema - Nächstes Thema

Torxgewinde

Hallo,
Ich wollte einem Tasmotagerät nicht die Zugangsdaten für MQTT verraten und habe deswegen den Zugriff über die HTTP-Schnittstelle genutzt. Hier der Snippet dazu:

defmod TasmotaRelais HTTPMOD http://[$name:TasmotaDeviceAddress]/cm?cmnd=STATUS+0 60
attr TasmotaRelais userattr TasmotaDeviceAddress
attr TasmotaRelais TasmotaDeviceAddress 192.168.123.123
attr TasmotaRelais comment '\
Unter dem Attribut "TasmotaDeviceAddress" trägt man die IP oder den Namen des Tasmota Gerätes ein.\
\
In diesem Beispiel wird der Status abgefragt und in Readings aktualisiert.\
Dies passiert mit dem Pollinterval wie im Define angegeben.\
\
Mit der Set-Funktion kann man das erste Relais "Power1" schalten.\
Da FHEM gerne mit on/off als Wert dafür arbeitet wird dies mit Map angepasst.\
\
Wenn das Tasmota Device direkt geschaltet wird, dauert es solange bis wieder gepollt wird bevor der \
Status korrekt übernommen wird. Das ist naturgemäß ein Problem beim Polling.\
Setzt man mittels FHEM den Relaiszustand, wird direkt danach der Status abgerufen und übernommen.\
'
attr TasmotaRelais disable 0
attr TasmotaRelais extractAllJSON 0
attr TasmotaRelais get01JSON POWER
attr TasmotaRelais get01Map ON:on,OFF:off
attr TasmotaRelais get01Name SwitchState
attr TasmotaRelais get01URL http://[$name:TasmotaDeviceAddress]/cm?cmnd=POWER
attr TasmotaRelais reading01JSON StatusSNS_Time
attr TasmotaRelais reading01Name Time
attr TasmotaRelais reading02JSON StatusSNS_ANALOG_Temperature1
attr TasmotaRelais reading02Name Temperature
attr TasmotaRelais reading03JSON StatusSNS_ENERGY_Total
attr TasmotaRelais reading03Name Total
attr TasmotaRelais reading04JSON StatusSNS_ENERGY_Yesterday
attr TasmotaRelais reading04Name Yesterday
attr TasmotaRelais reading05JSON StatusSNS_ENERGY_Today
attr TasmotaRelais reading05Name Today
attr TasmotaRelais reading06JSON StatusSNS_ENERGY_Power
attr TasmotaRelais reading06Name Power
attr TasmotaRelais reading07JSON StatusSNS_ENERGY_ApparentPower
attr TasmotaRelais reading07Name ApparentPower
attr TasmotaRelais reading08JSON StatusSNS_ENERGY_ReactivePower
attr TasmotaRelais reading08Name ReactivePower
attr TasmotaRelais reading09JSON StatusSNS_ENERGY_Factor
attr TasmotaRelais reading09Name Factor
attr TasmotaRelais reading10JSON StatusSNS_ENERGY_Frequency
attr TasmotaRelais reading10Name Frequency
attr TasmotaRelais reading11JSON StatusSNS_ENERGY_Voltage
attr TasmotaRelais reading11Name Voltage
attr TasmotaRelais reading12JSON StatusSNS_ENERGY_Current
attr TasmotaRelais reading12Name Current
attr TasmotaRelais reading13JSON Status_Power
attr TasmotaRelais reading13Map 1:on,0:off
attr TasmotaRelais reading13Name SwitchState
attr TasmotaRelais reading14JSON StatusSTS_Wifi_Signal
attr TasmotaRelais reading14Name WifiSignal
attr TasmotaRelais replacement01Mode expression
attr TasmotaRelais replacement01Regex \[([^:]+):([^\]]+)\]
attr TasmotaRelais replacement01Value my $device = $name if ($1 eq "\$name") // $1;;\
ReadingsVal($device, $2, undef) or AttrVal($device, $2, "???");;
attr TasmotaRelais set01FollowGet SwitchState
attr TasmotaRelais set01Hint on,off
attr TasmotaRelais set01Name Relais
attr TasmotaRelais set01TextArg 1
attr TasmotaRelais set01URL http://[$name:TasmotaDeviceAddress]/cm?cmnd=Power1%20$val
attr TasmotaRelais showBody 0
attr TasmotaRelais showMatched 0
attr TasmotaRelais stateFormat {\
  return ReadingsVal($name, 'SwitchState', '???');;\
}