Shelly 1L via MQTT second switch

Hello community, I have Shelly 1L correctly integrated to HA via MQTT. With Shelly 1L I can connect 2 phisical switches, the first is declared in HA as following, and it works perfect:

- platform: mqtt
  name: "Luce Tavolo Interruttore"
  state_topic: "shellies/shelly1l/relay/0"
  command_topic: "shellies/shelly1l/relay/0/command"
  qos: 0
  payload_on: "on"
  payload_off: "off"
  retain: false

The second is configured as following:

- platform: mqtt
  name: "Cameretta Interruttore"
  state_topic: "shellies/shelly1l/relay/1"
  command_topic: "shellies/shelly1l/relay/1/command"
  qos: 0
  payload_on: "on"
  payload_off: "off"
  retain: false

But is doesn’t work. I added both to lovelace:

The first works, the second, switch on, and then immediately switch off without triggering any automation.

What’s wrong?
Thank you
Lucas

You could check what’s going on in MQTT using MQTT-Explorer or something like this. Maybe you’ll find an answer. :slight_smile:

Thank you, what I have to check on MQTT Explorer? I have the following:

The relay command 1 is always “on” while the relay command 0 is on/off depending on what I do on lovelace.

Hi, I noticed this post while troubleshooting an issue similar to yours, in case you are still struggling:
[Disclaimer this is just my understanding…]

Remember that the shelly1L has two switches (or in italian: interruttori) for the same device (per la stessa lampadina per esempio). Is useful in its default settings if you have two button for the same light.

Comments on your setup:

NOTE: from your screenshot I have the impression that:

  • the wiring is not correct for SW1 (button0?)
  • or that you never pressed button0
    My understanding is that the 2 lines that you see in “input_event” means the following:
  • 0 = {“event”:"",“event_cnt”:0} <-- button0 has being pressed 0 times
  • 1 = {“event”:"",“event_cnt”:9} <-- button1 has being pressed 9 times

If this is the case, maybe you did not wire the two buttons from the physical switch (“interruttore”) to the shelly

Also the command topic you want to react on is not the relay, I believe is input/0 and input/1 that you may want to use instead.

See below my config if it could inspire you:

I did not want to use the buttons (switches or interruttori) to provide or not electricity. Instead:

  • I want electricity to always be on (I am powering 2 wifi tp-link light bulbs)
  • I want the left button on the wall to execute an automation (turn on/off via wifi a specific light bulb)
  • I want the right button on the wall to execute another automation (turn on/off via wifi a different specific light bulb)

I wanted to have also the state of the button, therefore I have created a binary sensor for each of the two buttons. this could be avoided and you can skip this step if you change the automation to listen to mqtt instead of following blindly the example of my configuration around binary sensor below.

Please note, that in order to make it work as I intended, I had to configure on the shelly1L web interface the buttons as “Detached Switch” ( Set Shelly device to be in “Detached” switch mode - switch is separated from the relays)

Here the binary sensor declared in configuration.yaml
my 2 binary sensors for the leftbutton and righbutton

binary_sensor:
  - platform: mqtt
    name: "Kitchen_left"
    device_class: power
    state_topic: "shellies/kitchenshelly1l/input/0"
    value_template: "{% if value == '1' %} on {% else %} off {% endif %}" 
    payload_on: "on"
    payload_off: "off"
    payload_available: "true"
    payload_not_available: "false"
    
  - platform: mqtt
    name: "Kitchen_right"
    device_class: power
    state_topic: "shellies/kitchenshelly1l/input/1"
    value_template: "{% if value == '1' %} on {% else %} off {% endif %}" 
    payload_on: "on"
    payload_off: "off"
    payload_available: "true"
    payload_not_available: "false"

##you should have other binary_sensor in this section if you have others

and here the automation to trigger the left button to turn on/off the kitchen light:

alias: KitchenLeftButton
description: Turn on Kitchen Light when KitchenLeftButton is pressed
trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_left
condition: []
action:
  - type: toggle
    device_id: [added by the UI]
    entity_id: light.kitchen_light
    domain: light
mode: single

and then an equivalent one for the right button (In italian: interruttore) to turn on/off in my case the other kitchen light that point to the table

alias: KitchenRightButton
description: Turn on Table Light when KitchenRightButton is pressed
trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_right
condition: []
action:
  - type: toggle
    device_id: [added by the UI - not sure if it is needed]
    entity_id: light.table_lamp
    domain: light
mode: single
1 Like