Exploring Multi-Button Automation with Shelly and ESPHome

Hi everyone,

I’ve been diving into the world of smart home automation lately, and I must say, it’s been an exciting journey! One of the devices I’ve been working with is the Shelly 2.5, paired with ESPHome. I wanted to share my experience and some tips on setting up multi-button automation, which I found both challenging and rewarding.

The Challenge

I have a Shelly 2.5 installed in my master bathroom, controlling a fan and a light. The goal was to create a system where toggling the fan switch would adjust the bathroom light in predefined steps—think of it as a multi-level brightness control without needing a slider. I wanted to achieve this using just the physical toggle switches on the Shelly device.

At first, I was a bit overwhelmed. The ESPHome documentation provided a good foundation, but applying it to my specific use case wasn’t straightforward. I spent hours tweaking scripts and lockout timers, only to face issues where the automation wouldn’t behave as expected.

The Solution

After some trial and error, I landed on a script-based approach. Here’s a simplified version of what I did:

  1. Script Definitions: I created separate scripts for each action level (e.g., turning on the fan and adjusting the light to 50% brightness, then to 25%, and so on).
  2. Toggle Handling: Each toggle action triggers the next script in the sequence. If a script is already running, it stops the current one before starting the next, ensuring smooth transitions.
  3. Binary Sensor Integration: I utilized a binary sensor to detect state changes on the toggle switch, allowing the automation to respond dynamically.

Here’s a snippet of the script logic I used:
yaml
script:

  • id: fan_action_1
    mode: parallel
    then:
    • switch.toggle: shelly_relay_1
  • id: fan_action_2
    mode: parallel
    then:
    • homeassistant.service:
      service: script.set_light_ct
      data:
      light_name: light.toilet_closet_bulb
      kelvin: ‘2000’
      brightness_pct: ‘50’

The Outcome

The result? Pure satisfaction! Now, each toggle of the fan switch cycles through predefined light settings, creating a seamless experience. It’s not just about functionality—it’s about how it enhances my daily routine. Imagine stepping into a dimly lit bathroom in the morning, with the light gradually brightening as I go about my business. It’s these small touches that make a home truly smart.

Final Thoughts

This project taught me the value of persistence and the importance of diving into the documentation, even when things get tricky. I’m now confident in tackling more complex automations. If you’re considering something similar, I’d say go for it! Start simple, test each part, and build from there.

Happy automating! :rocket:

Best,
[Your Name]