MQTT Konfiguration Zweck
MQTT-Broker-basierte Kommunikation als Alternative zur Home Assistant API für komplexe Netzwerk-Setups. Wann MQTT nutzen?
Kein Home Assistant: Andere Hausautomations-Systeme
Mehrere Systeme: Node-RED, OpenHAB, etc. parallel
Eigene Software: Custom Applications mit MQTT
Netzw...
Code-Vorschau
Haupt-Konfiguration
Tipp: Markieren & ⌘/Ctrl + C zum Kopieren
configuration.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# MQTT-Konfiguration# Alternative zur Home Assistant API für Broker-basierte Kommunikationmqtt:broker:!secret mqtt_broker # IP-Adresse oder Hostname des MQTT-Brokersport:1883# Standard MQTT Port (8883 für SSL)username:!secret mqtt_username
password:!secret mqtt_password
# Client-ID (muss für jedes Gerät eindeutig sein)client_id:"${device_name}_${mac_suffix}"# Discovery-Einstellungen für Home Assistantdiscovery:truediscovery_retain:falsediscovery_prefix:"homeassistant"discovery_unique_id_generator: mac # mac, device_name# Topic-Präfix für dieses Gerättopic_prefix:"esphome/${device_name}"# Verbindungseinstellungenkeepalive: 15s
reboot_timeout: 5min
# SSL/TLS-Einstellungen (für sichere Verbindung auskommentieren)# ssl_fingerprints:# - "SHA1 Fingerprint of your MQTT broker certificate"# # # Oder Zertifikats-Verifizierung verwenden# certificate_authority: | # -----BEGIN CERTIFICATE-----
# ... your CA certificate here ...
# -----END CERTIFICATE-----# Last Will and Testament (Offline-Nachricht)will_message:topic:"${topic_prefix}/status"payload:"offline"retain:true# Birth-Nachricht (Online-Nachricht)birth_message:topic:"${topic_prefix}/status"payload:"online"retain:true# Alle MQTT-Nachrichten protokollieren (für Debugging)# log_topic:# topic: "${topic_prefix}/debug"# level: INFO# Optional: MQTT-spezifische Sensoren und Steuerungensensor:-platform: mqtt_subscribe
name:"${friendly_name} External Temperature"id: external_temp
topic:"weather/temperature"unit_of_measurement:"°C"device_class: temperature
state_class: measurement
filters:-heartbeat: 300s # Als nicht verfügbar markieren wenn 5 Min. kein Update# Optional: Eigene Daten zu MQTT publiziereninterval:-interval: 60s
then:-mqtt.publish:topic:"${topic_prefix}/custom/uptime"payload:!lambda|- return to_string(id(uptime_sensor).state);
retain:true# Optional: MQTT-Befehle abonnierenmqtt:# ... (main config above)# Eigene Befehl-Abonnementson_message:-topic:"${topic_prefix}/command/restart"then:-logger.log:"Restart command received via MQTT"-delay: 1s
-restart:-topic:"${topic_prefix}/command/led/set"then:-logger.log:format:"LED command: %s"args:['x']-if:condition:lambda:'return x == "ON";'then:-output.turn_on: status_led
else:-output.turn_off: status_led
# Benötigter Uptime-Sensor für obiges Beispielsensor:-platform: uptime
name:"${friendly_name} Uptime"id: uptime_sensor
update_interval: 60s