Mqtt2server mit Home Assistant Verbindungsprobleme

Begonnen von andre07, 29 September 2026, 12:43:34

Vorheriges Thema - Nächstes Thema

rudolfkoenig

Ich habe jetzt die subscription Options (RetainAsPublished, NoLocal, RetainHandling:0,2) implementiert.

Hat das nicht implementierte SubscriptionIdentifierAvailable ausser der Meldung noch weitere Konsequenzen?

rudolfkoenig

Ich habe jetzt SubscriptionIdentifier hinzugefuegt.
Testen ist schwierig:
- keine Ahnung, wie ich das mit dem python Programm spezifizieren und ausgeben kann.
- mit mosquitto_sub kann ich es spezifizieren, es wird aber beim Empfang nicht ausgegeben.

Immherin: keiner der beiden ist abgestuerzt, und laut "verbose 5" habe ich den Identifier versendet.

andre07

Ein Test mit dem script lief eigentlich erfolgreich aber als ich den Broker auf fhem umstellte waren die Entitäten auch mit deinen Patch nicht verfügbar,obwohl die Nachrichten laut Diagnose korrekt zugeordnet ankamen.Werde also mit der neuen Version nochmal neu testen und berichten. Script zum nachstellen habe ich etwas abgeändert.# MQTT5 Subscription-Identifier-Test (paho-mqtt 2.x, wie Home Assistant)
# pip install "paho-mqtt>=2"
# Aufruf: python3 mqtt5_subid.py HOST PORT USER PASS TOPIC
import sys, paho.mqtt.client as mqtt
from paho.mqtt.properties import Properties
from paho.mqtt.packettypes import PacketTypes
host, port, user, pw, topic = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4], sys.argv[5]
c = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="subid-test", protocol=mqtt.MQTTv5)
c.username_pw_set(user, pw)
def on_connect(cl, ud, flags, rc, props):
    print("CONNACK:", rc, props)
    sp = Properties(PacketTypes.SUBSCRIBE)
    sp.SubscriptionIdentifier = 42
    cl.subscribe(topic, properties=sp)
c.on_connect = on_connect
c.on_message = lambda cl, ud, m: print("r%d" % m.retain, m.topic, m.payload[:40], m.properties)
c.connect(host, port, 60)
c.loop_forever()
 

andre07

Hallo ,

hab es doch gleich getestet mit dem script.Sieht gut aus im CONNACK steht jetzt SubscriptionIdentifierAvailable:1 und bei jeder Nachricht kommt der SubscriptionIdentifier hatte 42 gesetzt, kommt auch überall 42 an. Live Nachrichten kommen mit retain r0, passt.

Eine Sache ist mir aufgefallen: die gespeicherten retain Nachrichten die direkt nach dem subscribe kommen, haben bei MQTT 5 jetzt auch retain 0. Gestern kamen die noch mit r1. Mit 3.1.1 mosquitto_sub -V mqttv311 kommen sie richtig mit r1.

Soweit ich das verstehe muss bei den gespeicherten Nachrichten nach einem subscribe das retain immer r0 sein, RetainAsPublished gilt nur für neue Nachrichten die weitergeleitet werden.Man sieht das gut an den zeiten die ersten werte kamen sofort mit r0 und die live daten danach auch mit r1
CONNACK: Success [SessionExpiryInterval : 0, MaximumQoS : 1, SubscriptionIdentifierAvailable : 1, SharedSubscriptionAvailable : 0]
18:11:35 r0 foxess_m1/60M28010557L581/active_power_limit/state b'100' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/status b'online' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/state b'{"serial":"60M28010557L581","r_power_w":' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/availability b'online' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/power b'12' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/ac/power b'12' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/ac/export_power b'12' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/ac/voltage b'227.531' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/ac/current b'0.053' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/ac/frequency b'49.969' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/temperature b'27.22' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/yieldtotal b'286.266' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/0/status b'running' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/1/power b'4' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/1/voltage b'29.98' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/1/current b'0.16' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/2/power b'8' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/2/voltage b'29.992' [SubscriptionIdentifier : [42]]
18:11:35 r0 foxess_m1/60M28010557L581/2/current b'0.266' [SubscriptionIdentifier : [42]]
18:11:46 r0 foxess_m1/60M28010557L581/state b'{"serial":"60M28010557L581","r_power_w":' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/availability b'online' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/power b'11' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/ac/power b'11' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/ac/export_power b'11' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/ac/voltage b'227.719' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/ac/current b'0.047' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/ac/frequency b'49.961' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/temperature b'27.03' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/yieldtotal b'286.266' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/status b'running' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/1/power b'4' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/1/voltage b'29.98' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/1/current b'0.15' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/2/power b'7' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/2/voltage b'30.133' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/2/current b'0.252' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/sequence b'' [SubscriptionIdentifier : [42]]
18:11:49 r0 foxess_m1/60M28010557L581/0/status_code b'' [SubscriptionIdentifier : [42]]
18:13:17 r0 foxess_m1/60M28010557L581/state b'{"serial":"60M28010557L581","r_power_w":' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/availability b'online' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/power b'11' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/ac/power b'10' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/ac/export_power b'10' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/ac/voltage b'227.5' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/ac/current b'0.043' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/ac/frequency b'49.953' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/temperature b'26.88' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/yieldtotal b'286.273' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/status b'running' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/1/power b'4' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/1/voltage b'30.176' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/1/current b'0.133' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/2/power b'7' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/2/voltage b'30.039' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/2/current b'0.236' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/sequence b'' [SubscriptionIdentifier : [42]]
18:13:20 r0 foxess_m1/60M28010557L581/0/status_code b'' [SubscriptionIdentifier : [42]]
18:14:48 r0 foxess_m1/60M28010557L581/state b'{"serial":"60M28010557L581","r_power_w":' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/availability b'online' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/power b'9' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/ac/power b'10' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/ac/export_power b'10' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/ac/voltage b'227.125' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/ac/current b'0.043' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/ac/frequency b'49.969' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/temperature b'26.69' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/yieldtotal b'286.273' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/status b'running' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/1/power b'3' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/1/voltage b'29.98' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/1/current b'0.129' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/2/power b'6' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/2/voltage b'30.086' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/2/current b'0.225' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/sequence b'' [SubscriptionIdentifier : [42]]
18:14:51 r0 foxess_m1/60M28010557L581/0/status_code b'' [SubscriptionIdentifier : [42]]
18:16:20 r0 foxess_m1/60M28010557L581/state b'{"serial":"60M28010557L581","r_power_w":' [SubscriptionIdentifier : [42]]
18:16:20 r0 foxess_m1/60M28010557L581/availability b'online' [SubscriptionIdentifier : [42]]
18:16:22 r0 foxess_m1/60M28010557L581/0/power b'9' [SubscriptionIdentifier : [42]]
18:16:22 r0 foxess_m1/60M28010557L581/0/ac/power b'9' [SubscriptionIdentifier : [42]]
18:16:22 r0 foxess_m1/60M28010557L581/0/ac/export_power b'9' [SubscriptionIdentifier : [42]]

Gruß Andre

rudolfkoenig

ZitatEine Sache ist mir aufgefallen: die gespeicherten retain Nachrichten die direkt nach dem subscribe kommen, haben bei MQTT 5 jetzt auch retain 0. Gestern kamen die noch mit r1.
Das liegt an dem Subscription Options (https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169), die ich gestern implementiert habe.
Kommt per Voreinstellung mit allen Werten als 0, also auch RetainAsPublished=0:
ZitatIf the value of Retain As Published subscription option is set to 0, the Server MUST set the RETAIN flag to 0 when forwarding an Application Message regardless of how the RETAIN flag was set in the received PUBLISH packet.

rudolfkoenig

ZitatSoweit ich das verstehe muss bei den gespeicherten Nachrichten nach einem subscribe das retain immer r0 sein, RetainAsPublished gilt nur für neue Nachrichten die weitergeleitet werden.Man sieht das gut an den zeiten die ersten werte kamen sofort mit r0 und die live daten danach auch mit r1
(Sorry, zu spaet gelesen)
Bin nicht sicher, ob ich das Zusammenspiel von RetainAsPublished und RetainHandling richtig verstehe, ich finde die Spezifikation uebertreibt da etwas. Wenn die aktuelle Implementierung ein Problem ist, dann werde ich laenger darueber nachdenken.

andre07

#21
könnte dabei helfen das ein Client am Flag erkennt, ob ein Wert ein alter, gespeicherter Stand oder eine frische Meldung ist. Ob HA diese stelle auswertet für meine Devices weiß ich jetzt auch nicht genau kann aber auch ein Grund sein warum meine Entitäten in HA nicht funktionieren. Bei V5 Clients könnte es wichtig sein, weil die am Flag erkennen ob es ein alter gespeicherter Wert ist oder ein neuer. Eilt jetzt aber nicht. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html siehe 3.8.3.1, Beschreibung von Retain As Published
Andre

PS: Morgen werde ich mal HA im Debug loggen sowie Mqtt2Server der Unterschied der logs ist dann vieleicht die Lösung ehe ich hier weiter nur vermute.