Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Überwachung der Solaranlage per eMail oder Pushover und Steuerung von Geräten mit Smart Home Zentralen. PV-Überschuss Steuerung verbunden mit Geräten und Tasmota Firmware. Wallbox Steuerungen und API Schnittstelle, über die Daten in die Solaranzeigen Datenbanken geschrieben und gelesen werden können. Alles, was man für Steuerungsaufgaben benötigt.

Moderator: Ulrich

cyberdoro
Beiträge: 43
Registriert: So 29. Okt 2023, 11:31
Hat sich bedankt: 1 Mal

Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Beitrag von cyberdoro »

Hallo

Kann ich mir den Schaltzustand vom Sonoff 4CHpro im Dashboard anzeigen lassen, wenn ja wie ?
Hallo,
ich bin Frank und bin Neu hier.

Online
Benutzeravatar
Ulrich
Administrator
Beiträge: 5537
Registriert: Sa 7. Nov 2015, 10:33
Wohnort: Essen
Hat sich bedankt: 124 Mal
Danksagung erhalten: 834 Mal

Re: Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Beitrag von Ulrich »

Nein, so einfach geht das nicht. Das müsstest du dir selber programmieren. Der Sonoff antwortet ja mit dem Schaltzustand. Das muss du dann auslesen.
Ich weiß aber jetzt auch nicht, in welchem Zusammenhang deine Frage steht.
-----------------------------------------------------
Ulrich . . . . . . . . [Projekt Administrator]

cyberdoro
Beiträge: 43
Registriert: So 29. Okt 2023, 11:31
Hat sich bedankt: 1 Mal

Re: Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Beitrag von cyberdoro »

Naja .... ich würde es halt gerne im Dashboard sehen, welcher Kanal grade an ist.

Bei einem Sonoff POW kann ich mir das ja aus der Datenbank holen.... den aktuellen schaltzustand und somit sehe ich das er an ist
Hallo,
ich bin Frank und bin Neu hier.

Benutzeravatar
mr.big
Beiträge: 485
Registriert: Mi 7. Sep 2022, 12:12
Wohnort: tief im Osten...
Hat sich bedankt: 13 Mal
Danksagung erhalten: 96 Mal

Re: Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Beitrag von mr.big »

:D KI . sagt folgendes dazu:


Hier ist ein Beispiel-Skript, das Sie verwenden können, um den Status aller 4 Kanäle eines Sonoff 4CH Pro mittels Python abzurufen und in Variablen zu speichern. Das Skript verwendet die Bibliotheken paho-mqtt und json. Sie benötigen auch einen laufenden Mosquitto-Server und ein Tasmota Sonoff 4CH Pro-Gerät, das über das MQTT-Protokoll kommuniziert. Das Skript ist so konzipiert, dass es Daten von einem Tasmota-Gerät abruft, das über das MQTT-Protokoll kommuniziert, und diese Daten in Variablen speichert. Sie müssen das Skript anpassen, um es an Ihre spezifischen Anforderungen anzupassen. Bitte beachten Sie, dass ich keine Garantie für die Richtigkeit oder Vollständigkeit des Skripts geben kann.

Python
KI-generierter Code. Überprüfen und sorgfältig verwenden. Weitere Informationen zu häufig gestellten Fragen.

Code: Alles auswählen

import paho.mqtt.client as mqtt
import json
from influxdb import InfluxDBClient

# MQTT settings
MQTT_BROKER = "localhost"
MQTT_PORT = 1883
MQTT_TOPIC = "tele/sonoff_4ch_pro/STATE"

# InfluxDB settings
INFLUXDB_HOST = "localhost"
INFLUXDB_PORT = 8086
INFLUXDB_USERNAME = "admin"
INFLUXDB_PASSWORD = "admin"
INFLUXDB_DATABASE = "mydb"

# Connect to MQTT broker
client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT, 60)

# Connect to InfluxDB
influxdb_client = InfluxDBClient(host=INFLUXDB_HOST, port=INFLUXDB_PORT, username=INFLUXDB_USERNAME, password=INFLUXDB_PASSWORD, database=INFLUXDB_DATABASE)

# Define callback function for MQTT message
def on_message(client, userdata, message):
    # Decode JSON payload
    payload = json.loads(message.payload.decode())
    # Extract channel status
    channel1 = payload["POWER1"]
    channel2 = payload["POWER2"]
    channel3 = payload["POWER3"]
    channel4 = payload["POWER4"]
    # Print channel status
    print("Channel 1: " + channel1)
    print("Channel 2: " + channel2)
    print("Channel 3: " + channel3)
    print("Channel 4: " + channel4)
    # Write data to InfluxDB
    json_body = [
        {
            "measurement": "sonoff_4ch_pro",
            "tags": {
                "device": "sonoff_4ch_pro"
            },
            "fields": {
                "channel1": channel1,
                "channel2": channel2,
                "channel3": channel3,
                "channel4": channel4
            }
        }
    ]
    influxdb_client.write_points(json_body)

# Subscribe to MQTT topic
client.subscribe(MQTT_TOPIC)

# Set callback function for MQTT message
client.on_message = on_message

# Start MQTT loop
client.loop_forever()
Das Skript verwendet die Bibliotheken paho-mqtt und json, um Daten von einem Tasmota-Gerät mittels MQTT abzurufen, und die Bibliothek influxdb, um Daten in eine InfluxDB-Datenbank zu schreiben. Sie müssen das Skript an Ihre spezifischen Anforderungen anpassen, indem Sie die Werte für MQTT_BROKER, MQTT_PORT, MQTT_TOPIC, INFLUXDB_HOST, INFLUXDB_PORT, INFLUXDB_USERNAME, INFLUXDB_PASSWORD und INFLUXDB_DATABASE ändern.

Ich hoffe, das hilft Ihnen weiter.

cyberdoro
Beiträge: 43
Registriert: So 29. Okt 2023, 11:31
Hat sich bedankt: 1 Mal

Re: Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Beitrag von cyberdoro »

Habe mal was anderes Versucht um meine Daten zu bekommen und habe mir die https://solaranzeige.de/phpBB3/download ... nzeige.pdf angesehen. Bin mir nicht Sicher ob der Sonoff 4CH ein anderes Gerät ist, aber ich habe es mal versucht.
Die 4.user.config.php habe ich wie folgt geändert

Code: Alles auswählen

$Regler = "23";
$GeraeteNummer = "4";
$WR_IP = "192.168.2.194";
$WR_Port = "1883";
$WR_Adresse = "1";  
$Objekt = "Sonoff 4CH Daten";
$InfluxDB_local = true;
$InfluxDBLokal  = "solaranzeige4";
$MQTT = true;
$MQTTGeraet = "box4";
$MQTTAuswahl = "";
$MQTTTopic[1] = "solaranzeige/anzeige/4/#";
$Topic = "Sonoff-4CHPROR3";
wenn ich dann mosquitto_sub -h localhost -v -t "#" eingebe, bekomme ich ja die daten angezeigt die MQTT empfängt...oder ?

Code: Alles auswählen

cmnd/Sonoff-4CHPROR3/status 0
stat/Sonoff-4CHPROR3/STATUS {"Status":{"Module":0,"DeviceName":"Sonoff 4CHPROR3","FriendlyName":["Sonoff 4CHPROR3 01","Sonoff 4CHPROR3 02","Sonoff 4CHPROR3 03","Sonoff 4CHPROR3 04"],"Topic":"Sonoff-4CHPROR3","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Sonoff-4CHPROR3/STATUS1 {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Software/System restart","Uptime":"0T00:17:41","StartupUTC":"2023-11-09T08:14:40","Sleep":50,"CfgHolder":4617,"BootCount":29,"BCResetTime":"2023-11-07T17:25:55","SaveCount":742,"SaveAddress":"F9000"}}
stat/Sonoff-4CHPROR3/STATUS2 {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8285N08","CR":"445/699"}}
stat/Sonoff-4CHPROR3/STATUS3 {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
stat/Sonoff-4CHPROR3/STATUS4 {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":23,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"14325E","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Sonoff-4CHPROR3/STATUS5 {"StatusNET":{"Hostname":"Sonoff-4CHPROR3-6099","IPAddress":"192.168.2.163","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"80:64:6F:B9:17:D3","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Sonoff-4CHPROR3/STATUS6 {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_B917D3","MqttUser":"DVES_USER","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Sonoff-4CHPROR3/STATUS7 {"StatusTIM":{"UTC":"2023-11-09T08:32:21","Local":"2023-11-09T09:32:21","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Sonoff-4CHPROR3/STATUS10 {"StatusSNS":{"Time":"2023-11-09T09:32:21"}}
stat/Sonoff-4CHPROR3/STATUS11 {"StatusSTS":{"Time":"2023-11-09T09:32:21","Uptime":"0T00:17:41","UptimeSec":1061,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":21,"MqttCount":1,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":92,"Signal":-54,"LinkCount":1,"Downtime":"0T00:00:03"}}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.632 MQT: stat/Sonoff-4CHPROR3/STATUS = {"Status":{"Module":0,"DeviceName":"Sonoff 4CHPROR3","FriendlyName":["Sonoff 4CHPROR3 01","Sonoff 4CHPROR3 02","Sonoff 4CHPROR3 03","Sonoff 4CHPROR3 04"],"Topic":"Sonoff-4CHPROR3","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.640 MQT: stat/Sonoff-4CHPROR3/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Software/System restart","Uptime":"0T00:17:41","StartupUTC":"2023-11-09T08:14:40","Sleep":50,"CfgHolder":4617,"BootCount":29,"BCResetTime":"2023-11-07T17:25:55","SaveCount":742,"SaveAddress":"F9000"}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.647 MQT: stat/Sonoff-4CHPROR3/STATUS2 = {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8285N08","CR":"445/699"}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.654 MQT: stat/Sonoff-4CHPROR3/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.668 MQT: stat/Sonoff-4CHPROR3/STATUS4 = {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":23,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"14325E","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.675 MQT: stat/Sonoff-4CHPROR3/STATUS5 = {"StatusNET":{"Hostname":"Sonoff-4CHPROR3-6099","IPAddress":"192.168.2.163","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"80:64:6F:B9:17:D3","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.682 MQT: stat/Sonoff-4CHPROR3/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_B917D3","MqttUser":"DVES_USER","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.689 MQT: stat/Sonoff-4CHPROR3/STATUS7 = {"StatusTIM":{"UTC":"2023-11-09T08:32:21","Local":"2023-11-09T09:32:21","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.695 MQT: stat/Sonoff-4CHPROR3/STATUS10 = {"StatusSNS":{"Time":"2023-11-09T09:32:21"}}
stat/Sonoff-4CHPROR3/LOGGING 09:32:21.703 MQT: stat/Sonoff-4CHPROR3/STATUS11 = {"StatusSTS":{"Time":"2023-11-09T09:32:21","Uptime":"0T00:17:41","UptimeSec":1061,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":21,"MqttCount":1,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":92,"Signal":-54,"LinkCount":1,"Downtime":"0T00:00:03"}}}
solaranzeige/box4/status Online
solaranzeige/box4/period 0
solaranzeige/box4/powerstatus 0
solaranzeige/box4/temperatur 0
solaranzeige/box4/powerstatus0 0
solaranzeige/box4/powerstatus1 0
solaranzeige/box4/sensor 0
solaranzeige/box4/zentralertimestamp 1699518721
solaranzeige/box4/ac_frequenz 0
solaranzeige/box4/sonoffmodul 0
solaranzeige/box4/devicename Sonoff 4CHPROR3
solaranzeige/box4/produkt 13.2.0(tasmota)
solaranzeige/box4/hardware ESP8285N08
solaranzeige/box4/hostname Sonoff-4CHPROR3-6099
solaranzeige/box4/ac_spannung 0
solaranzeige/box4/ac_strom 0
solaranzeige/box4/ac_scheinleistung 0
solaranzeige/box4/ac_blindleistung 0
solaranzeige/box4/wattstundengesamt 0
solaranzeige/box4/wattstundengesamtheute 0
solaranzeige/box4/wattstundengesamtgestern 0
solaranzeige/box4/ac_leistung 0
solaranzeige/box4/regler 23
solaranzeige/box4/objekt Sonoff 4CH Daten
solaranzeige/box4/firmware 0
solaranzeige/box4/ac_ausgangsspannung 0
cmnd/Sonoff-POWR3/status 0
stat/Sonoff-POWR3/STATUS {"Status":{"Module":0,"DeviceName":"Sonoff POW R3","FriendlyName":["Sonoff-POW-R3"],"Topic":"Sonoff-POWR3","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Sonoff-POWR3/STATUS1 {"StatusPRM":{"Baudrate":4800,"SerialConfig":"8E1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Power On","Uptime":"0T19:55:42","StartupUTC":"2023-11-08T12:36:49","Sleep":50,"CfgHolder":4617,"BootCount":19,"BCResetTime":"2023-11-08T07:39:50","SaveCount":97,"SaveAddress":"F5000"}}
stat/Sonoff-POWR3/STATUS2 {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8266EX","CR":"378/699"}}
stat/Sonoff-POWR3/STATUS3 {"StatusLOG":{"SerialLog":0,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000680003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
stat/Sonoff-POWR3/STATUS4 {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":23,"ProgramFlashSize":1024,"FlashSize":4096,"FlashChipId":"1640EF","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Sonoff-POWR3/STATUS5 {"StatusNET":{"Hostname":"Sonoff-POWR3-2341","IPAddress":"192.168.2.162","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"EC:FA:BC:51:09:25","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Sonoff-POWR3/STATUS6 {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_510925","MqttUser":"DVES_USER","MqttCount":2,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Sonoff-POWR3/STATUS7 {"StatusTIM":{"UTC":"2023-11-09T08:32:31","Local":"2023-11-09T09:32:31","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Sonoff-POWR3/STATUS9 {"StatusPTH":{"PowerDelta":[0,0,0],"PowerLow":0,"PowerHigh":0,"VoltageLow":0,"VoltageHigh":0,"CurrentLow":0,"CurrentHigh":0}}
stat/Sonoff-POWR3/STATUS10 {"StatusSNS":{"Time":"2023-11-09T09:32:31","ENERGY":{"TotalStartTime":"2023-11-08T07:39:50","Total":0.034,"Yesterday":0.032,"Today":0.003,"Power":8,"ApparentPower":15,"ReactivePower":12,"Factor":0.57,"Voltage":234,"Current":0.062}}}
stat/Sonoff-POWR3/STATUS11 {"StatusSTS":{"Time":"2023-11-09T09:32:31","Uptime":"0T19:55:42","UptimeSec":71742,"Heap":23,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":2,"POWER":"ON","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":100,"Signal":-49,"LinkCount":1,"Downtime":"0T00:00:05"}}}
cmnd/Shelly1PM-01/status 0
stat/Shelly1PM-01/STATUS {"Status":{"Module":0,"DeviceName":"Shelly 1PM","FriendlyName":["Shelly1PM-01"],"Topic":"Shelly1PM-01","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Shelly1PM-01/STATUS1 {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Software/System restart","Uptime":"0T19:43:01","StartupUTC":"2023-11-08T12:49:40","Sleep":50,"CfgHolder":4617,"BootCount":51,"BCResetTime":"2023-11-03T09:35:14","SaveCount":235,"SaveAddress":"F7000"}}
stat/Shelly1PM-01/STATUS2 {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8266EX","CR":"387/699"}}
stat/Shelly1PM-01/STATUS3 {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
stat/Shelly1PM-01/STATUS4 {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":21,"ProgramFlashSize":1024,"FlashSize":2048,"FlashChipId":"15400B","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Shelly1PM-01/STATUS5 {"StatusNET":{"Hostname":"Shelly1PM-01-7285","IPAddress":"192.168.2.160","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"34:AB:95:39:5C:75","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Shelly1PM-01/STATUS6 {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_395C75","MqttUser":"DVES_USER","MqttCount":3,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Shelly1PM-01/STATUS7 {"StatusTIM":{"UTC":"2023-11-09T08:32:41","Local":"2023-11-09T09:32:41","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Shelly1PM-01/STATUS9 {"StatusPTH":{"PowerDelta":[0,0,0],"PowerLow":0,"PowerHigh":0,"VoltageLow":0,"VoltageHigh":0,"CurrentLow":0,"CurrentHigh":0}}
stat/Shelly1PM-01/STATUS10 {"StatusSNS":{"Time":"2023-11-09T09:32:41","Switch1":"OFF","ANALOG":{"Temperature":45.5},"ENERGY":{"TotalStartTime":"2023-11-03T09:39:11","Total":0.081,"Yesterday":0.000,"Today":0.000,"Power":0},"TempUnit":"C"}}
stat/Shelly1PM-01/STATUS11 {"StatusSTS":{"Time":"2023-11-09T09:32:41","Uptime":"0T19:43:01","UptimeSec":70981,"Heap":21,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":3,"POWER":"OFF","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":34,"Signal":-83,"LinkCount":1,"Downtime":"0T00:00:03"}}}
cmnd/Sonoff-4CHPROR3/status 0
solaranzeige/box1/zentralertimestamp 1699518791
stat/Sonoff-4CHPROR3/STATUS {"Status":{"Module":0,"DeviceName":"Sonoff 4CHPROR3","FriendlyName":["Sonoff 4CHPROR3 01","Sonoff 4CHPROR3 02","Sonoff 4CHPROR3 03","Sonoff 4CHPROR3 04"],"Topic":"Sonoff-4CHPROR3","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Sonoff-4CHPROR3/STATUS1 {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Software/System restart","Uptime":"0T00:18:21","StartupUTC":"2023-11-09T08:14:40","Sleep":50,"CfgHolder":4617,"BootCount":29,"BCResetTime":"2023-11-07T17:25:55","SaveCount":742,"SaveAddress":"F9000"}}
stat/Sonoff-4CHPROR3/STATUS2 {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8285N08","CR":"445/699"}}
stat/Sonoff-4CHPROR3/STATUS3 {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
solaranzeige/box1/sma SMA
solaranzeige/box1/tag0 02a0
solaranzeige/box1/gruppe 00000001
solaranzeige/box1/datenlaenge 588
solaranzeige/box1/sma_net_2 0010
solaranzeige/box1/protokoll_id 6069
solaranzeige/box1/susy-id 372
solaranzeige/box1/serno 3011820203
solaranzeige/box1/ticker_ms 3006699741
solaranzeige/box1/wh_bezug 5598577.2
solaranzeige/box1/wh_einspeisung 3601445.1
solaranzeige/box1/pf_leistung 0.963
solaranzeige/box1/frequenz 50.01
solaranzeige/box1/bezugphase_r 167.6
solaranzeige/box1/einspeisungphase_r 0
solaranzeige/box1/ac_leistung_r 167.6
solaranzeige/box1/ac_strom_r 1.634
solaranzeige/box1/ac_spannung_r 236.76
solaranzeige/box1/pf_r 0.915
solaranzeige/box1/bezugphase_s 456.2
solaranzeige/box1/einspeisungphase_s 0
solaranzeige/box1/ac_leistung_s 456.2
solaranzeige/box1/ac_strom_s 3.197
solaranzeige/box1/ac_spannung_s 234.34
solaranzeige/box1/pf_s 0.651
solaranzeige/box1/bezugphase_t 135.8
solaranzeige/box1/einspeisungphase_t 0
solaranzeige/box1/ac_leistung_t 135.8
solaranzeige/box1/ac_strom_t 1.237
solaranzeige/box1/ac_spannung_t 236.74
solaranzeige/box1/pf_t 0.482
solaranzeige/box1/firmware 0.2.A.0
solaranzeige/box1/ac_leistung 759.6
solaranzeige/box1/gesamterleistungsbedarf 9200022.3
solaranzeige/box1/bezug 759.6
solaranzeige/box1/einspeisung 0
solaranzeige/box1/ac_strom 6.068
solaranzeige/box1/regler 54
solaranzeige/box1/objekt Home Manager 2
solaranzeige/box1/modell Energy Meter
solaranzeige/box1/wattstundengesamtheute 0
stat/Sonoff-4CHPROR3/STATUS4 {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":22,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"14325E","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Sonoff-4CHPROR3/STATUS5 {"StatusNET":{"Hostname":"Sonoff-4CHPROR3-6099","IPAddress":"192.168.2.163","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"80:64:6F:B9:17:D3","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Sonoff-4CHPROR3/STATUS6 {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_B917D3","MqttUser":"DVES_USER","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Sonoff-4CHPROR3/STATUS7 {"StatusTIM":{"UTC":"2023-11-09T08:33:01","Local":"2023-11-09T09:33:01","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Sonoff-4CHPROR3/STATUS10 {"StatusSNS":{"Time":"2023-11-09T09:33:01"}}
stat/Sonoff-4CHPROR3/STATUS11 {"StatusSTS":{"Time":"2023-11-09T09:33:01","Uptime":"0T00:18:21","UptimeSec":1101,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":72,"Signal":-64,"LinkCount":1,"Downtime":"0T00:00:03"}}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.472 MQT: stat/Sonoff-4CHPROR3/STATUS = {"Status":{"Module":0,"DeviceName":"Sonoff 4CHPROR3","FriendlyName":["Sonoff 4CHPROR3 01","Sonoff 4CHPROR3 02","Sonoff 4CHPROR3 03","Sonoff 4CHPROR3 04"],"Topic":"Sonoff-4CHPROR3","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.478 MQT: stat/Sonoff-4CHPROR3/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Software/System restart","Uptime":"0T00:18:21","StartupUTC":"2023-11-09T08:14:40","Sleep":50,"CfgHolder":4617,"BootCount":29,"BCResetTime":"2023-11-07T17:25:55","SaveCount":742,"SaveAddress":"F9000"}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.483 MQT: stat/Sonoff-4CHPROR3/STATUS2 = {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8285N08","CR":"445/699"}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.488 MQT: stat/Sonoff-4CHPROR3/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":2,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.500 MQT: stat/Sonoff-4CHPROR3/STATUS4 = {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":22,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"14325E","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.508 MQT: stat/Sonoff-4CHPROR3/STATUS5 = {"StatusNET":{"Hostname":"Sonoff-4CHPROR3-6099","IPAddress":"192.168.2.163","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"80:64:6F:B9:17:D3","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.513 MQT: stat/Sonoff-4CHPROR3/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_B917D3","MqttUser":"DVES_USER","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.519 MQT: stat/Sonoff-4CHPROR3/STATUS7 = {"StatusTIM":{"UTC":"2023-11-09T08:33:01","Local":"2023-11-09T09:33:01","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.524 MQT: stat/Sonoff-4CHPROR3/STATUS10 = {"StatusSNS":{"Time":"2023-11-09T09:33:01"}}
stat/Sonoff-4CHPROR3/LOGGING 09:33:01.530 MQT: stat/Sonoff-4CHPROR3/STATUS11 = {"StatusSTS":{"Time":"2023-11-09T09:33:01","Uptime":"0T00:18:21","UptimeSec":1101,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":72,"Signal":-64,"LinkCount":1,"Downtime":"0T00:00:03"}}}
cmnd/Sonoff-POWR3/status 0
stat/Sonoff-POWR3/STATUS {"Status":{"Module":0,"DeviceName":"Sonoff POW R3","FriendlyName":["Sonoff-POW-R3"],"Topic":"Sonoff-POWR3","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
stat/Sonoff-POWR3/STATUS1 {"StatusPRM":{"Baudrate":4800,"SerialConfig":"8E1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota-DE.bin.gz","RestartReason":"Power On","Uptime":"0T19:56:16","StartupUTC":"2023-11-08T12:36:49","Sleep":50,"CfgHolder":4617,"BootCount":19,"BCResetTime":"2023-11-08T07:39:50","SaveCount":97,"SaveAddress":"F5000"}}
stat/Sonoff-POWR3/STATUS2 {"StatusFWR":{"Version":"13.2.0(tasmota)","BuildDateTime":"2023.10.19 09:07:29","Boot":31,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8266EX","CR":"378/699"}}
stat/Sonoff-POWR3/STATUS3 {"StatusLOG":{"SerialLog":0,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["RKS-55-24GHz",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000680003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
stat/Sonoff-POWR3/STATUS4 {"StatusMEM":{"ProgramSize":636,"Free":364,"Heap":21,"ProgramFlashSize":1024,"FlashSize":4096,"FlashChipId":"1640EF","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000407","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000080"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62,68","Sensors":"1,2,3,4,5,6","I2CDriver":"7"}}
stat/Sonoff-POWR3/STATUS5 {"StatusNET":{"Hostname":"Sonoff-POWR3-2341","IPAddress":"192.168.2.162","Gateway":"192.168.2.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.2.1","DNSServer2":"0.0.0.0","Mac":"EC:FA:BC:51:09:25","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
stat/Sonoff-POWR3/STATUS6 {"StatusMQT":{"MqttHost":"192.168.2.194","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_510925","MqttUser":"DVES_USER","MqttCount":2,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
stat/Sonoff-POWR3/STATUS7 {"StatusTIM":{"UTC":"2023-11-09T08:33:05","Local":"2023-11-09T09:33:05","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":"+01:00","Sunrise":"07:49","Sunset":"17:17"}}
stat/Sonoff-POWR3/STATUS9 {"StatusPTH":{"PowerDelta":[0,0,0],"PowerLow":0,"PowerHigh":0,"VoltageLow":0,"VoltageHigh":0,"CurrentLow":0,"CurrentHigh":0}}
stat/Sonoff-POWR3/STATUS10 {"StatusSNS":{"Time":"2023-11-09T09:33:05","ENERGY":{"TotalStartTime":"2023-11-08T07:39:50","Total":0.034,"Yesterday":0.032,"Today":0.003,"Power":8,"ApparentPower":14,"ReactivePower":12,"Factor":0.58,"Voltage":234,"Current":0.061}}}
stat/Sonoff-POWR3/STATUS11 {"StatusSTS":{"Time":"2023-11-09T09:33:05","Uptime":"0T19:56:16","UptimeSec":71776,"Heap":21,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":2,"POWER":"ON","Wifi":{"AP":1,"SSId":"RKS-55-24GHz","BSSId":"B2:8B:A9:36:99:26","Channel":11,"Mode":"11n","RSSI":100,"Signal":-48,"LinkCount":1,"Downtime":"0T00:00:05"}}}
Wenn ich dann die Kanäle 1 u 2 beim Sonoff 4CH schalte ändern sich auch die zwei eintrage

Code: Alles auswählen

solaranzeige/box4/powerstatus0 0
solaranzeige/box4/powerstatus1 0
aber leider nur 2 von 4. Die zwei werden auch in die Datenbank geschrieben.

Code: Alles auswählen

> select * from Service order by time desc Limit 20
name: Service
time                Powerstatus Powerstatus1 Powerstatus2 Status Temperatur
----                ----------- ------------ ------------ ------ ----------
1699518181000000000 1           1            1            Online 0
1699518121000000000 1           1            1            Online 0
1699518061000000000 1           1            1            Online 0
1699518001000000000 0           0            0            Online 0
1699517941000000000 0           0            0            Online 0
1699517880000000000 0           0            0            Online 0
1699517821000000000 0           0            0            Online 0
1699517102000000000 0           0            1            Online 0
1699517041000000000 0           0            1            Online 0
1699516980000000000 1           1            1            Online 0
1699516922000000000 0           0            0            Online 0
1699516861000000000 0           0            0            Online 0
Warum werden die andern 2 nicht angezeigt ? Oder habe ich nur Glück das es halb funktioniert ?
Hallo,
ich bin Frank und bin Neu hier.

cyberdoro
Beiträge: 43
Registriert: So 29. Okt 2023, 11:31
Hat sich bedankt: 1 Mal

Re: Schaltzustand vom Sonoff 4CH pro im Dashboard anzeigen lassen

Beitrag von cyberdoro »

mr.big hat geschrieben:
Mi 8. Nov 2023, 16:17
:D KI . sagt folgendes dazu:


Hier ist ein Beispiel-Skript, das Sie verwenden können, um den Status aller 4 Kanäle eines Sonoff 4CH Pro mittels Python abzurufen und in Variablen zu speichern. Das Skript verwendet die Bibliotheken paho-mqtt und json. Sie benötigen auch einen laufenden Mosquitto-Server und ein Tasmota Sonoff 4CH Pro-Gerät, das über das MQTT-Protokoll kommuniziert. Das Skript ist so konzipiert, dass es Daten von einem Tasmota-Gerät abruft, das über das MQTT-Protokoll kommuniziert, und diese Daten in Variablen speichert. Sie müssen das Skript anpassen, um es an Ihre spezifischen Anforderungen anzupassen. Bitte beachten Sie, dass ich keine Garantie für die Richtigkeit oder Vollständigkeit des Skripts geben kann.

Python
KI-generierter Code. Überprüfen und sorgfältig verwenden. Weitere Informationen zu häufig gestellten Fragen.

Code: Alles auswählen

import paho.mqtt.client as mqtt
import json
from influxdb import InfluxDBClient

# MQTT settings
MQTT_BROKER = "localhost"
MQTT_PORT = 1883
MQTT_TOPIC = "tele/sonoff_4ch_pro/STATE"

# InfluxDB settings
INFLUXDB_HOST = "localhost"
INFLUXDB_PORT = 8086
INFLUXDB_USERNAME = "admin"
INFLUXDB_PASSWORD = "admin"
INFLUXDB_DATABASE = "mydb"

# Connect to MQTT broker
client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT, 60)

# Connect to InfluxDB
influxdb_client = InfluxDBClient(host=INFLUXDB_HOST, port=INFLUXDB_PORT, username=INFLUXDB_USERNAME, password=INFLUXDB_PASSWORD, database=INFLUXDB_DATABASE)

# Define callback function for MQTT message
def on_message(client, userdata, message):
    # Decode JSON payload
    payload = json.loads(message.payload.decode())
    # Extract channel status
    channel1 = payload["POWER1"]
    channel2 = payload["POWER2"]
    channel3 = payload["POWER3"]
    channel4 = payload["POWER4"]
    # Print channel status
    print("Channel 1: " + channel1)
    print("Channel 2: " + channel2)
    print("Channel 3: " + channel3)
    print("Channel 4: " + channel4)
    # Write data to InfluxDB
    json_body = [
        {
            "measurement": "sonoff_4ch_pro",
            "tags": {
                "device": "sonoff_4ch_pro"
            },
            "fields": {
                "channel1": channel1,
                "channel2": channel2,
                "channel3": channel3,
                "channel4": channel4
            }
        }
    ]
    influxdb_client.write_points(json_body)

# Subscribe to MQTT topic
client.subscribe(MQTT_TOPIC)

# Set callback function for MQTT message
client.on_message = on_message

# Start MQTT loop
client.loop_forever()
Das Skript verwendet die Bibliotheken paho-mqtt und json, um Daten von einem Tasmota-Gerät mittels MQTT abzurufen, und die Bibliothek influxdb, um Daten in eine InfluxDB-Datenbank zu schreiben. Sie müssen das Skript an Ihre spezifischen Anforderungen anpassen, indem Sie die Werte für MQTT_BROKER, MQTT_PORT, MQTT_TOPIC, INFLUXDB_HOST, INFLUXDB_PORT, INFLUXDB_USERNAME, INFLUXDB_PASSWORD und INFLUXDB_DATABASE ändern.

Ich hoffe, das hilft Ihnen weiter.
Vielen Dank

Wenn sie mir noch sagen wie und wo ich das einbinden muss ;)
Hallo,
ich bin Frank und bin Neu hier.

Zurück zu „Überschuss Steuerung, Anlagenüberwachung, Anbindung an die Heizung, API Schnittstelle und vieles Andere mehr.“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 0 Gäste