Shelly 2.5 Binary Sensors not recognizing state change

Long winded explanation of what I’m trying to do: In my one of the rooms of my house I have a single light switch that provides power to a ceiling fan. This fan doesn’t have a pull string and we are expected to use the remote to control the light and the fan. I’ve been using a broad link for a while to get the fan and the light separated in Home Assistant. My grandiose plan was to use a shelly 2.5 running ESPHome behind a dual light switch. When the switches to flipped, the broad link would send the appropriate commands. This way I’d have manual switches to control the fan and the light.

The problem: Everything is wired up exactly as it should be and works, with the exception of the physical switches, which should be read as binary sensors via the software. When I flip a switch, the software switch doesn’t change.

The switches are wired to SW1 and SW2 and the ESPHome firmware has those mapped to GPIO 5 and 13 respectively. Any bright ideas what I’m missing?

Here’s the current binary sensor section of the ESPHome firmware:

    binary_sensor:
      - platform: gpio
        pin:
          number: GPIO13
        name: ${devicename} Switch1
        on_press:
          then:
            - switch.toggle: shelly_relay_2
        on_release:
          then:
            - switch.toggle: shelly_relay_2            
      - platform: gpio
        pin:
          number: GPIO5
        name: ${devicename} Switch2
        on_press:
          then:
            - switch.toggle: shelly_relay_1
        on_release:
          then:
            - switch.toggle: shelly_relay_1            

Would be nice to see your switch configuration as well.

And a wiring diagram.

Pretty sure I may have mixed up the order of the inputs on the drawing of the Shelly, but everything is wired up like that.

and what about this?

Here’s the switch config. Although, I’d like to re-iterate that the switch is working fine. The only issue is that the binary sensors aren’t changing based on the state of the physical switch.

switch:
  - platform: gpio
    id: shelly_relay_1
    name: ${devicename} Relay1
    pin: GPIO15
    icon: "mdi:electric-switch"
    restore_mode: RESTORE_DEFAULT_OFF
  - platform: gpio
    id: shelly_relay_2
    name: ${devicename} Relay2
    pin: GPIO4
    icon: "mdi:electric-switch"
    restore_mode: RESTORE_DEFAULT_OFF 

Apart from the fact, that O1 and O2 should go to the neutral of two different consumers and not line and neutral of the same consumer I can not see anything out of the ordinary. But this should be a problem no matter how you operate the switch (hassio vs. physical).
Also N should be connected to neutral not ground, but I’m not really an expert.

Do you use spring loaded switches, that return to their position when released?

In hassio the visual state of the switch does not change when you throw the physical switch?

Can you take the switches out of the equation?

In other words, are these momentary switches?

Correct. The issue ultimately is that the state of the switch does not change when I flip the physical switch. The light switch itself is not a momentary switch. It is a Leviton decora, so it stays in place when flipped. I have these same switches working successfully in three other rooms.

And what does the esphome log say when you flip the switches?

Also, blakadder lists those switch inputs as 83n and 82n. The n is something to do with pullup, but I am not sure what that means you should do in you yaml file.

The log doesn’t show anything when the switches are flipped. It does show the binary sensors when it initially loads, but that’s the only mention of them in the log.

Try:

    binary_sensor:
      - platform: gpio
        pin:
          number: GPIO13
          mode: INPUT_PULLUP
        name: ${devicename} Switch1
        on_press:
          then:
            - switch.toggle: shelly_relay_2
        on_release:
          then:
            - switch.toggle: shelly_relay_2 

I have (in the absence of much else to do) taken a good look at this again.

From your first post it appears that you do not want this wall switch to switch any mains voltage at all. You simply want it to create binary sensor that home assistant reads and then gets the broadlink to actually control the light/fan.

In that case I really can’t understand your wiring diagram, or the need to switch the relays at all. The logic can all be done in home assistant.

Further: the upper switch in your diagram has only one wire connected to it, It won’t switch anything.

I’m fairly sure this is a problem with the switch or it’s wiring, hence my suggestion to take the switch out of the equation for testing.

@nickrout You don’t want to rely on home assistant or wifi to turn on your lights with the physical switch.

1 Like

The quick update is that I got it working. The wiring in principal was correct, so I’m not sure what was wrong before. I simplified the line wiring and re-installed everything and it worked fine. Now I’m just fine-tuning the software. Thanks for all the help!

But if you are using broadlink to control the lights, how else do you suggest doing it?

I don’t know what broadlink is but from your question I take it is controlled via WiFi.

I was arguing in a more general way.

Broadlink is an IR hub.

I understand your point and its validity. It is just not relevant to this use case.