Please I really need your help with my mqtt that go crazy

Dear friends of the community, I really need your help. A year ago I started automating my home with home assistant.
I am very satisfied but I have a big problem with mqtt. I have about 20 sonoffs (basic, touch, bridge … etc.). The sonoffs sometimes go crazy (for example if the server restarts or if I change something in the settings). When this happens I have to do tests, tests, change settings, cancel the configuration and after hours of work without reason they come back online.
They go crazy: in the home assistant they are unavailable and in tasmota admin they go online and off-line like a Christmas tree.
Please help me, I really like Home Assistant but if I don’t solve this problem I will have to abandon all the projects because my wife will kill me. I automated the whole house and when I don’t have the sonoffs available, nothing works anymore.

Post config for sonoff switches

… and as much as possible about your HA setup.

Thank you tmjpugh, this is the configuration of a sonoff basic

Thank you AhmadK this is my configuration.yaml
Sorry for the comments in Italian and thanks again

 homeassistant:
  # Name of the location where Home Assistant is running
  name: XXXXX XXXXX
  # Location required to calculate the time the sun rises and sets
  latitude: XX.XXXXXXX
  longitude: XX.XXXXXXX
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 91
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Rome
  # Customization file
  customize: !include customize.yaml
ffmpeg:
  
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:
  api_password: !secret http_pwd
  base_url: https://xxxxxxx.xxxxxxxxxx.xxxxx:8123
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

# speedtest
speedtestdotnet:
  scan_interval:
    hours: 1
  monitored_conditions:
    - ping
    - download
    - upload

# Alexa api
api:
alexa:
  smart_home:

# Piattaforma DarkSky per le previsioni del tempo
weather:
  - platform: darksky
    api_key: !secret darksky_api
    #language: it
    mode: daily

# Tracking Dispositivi
device_tracker:
  - platform: nmap_tracker
    hosts:
      - 192.168.1.10-49
      - !secret iphone_matteo_ip
      - !secret iphone_daniela_ip
    scan_options: " --privileged -sP "
    interval_seconds: 30

person:
  - name: Matteo
    id: matteo80
    user_id: XXXXXXXXXXXXXXXXXX
    device_trackers:
      - device_tracker.iphonedimatteo
  - name: Daniela
    id: daniela78
    user_id: XXXXXXXXXXXXXXXXXX
    device_trackers:
      - device_tracker.iphonedidaniela_homenet_telecomitalia_it

#### SMARTLIFE ####
tuya:
  username: !secret mia_email
  password: XXXXXXXXX
  country_code: 39
  platform: smart_life

#### ALLARM ####
alarm_control_panel:
  - platform: manual
    name: Allarme Casa
    code: !secret antifurto_code
    trigger_time: 300
    disarmed:
      trigger_time: 0
    armed_home:
      delay_time: 0
      pending_time: 0
    armed_away:
      delay_time: 0
      pending_time: 30
    triggered:
      pending_time: 0

### TERMOSTATO NETATMO ###
climate:
  - platform: netatmo
netatmo:
  api_key: !secret netatmo_client_id
  secret_key: !secret netatmo_client_secret
  username: !secret mia_email
  password: !secret http_pwd
  discovery: false

### TEXT TO SPEECH ###
tts:
  - platform: google_translate
    service_name: google_say
    language: 'it'
    cache: true
    cache_dir: /tmp/tts
    time_memory: 300

### MEDIA PLAYERS ###
media_player:
  - platform: mpd
    name: Raspberry
    host: 192.168.1.3
    port: 6600

  - platform: samsungtv
    host: 192.168.1.80
    port: 8001
    name: samsungtv65
    mac: XXXXXXXXXXXXXXXXXX

alexa_media:
  accounts:
    - email: !secret mia_email
      password: !secret http_pwd
      url: amazon.it

### TELEGRAM ###
telegram_bot:
  - platform: polling
    api_key: !secret telegram_token
    allowed_chat_ids:
      - !secret telegram_matteo_id
notify:
  name: nohometelegram
  platform: telegram
  chat_id: !secret telegram_matteo_id

### STORICO ###
recorder:
  purge_keep_days: 3
  include:
    domains:
      - automation
      - input_boolean
      - input_number
      - input_datetime
      - input_select
      - binary_sensor
      - sensor
      - climate
      - history_graph
      - device_tracker
      - alarm_control_panel
      - switch
      - person

### FLOORPLAN ###
frontend:
  extra_html_url:
    - /xxxxxx/xxxxxx_xx/state-card-floorplan.html
  themes: !include_dir_merge_named themes/

# Visualizzare floorplan nel menu a sinistra
panel_custom:
  - name: floorplan
    sidebar_title: floorplan
    sidebar_icon: mdi:home
    url_path: floorplan
    config: !include floorplan.yaml

# Enables configuration UI
config:

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:
  ignore:
    - igd
    - yeelight

yeelight:
  devices:
    192.168.1.106:
      name: Led Televisione
    192.168.1.122:
      name: Led Letto
    192.168.1.123:
      name: Led Giulia

# Allows you to issue voice commands from the frontend in enabled browsers
#conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
map:

# Track the sun
sun:

# Cloud
cloud:

# Interfaccia Lovelace Attiva
lovelace:
  mode: yaml

logger:
  default: info

system_health:

# Alleggerimento configuration.yaml
camera: !include cameras.yaml
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
sensor: !include sensors.yaml
switch: !include switchs.yaml
light: !include lights.yaml
zone: !include zones.yaml
binary_sensor: !include binary_sensors.yaml
scene: !include scenes.yaml

PLEASE edit your post by surrounding the config by three single backquotes to preserve formatting

The MQTT Broker’s log is filled with:

Socket error on client < device name >, disconnecting.

Has anything changed recently with:

  • your Wi-Fi network?
  • the tasmota fimware version?

No, nothing has changed. Since I installed home assistant sometimes it gives me this problem. When the Server shuts down for some reason or when I touch the mqtt configuration.

He’s making me crazy. When the system was simple, it was easy to get it back to work, but now that it’s much more complex it has become a nightmare.

?

This problem has been present since you installed Home Assistant a year ago?

yes, it started when I started using mqtt with sonoffs. Sometimes they went off-line but it wasn’t a big problem because they returned online immediately. Now the problem is more frequent and I am no longer able to resolve it and to return to the operational area.

MQTT hadn’t worked for 3 days, I tried everything by deleting the integration and reactivating it, deleting the user and recreating it … but nothing.
Now I have tried to implement the acl_file file which is optional in the configuration and which, in my opinion, has nothing to do with my problem considering the fact that it manages user permissions.
I restarted and now it works but I don’t think I’ve solved anything. Probably, in a few days, everything will be off-line again. I need to understand what the problem is.

Perhaps it can be useful to understand the problem. Sometimes a strange thing happens to me: suddenly a sonoff touch T2 plays 4 beeps and the light turns on by itself … even at night with my wife’s happiness …

In fact now it works but I still have lots of socket_error in the broker’s log mqtt.

That’s why I haven’t solved for a year; because I go crazy for 2/3 days then I solve the problem (even if I don’t understand how) and I think I have solved it

It’s not working well. Socket errors indicate Wi-Fi connection instability. My MQTT broker’s log contains no socket errors.

What do you think I can do to resolve?

I’m not a Tasmota expert but I believe it has the ability to report a device’s Wi-Fi signal strength (RSSI). I don’t know exactly where it shows it; either in the web console, log, or telemetry topic (or in all three sources). Anyway, if I had the problem you’re experiencing, that’s where I would start to investigate it.

The signal strength is over 80% on all devices. Furthermore, when it is not working, no device will work, not even the one near the router.

The router is a great product: it’s a FritzBox 7590 …

There’s your first assignment, determine the device’s signal-strength at that moment in time.

Again, everything off-line right now.:face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth::face_with_symbols_over_mouth: I do not know what to do. The signal is in all very good.

At this very moment, when ‘everything is off-line’, can you access one of the switch’s tasmota web console?