Native MQTT and Shelly

Hello all
I’m pretty new to HA and all those technologies, then tapping blindly sometimes…
I’m running HA on RPi4 (default installation installed from image)

Recently bought a few pieces of Shelly 1 being wanted to automate them through MQTT.

I installed Mosquitto broker from official repo using default config. I’ve created new user requested in installation manual.
Then following manual, I jumped into Configuration/Integration and added integration with MQTT which was announced and newly recognized one at this time. Unfortunately there is no shelly devices recognized by auto-discovery. I quess it’s because Shelly doesn’t conform MQTT topic format, required for auto-discovery.

Anyway, at first I attempted to try new relay with Node-Red. It worked at first try: it sends messages switching the relay, it receives states.

But then I wanted to add some visualization/button to HA dashboard. And I failed :frowning: I spent literally 4 hours browsing Internet. I saw a lot of discussions about similar troubles, with suggestion to use automation script syncing Shellys at HA start. Nothing helped.

My configuration for shelly relay looks like this (I’m including whole switch section, which includes Twinkly too)

  - platform: command_line
        command_on: "python3 /config/python_scripts/ on"
        command_off: "python3 /config/python_scripts/ off" 
        command_state: "python3 /config/python_scripts/ state"
        value_template: "{{ value == \"1\" }}"
        friendly_name: Twinkly
  - platform: mqtt
    name: "shelly1-10D891"
    command_topic: "shellies/shelly1-10D891/relay/0/command"
    state_topic: "shellies/shelly1-10D891/relay/0"
    availability_topic: "shellies/shelly1-10D891/online"
    qos: 1
    retain: false
    payload_on: "on"
    payload_off: "off"
    state_on: "on"
    state_off: "off"
    optimistic: false

This config allowed me to show “shelly1-10D891” on dashboard. unfortunately with status “unknown”

I attempted to add mqtt section to configuration.yaml (I saw somewhere “old-school” term for this) but this is probably not needed for native Mosquito plugin. Anyway if mosquito integration is removed then HA shows notification about not finding mqtt platform. With mosquito integration is added, then no error or warnings is shown, even without mqtt: section in configuration.yaml.

Right now two options seems to remain. Use REST integration (incl one available in HACS) or try Shelly discovery add-on for MQTT (also from HACS) but don’t know if it will work

Anyway I’m really curious why it doesn’t work and what I am doing wrong. I would like to understand that. Especially it works in Node-Red so communication Shelly-MQTT and MQTT-NodeRed is working.

Thanks in advance.

Okay just going take a stab at it. Without confirming as I flashed all my shellies with esphome
shellies is a group topic
Remove that from the topics
So you only have for example

No I’m wrong disregard the above

You don’t need the state_on or state_off.
That should be
payload_available: “true”
payload_not_available: “false”

Yes, you are right: payload_available and payload_not_available were missing.
I didn’t try this discovery script yet. Knew about it but at this stage of learning, I would like to have a control over things at first.

BTW those relays are great. I managed to mount them under light switches. Work like a charm.

Thank you!

You don’t need to tell me.
all my lights are controlled by a shelly1 or a shelly2
Single and 2way (US refer to them as 3 way why? I don’t know). But I found the Esphome far more responsive than the Stock firmware using MQTT/Rest or even Tasmota firmware. Though there is no support for the PM in a Shelly2 via Esphome

1 Like

Newbie question, sorry but what is PM? Do you need hardware to flash Esphome? Does that also work in HA through MQTT? So many acronyms…

Shelly 1 PM and the Shelly 2.5 have Power Monitoring. You need an USB FTDI adapter to flash them with alternative firmware, either Tasmota or Esphome.

1 Like

Yes does with original firmware.

1 Like

Without the cloud even?

On the shellies, if you activate mqtt then you can’t use the shelly cloud anymore. So mqtt -> totally local.

Oh, that seems nice! Thanks for the info. Do I need any tools to activate MQTT?

The Shelly app

Or you can use WEB interface available on IP address of Shelly device.
But for beginning I suggest to read manual and other resources available on Shelly pages

The reason is how many configurations the switches can be in, ie both up or both down or one up and one down. so there is 3 ways (or configurations) the switches can be in. As an electrician I get asked this a lot, I see why people think 2 way as there is only 2 current paths, but the term refers to the switch config.

hmm imo there are 4 combinations for 2 switches. and this number rapidly increases while adding switches to drive the same light.

not saying that what you is saying is not true (or used to be true when invented).