Shelly Cloud - new Component? How to implement it? API is available

Argh, good spotting. I think that is on. What’s the purpose of enabling that?

does anyone know how to integrate the power meter via mqtt?

sensor:
  - platform: mqtt
    name: "Family Room Shelly Power"
    state_topic: "shellies/shellyswitch-9F6008/relay/power"

  - platform: mqtt
    name: "Stairs Shelly Power"
    state_topic: "shellies/shellyswitch-9F5ED/relay/power"

Even though the Shelly2 has two relays, there is only one power monitoring chip.

1 Like

Both h.a. and Shelly need to use retain or both need to not use retain.

If you were previously using retain then you must delete the retained message topic if you want to use retain false.

The problem you describe sounds like a retain message hasn’t been cleared problem.

Thanks. I’ve now turned off clean session on the Shelly but have QoS2 and retain on and retain on for the Hass config and still the light turns off (from being on) when Hass restarts. If I turn the light on and then open MQTT.fx and subscribe to the switch topic, I immediately get a retained message with the payload on.

I’d change to retain false in everything and then publish a blank / null message to all the topics to clear the retained messages. Can also uninstall and reinstall mqtt server to clear it.

Both clients don’t need to use retain, it depends which one you want to have control. For example, I set my switches to be off following a power outage. They have retain set. If I set retain also in home assistant, they would turn back on if they were on in home assistant before the power outage.

How do I debug this? I have retain off in Hass and have published no payload to shellies/shellyswitch-9F6008/relay/1/command but the lights still turn off on HA restart. Retain is on on the Shelly2 device and clean session is off. I use MQTT.fx all the time but I’m struggling to get this behaving properly. Could it be a bug in the Shelly firmware? If not, where is the command to tell the light to turn off coming from if the retained state on the broker is on.

I think it should be debugged with the mosquitto command line tools.

mosquitto_sub -v -t '#' 

Plus whatever other options you need to connect…

Have you checked the other settings on the shelly. Under timers for example check the auto on/off settings. Mine are all set to 0.

On another matter, the auto off on my shelly 1 only turns off after X time if I use the physical switch. If I use Mqtt to turn it on then it stays on.

I have clean session on, it should ignore retained messages then when it connects. I use QoS 1

Did you do a factory reset?

So yours does not turn off on HA restart? It’s odd, as the HA service should not interfere with a MQTT based entity. I’m debugging from a Windows 10 laptop so I don’t directly have access to mosquitto sub tools.

I’ve not had any issues. Expected to want to put tasmota on straight away but got it working with the settings I described. I can confirm it stays on when I restart ha. I am using a shelly 1 though. Not tried a 2 yet.

Are you using the MQTT add-on for Hass.io?

I am now but I do remember it working ok with the built in server too. I have found that the add on speeds up hassio, particularly at boot up as I have added more Mqtt devices

I’ve just spun up a Docker container with MQTT and connected one Shelly to it. Restarting that instance does not turn off the light but it does with the Hassio MQTT add-on. I also had an issue with the Monitor presence detection where the two Pi’s I had would flood the MQTT add-on with connect/disconnect messages and essentially make all my MQTT devices unusable. It did not appear to behave the same with a Docker instance on my NAS.

I might try flicking everything back to my Docker instance and see how I go.

Found my problem!! Something funky going on with MQTT Light. I have two of the Shelly relays configured as lights. Doesn’t matter whether I have MQTT on/off on the Shelly, clean session on/off, retain true/false on HA, none of it makes a blind bit of difference.

If I restart HA, it sends a command ‘off’ to the Shelly command topic which I’ve tracked using MQTT.fx. however, one of the Shelly relays is configured to control a ceiling fan as a MQTT switch as this does not turn off on HA restart (same device as one of the lights that does turn off).

Some for some reason, HA sends an off command on restart to the command topic of the Shelly lights.

light:
  - platform: mqtt
    name: "Kitchen Lights"
    state_topic: "shellies/shellyswitch-9F6008/relay/1"
    command_topic: "shellies/shellyswitch-9F6008/relay/1/command"
    qos: 2
    payload_on: "on"
    payload_off: "off"
    retain: false
    optimistic: false

switch:
  - platform: mqtt
    name: "Family Room Fan"
    state_topic: "shellies/shellyswitch-9F6008/relay/0"
    command_topic: "shellies/shellyswitch-9F6008/relay/0/command"
    qos: 2
    payload_on: "on"
    payload_off: "off"
    retain: false

Thanks for the update on this, all my lights are configured as switches so i never noticed this.

Have you figured out how the lwt message works or should be configured for the shelly?

@Crhass Haven’t played with that yet. Focused on keeping the lights going at the moment. I want the relays in HA as lights so I can use all lights off command in Lovelace and UI shows if any lights are on. I know I can do it with a template light as I’ve done with my Xaiomi switches that are controlling lights but I was hopeful of being able to bring them straight into HA as lights. Rob (?) from TheHookup is aware of my problem so I’m waiting to see if he has an answers. He posted a video today of configuring the Shellys in HA using MQTT.

Did you try uninstall and reinstall mqtt hass.io add-on?

Moved to external broker, same problem. Only happens when Shelly relay configured as MQTT light.