Shelly1 Integration through MQTT - problem

I’m trying to connect Shelly through MQTT (mosquitto) with my HA (on
Below you can find log from mqtt mosquito
And also switch config from configuration.yaml
and from shelly configuration page

I cannot switch the relay, the button ingo HA turning on for 2 secs but nothing happened.
Any advices?

[09:05:20] INFO: Setup mosquitto configuration
[09:05:20] WARNING: SSL not enabled - No valid certs found!
[09:05:20] INFO: No local user available
[09:05:21] INFO: Initialize Add-on services
[09:05:21] INFO: Initialize Home Assistant discovery
[09:05:21] INFO: Start Mosquitto daemon
1576742721: mosquitto version 1.6.3 starting
1576742721: Config loaded from /etc/mosquitto.conf.
1576742721: Loading plugin: /usr/share/mosquitto/
1576742721: |-- *** auth-plug: startup
1576742721:  ├── Username/password checking enabled.
1576742721:  ├── TLS-PSK checking enabled.
1576742721:  └── Extended authentication not enabled.
1576742721: Opening ipv4 listen socket on port 1883.
1576742721: Opening ipv6 listen socket on port 1883.
1576742721: Opening websockets listen socket on port 1884.
1576742721: Warning: Mosquitto should not be run as root/administrator.
1576742725: New connection from on port 1883.
1576742726: Socket error on client <unknown>, disconnecting.
1576742726: New connection from on port 1883.
[INFO] found homeassistant on local database
1576742726: New client connected from as auto-2218411D-330D-3606-627F-84B79D7B2DDB (p2, c1, k60, u'homeassistant').
1576742740: New connection from on port 1883.
[INFO] found hass on Home Assistant
1576742741: New client connected from as shelly1-xxxxx (p2, c1, k60, u'hass').
1576742744: Socket error on client shelly1-B97AA2, disconnecting.
1576742746: New connection from on port 1883.
1576742746: New client connected from as shelly1-xxxxx (p2, c1, k60, u'hass').

switch config

switch 4:
  - platform: mqtt
    name: “Shelly”
    state_topic: “shellies/shelly1-xxxxx/relay/0”
    command_topic: “shellies/shelly1-xxxxx/relay/0/command”
    qos: 1
    payload_on: “on”
    payload_off: “off”
    retain: false
    optimistic: false

shelly config

Min reconnect timeout
Max reconnect timeout:
Keep alive:
Clean Session
Max QoS 2

Any advices will be appreciated…

If you aks me, don’t go that route.
The best way is the shelly discovery component. It will find the shelly devices automaticly.
Check this: Shellies Discovery Script

Install hacs, install shelly and enjoy.

I tried it before (I mean shellies discovery script).
Relay was discovered, but…
problem was different - after each restart of HA - shellies was unavailable.

So that’s the reason why I removed device “automatically discovered” and start to figure out how to add this manually and make it work.

Do you have Shellies Announce automation? Without it entities are unavailable after restart.

No spaces in switch object ids. Change this:

switch 4:

to this:


All of your double quotations are fancy tpes like this “ ”. They won’t work. They should be the straight type like this " ".

Just for the information I already tested for simple things Domoticz - relays, ESP sensors etc. It was very easy but … ugly. I like the way how HA works, but I need to learn a lot about this systems before I start to build my house.

O_o = I have correct quotiations something went wrong when pasted here.
According to switches i cannot use switchx instead of switch x because if I change i have fault - there is no integration switch4 etc.
I leave it like it was.

Neverthless… I create again automation scripts, remove mqtt from integrations. Reset whole system. And then it is working in both way - with REST method and MQTT manually added sensor and MQTT automatically discovered - MQTT work much faster so I will test both method for couple of weeks and will see …

Still I have no idea what was wrong… :confused:
I also added Access Control List to MQTT configs etc…

Below for future references my configuration.yaml


switch 3:
  - platform: rest
    name: "Relay"
    scan_interval: 5
    body_on: 'turn=on'
    body_off: 'turn=off'
    is_on_template: '{{ value_json.ison == true}}'
      content-type: application/x-www-form-urlencoded
switch 4:
  - platform: mqtt
    name: "ShellyTest"
    state_topic: "shellies/shelly1-xxxxx/relay/0"
    command_topic: "shellies/shelly1-xxxxx/relay/0/command"
    qos: 1
    payload_on: "on"
    payload_off: "off"
    retain: false
    optimistic: false

And here automation.yaml

- id: shellies_announce
  alias: 'Shellies Announce'
    - platform: homeassistant
      event: start
    service: mqtt.publish
      topic: shellies/command
      payload: announce

- id: 'shellies_discovery'
  alias: 'Shellies Discovery'
  - platform: mqtt
    topic: shellies/announce
    service: python_script.shellies_discovery
      id: '{{ }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'

Then it will never work.

When I remove space from switch declaration:
thats the result…

Component error: switch2 - Integration ‘switch2’ not found.
Component error: switch1 - Integration ‘switch1’ not found.

All switches from my config working now perfectly.