How to add mqtt topics in configuration.yaml correctly?

Hi,

i try to add virtual switches over mqtt with node-red. The switches are set and i want to add them in home assistant.

Now i red the documentation, many tutorials, examples and more. nothing workes.

This is the actual config for two switches:

# MQTT
switch:
- platform: mqtt
  entity_id: p0-on
  name: "Ladestation 1 On"
  state_topic: "tele/f/strom/battery-1-strom-control/STATE/POWER" # Topic to read the current state
  command_topic: "tele/f/control/p0-on"
  optimistic: false
  qos: 0
  state_on: "ON"
  state_off: "OFF"
  payload_on: true # or "on", depending on your MQTT device
  payload_off: false # or "off", depending on your MQTT device
  retain: true # or false if you want to wait for changes

- platform: mqtt
  entity_id: p1-on
  name: "Ladestation 2 On"
  state_topic: "tele/f/strom/battery-2-strom-control/STATE/POWER" # Topic to read the current state
  command_topic: "tele/f/control/p1-on"
  optimistic: false
  qos: 0
  state_on: "ON"
  state_off: "OFF"
  payload_on: true # or "on", depending on your MQTT device
  payload_off: false # or "off", depending on your MQTT device
  retain: true # or false if you want to wait for changes

i tried without plaform: mqtt
i tried with switch: on every switch
i tried to fix it with chatgpt.

I hope you can help me.

Thanks

mqtt:
  switch:
  - entity_id: p0-on
    name: "Ladestation 1 On"
    state_topic: "tele/f/strom/battery-1-strom-control/STATE/POWER" # Topic to read the current state
    command_topic: "tele/f/control/p0-on"
    optimistic: false
    qos: 0
    state_on: "ON"
    state_off: "OFF"
    payload_on: true # or "on", depending on your MQTT device
    payload_off: false # or "off", depending on your MQTT device
    retain: true # or false if you want to wait for changes

  - entity_id: p1-on
    name: "Ladestation 2 On"
    state_topic: "tele/f/strom/battery-2-strom-control/STATE/POWER" # Topic to read the current state
    command_topic: "tele/f/control/p1-on"
    optimistic: false
    qos: 0
    state_on: "ON"
    state_off: "OFF"
    payload_on: true # or "on", depending on your MQTT device
    payload_off: false # or "off", depending on your MQTT device
    retain: true # or false if you want to wait for changes
The system cannot restart because the configuration is not valid: Invalid config for [mqtt]: [entity_id] is an invalid option for [mqtt]. Check: mqtt->mqtt->0->switch->0->entity_id. (See /config/configuration.yaml, line 28).

Complete Config:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Reverse Proxy
http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 10.0.0.31
    

# MQTT
mqtt:
  switch:
  - entity_id: p0-on
    name: "Ladestation 1 On"
    state_topic: "tele/f/strom/battery-1-strom-control/STATE/POWER" # Topic to read the current state
    command_topic: "tele/f/control/p0-on"
    optimistic: false
    qos: 0
    state_on: "ON"
    state_off: "OFF"
    payload_on: true # or "on", depending on your MQTT device
    payload_off: false # or "off", depending on your MQTT device
    retain: true # or false if you want to wait for changes
  
  - entity_id: p1-on
    name: "Ladestation 2 On"
    state_topic: "tele/f/strom/battery-2-strom-control/STATE/POWER" # Topic to read the current state
    command_topic: "tele/f/control/p1-on"
    optimistic: false
    qos: 0
    state_on: "ON"
    state_off: "OFF"
    payload_on: true # or "on", depending on your MQTT device
    payload_off: false # or "off", depending on your MQTT device
    retain: true # or false if you want to wait for changes

Yes, you will have to remove entity_id

Maybe you meant object_id instead of entity_id? Or maybe unique_id?

object_id string (optional)

Used instead of `name` for automatic generation of `entity_id`
1 Like

here it begins to confuse me. which variable i put after “-”?

mqtt:
  switch:
  -  
    name: "Ladestation 1 On"
    state_topic: "tele/f/strom/battery-1-strom-control/STATE/POWER" # Topic to read the current state
    command_topic: "tele/f/control/p0-on"
    optimistic: false
    qos: 0
    state_on: "ON"
    state_off: "OFF"
    payload_on: true # or "on", depending on your MQTT device
    payload_off: false # or "off", depending on your MQTT device
    retain: true # or false if you want to wait for changes

With object_id it works. Thanks!

Last Question.

can i change this thunder icons to a switch like the other switches under the thunders in “monirtoring”?