home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.07k stars 29.73k forks source link

Can't add multiple Mqtt switches and covers #114653

Closed a-cesari closed 4 months ago

a-cesari commented 5 months ago

The problem

I'm trying to add several MQTT switches (via Zigbee2MQTT) and covers (via shelly MQTT) via configuration.yaml. The configurations is fine as all the devices (including availability and state reporting) work fine if added separately (i.e. commenting out the configuration for the others). However, when including all together, randomically some of them are displayed as not available or not reporting the state. The command topic is always fine. The issue seems that even if HA subscribe to the correct state topic (I can see it's subscribing from the log), it then doesn't receive any message (even if they are published on the broker. Again checked with Mqtt explorer). Also I can see that there are no messages HA side from the "MQTT info" panel of each device. It looks like HA go crazy when there are many MQTT topic to subscribe to.

What version of Home Assistant Core has the issue?

core-2024.3.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

MQTT

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

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

    # log level for MQTT integration
    homeassistant.components.mqtt: debug
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text-to-speech
tts:
  - platform: google_translate

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

homeassistant:
  auth_mfa_modules:
    - type: totp

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.28.0.0/16
panel_iframe:
  zigbee2mqtt:
    title: zigbee2mqtt
    icon: mdi:wrench
    url: https://z2mm.acesari.it
    require_admin: true   
mqtt:
  cover:
    !include mqtt_covers.yaml
  switch:
    !include mqtt_switches.yaml
#  sensor:
#    !include mqtt_sensors.yaml

The mqtt_switches.yaml file

 - name: "Corridoio"
    #availability_topic: "zigbee2mqttM/corridoio/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline"

    command_topic: "zigbee2mqttM/corridoio/set"
    state_topic: "zigbee2mqttM/corridoio"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}' 

    state_on: "ON"
    state_off: "OFF"
    unique_id: "switch_corridoio"
    device:
      identifiers: "Corridoio"
      name: "Corridoio"
      manufacturer: "Sonoff"
      model: "ZBMINI-L2"
    qos: 1
  - name: "Lampadario"
    #availability_topic: "zigbee2mqttM/lampadario/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline"

    command_topic: "zigbee2mqttM/lampadario/set"
    state_topic: "zigbee2mqttM/lampadario"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}' 

    state_on: "ON"
    state_off: "OFF"
    unique_id: "switch_lampadario"
    device:
      identifiers: "Lampadario"
      name: "Lampadario"
      manufacturer: "Sonoff"
      model: "ZBMINI-L2"
    qos: 1

  - name: "Cucina"
    command_topic: "zigbee2mqttM/cucina/set"
    state_topic: "zigbee2mqttM/cucina"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}'
    #availability_topic: "zigbee2mqttM/cucina/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline" 
    state_on: "ON"
    state_off: "OFF"
    unique_id: "switch_cucina"
    device:
      identifiers: "Cucina"
      name: "Cucina"
      manufacturer: "Sonoff"
      model: "ZBMINI-L2"
    qos: 1
  - name: "Mensola"
    #availability_topic: "zigbee2mqttM/mensola/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline"

    command_topic: "zigbee2mqttM/mensola/set"
    state_topic: "zigbee2mqttM/mensola"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}'

    state_on: "ON"
    state_off: "OFF"
    unique_id: "switch_mensola"
    device:
      identifiers: "Mensola"
      name: "Mensola"
      manufacturer: "Sonoff"
      model: "ZBMINI"
    qos: 1
  - name: "Ingresso"
    command_topic: "zigbee2mqttM/ingresso/set"
    state_topic: "zigbee2mqttM/ingresso"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}'

    #availability_topic: "zigbee2mqttM/ingresso/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline"

    state_on: "ON"
    state_off: "OFF"
    unique_id: "switch_ingresso"
    device:
      identifiers: "Ingresso"
      name: "Ingresso"
      manufacturer: "Sonoff"
      model: "ZBMINI"
    qos: 1
  - name: "Piantana"
    command_topic: "zigbee2mqttM/piantana/set"
    state_topic: "zigbee2mqttM/piantana"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}'

    state_on: "ON"
    state_off: "OFF"
    #availability_topic: "zigbee2mqttM/piantana/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline"

    unique_id: "switch_piantana"
    device:
      identifiers: "Piantana"
      name: "Piantana"
      manufacturer: "Sonoff"
      model: "ZBMINI"
    qos: 1
  - name: "Abat Jour"
    #availability_topic: "zigbee2mqttM/abat_jour/availability"
    #availability_template: '{{ value_json["state"] }}'
    #payload_available: "online"
    #payload_not_available: "offline"

    command_topic: "zigbee2mqttM/abat_jour/set"
    state_topic: "zigbee2mqttM/abat_jour"
    payload_on: '{"state": "ON"}'
    payload_off: '{"state": "OFF"}'
    value_template: '{{ value_json["state"] }}'

    state_on: "ON"
    state_off: "OFF"
    unique_id: "switch_abat_jour"
    device:
      identifiers: "Abat Jour"
      name: "Abat Jour"
      manufacturer: "Sonoff"
      model: "ZBMINI"
    qos: 1

  - name: "Faretto 1"
    #command_topic: "maglie_faretti_soggiorno/rpc"
    #payload_on: '{"id":"switch-on","src":"shellyplus2pm-0cdc7efa8a30/status","method":"Switch.Set","params": {"id":0,"on":true}}'
    #payload_off: '{"id":"switch-off","src":"shellyplus2pm-0cdc7efa8a30/status","method":"Switch.Set","params": {"id":0,"on":false}}'

    command_topic: "maglie_faretti_soggiorno/command/switch:0"
    payload_on: 'on'
    payload_off: 'off' 

    state_topic: "maglie_faretti_soggiorno/status/switch:0"
    value_template: "{{  value_json.output }}"

    #value_template: "{{ 'true' if value_json['output'] == true else 'false' }}"
    #state_topic: "maglie_faretti_soggiorno/rpc"

    state_on: true
    state_off: false
    #availability_topic: "maglie_faretti_soggiorno/online"
    #payload_available: 'true'
    #payload_not_available: 'false'
    optimistic: false
    unique_id: "faretto_soggiorno_1"
    qos: 1
    device:
      identifiers: "Faretto_Soggiorno_1"
      name: "Faretto Soggiorno 1"
      manufacturer: "Shelly"
      model: "Plus2PM"

  - name: "Faretto 2"
    #command_topic: "maglie_faretti_soggiorno/rpc"
    #payload_on: '{"id":"switch-on","src":"shellyplus2pm-0cdc7efa8a30/status","method":"Switch.Set","params": {"id":1,"on":true}}'
    #payload_off: '{"id":"switch-off","src":"shellyplus2pm-0cdc7efa8a30/status","method":"Switch.Set","params": {"id":1,"on":false}}'

    command_topic: "maglie_faretti_soggiorno/command/switch:1"
    payload_on: 'on'
    payload_off: 'off'

    state_topic: "maglie_faretti_soggiorno/status/switch:1"
    #value_template: "{{ 'true' if value_json['output'] == true else 'false' }}"
    value_template: "{{  value_json.output }}"
    state_on: true
    state_off: false
    #availability_topic: "maglie_faretti_soggiorno/online"
    #payload_available: 'true'
    #payload_not_available: 'false'
    optimistic: false
    unique_id: "faretto_soggiorno_2"
    qos: 1
    device:
      identifiers: "Faretto_Soggiorno_2"
      name: "Faretti Soggiorno 2"
      manufacturer: "Shelly"
      model: "Plus2PM"

Anything in the logs that might be useful for us?


home-assistant-maglie  | 2024-04-02 13:29:57.670 INFO (MainThread) [homeassistant.components.device_tracker] Setting up mqtt.device_tracker
home-assistant-maglie  | 2024-04-02 13:29:57.718 INFO (MainThread) [homeassistant.components.light] Setting up mqtt.light
home-assistant-maglie  | 2024-04-02 13:29:57.726 INFO (MainThread) [homeassistant.components.switch] Setting up mqtt.switch
home-assistant-maglie  | 2024-04-02 13:29:57.759 INFO (MainThread) [homeassistant.components.camera] Setting up mqtt.camera
home-assistant-maglie  | 2024-04-02 13:29:57.766 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to tapparella_sala/online, mid: 1, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:57.766 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to tapparella_sala/status/cover:0, mid: 1, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:57.766 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to tapparella_silvia/online, mid: 1, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:57.766 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to tapparella_silvia/status/cover:0, mid: 1, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:57.766 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to tapparella_cameretta/online, mid: 1, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:57.766 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to tapparella_cameretta/status/cover:0, mid: 1, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:57.780 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on tapparella_sala/online (qos=1): b'true'
home-assistant-maglie  | 2024-04-02 13:29:57.780 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on tapparella_silvia/online (qos=1): b'true'
home-assistant-maglie  | 2024-04-02 13:29:57.781 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on tapparella_cameretta/online (qos=1): b'true'
home-assistant-maglie  | 2024-04-02 13:29:58.685 INFO (MainThread) [homeassistant.setup] Setting up radio_browser
home-assistant-maglie  | 2024-04-02 13:29:58.686 INFO (MainThread) [homeassistant.setup] Setup of domain radio_browser took 0.0 seconds
home-assistant-maglie  | 2024-04-02 13:29:58.712 INFO (MainThread) [homeassistant.setup] Setting up backup
home-assistant-maglie  | 2024-04-02 13:29:58.714 INFO (MainThread) [homeassistant.setup] Setup of domain backup took 0.0 seconds
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to maglie_faretti_soggiorno/online, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to maglie_faretti_soggiorno/status/switch:0, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to maglie_faretti_soggiorno/status/switch:1, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to zigbee2mqttM/corridoio, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to zigbee2mqttM/cucina, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to zigbee2mqttM/mensola, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.748 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing to zigbee2mqttM/ingresso, mid: 2, qos: 1
home-assistant-maglie  | 2024-04-02 13:29:58.786 INFO (MainThread) [homeassistant.setup] Setting up mobile_app
home-assistant-maglie  | 2024-04-02 13:29:58.790 INFO (MainThread) [homeassistant.setup] Setup of domain mobile_app took 0.0 seconds
home-assistant-maglie  | 2024-04-02 13:29:58.793 INFO (MainThread) [homeassistant.setup] Setting up notify
home-assistant-maglie  | 2024-04-02 13:29:58.793 INFO (MainThread) [homeassistant.setup] Setup of domain notify took 0.0 seconds
home-assistant-maglie  | 2024-04-02 13:29:58.801 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up mobile_app.binary_sensor
home-assistant-maglie  | 2024-04-02 13:29:58.806 INFO (MainThread) [homeassistant.components.device_tracker] Setting up mobile_app.device_tracker
home-assistant-maglie  | 2024-04-02 13:29:58.811 INFO (MainThread) [homeassistant.components.sensor] Setting up mobile_app.sensor
home-assistant-maglie  | 2024-04-02 13:29:58.835 INFO (MainThread) [homeassistant.components.notify] Setting up notify.mobile_app
home-assistant-maglie  | 2024-04-02 13:29:58.842 INFO (MainThread) [homeassistant.setup] Setting up default_config
home-assistant-maglie  | 2024-04-02 13:29:58.842 INFO (MainThread) [homeassistant.setup] Setup of domain default_config took 0.0 seconds
home-assistant-maglie  | 2024-04-02 13:29:58.858 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on maglie_faretti_soggiorno/online (qos=1): b'true'
home-assistant-maglie  | 2024-04-02 13:29:58.893 INFO (MainThread) [homeassistant.bootstrap] Home Assistant initialized in 10.03s
home-assistant-maglie  | 2024-04-02 13:29:58.894 INFO (MainThread) [homeassistant.core] Starting Home Assistant

Additional information

No response

mib1185 commented 5 months ago

You may want to show us your configurations (working and not working ones)

a-cesari commented 5 months ago

Thank @mib1185 for taking on this. I added some more info. Let me know if it's enough or if you need something else in particular

home-assistant[bot] commented 5 months ago

Hey there @emontnemery, @jbouwh, mind taking a look at this issue as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `mqtt` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mqtt` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


mqtt documentation mqtt source (message by IssueLinks)

jbouwh commented 4 months ago

See: https://www.home-assistant.io/docs/configuration/splitting_configuration/

May be you have an indention problem. I tried to reproduce, (did not use your config as it is not valid), but can only conclude that it works as expected. So this not an issue with Home Assistant.