惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Simply Explained

Converting a Tuya Thermostat to ESPHome Bringing Foam Monsters to Life: How I Wrote and Illustrated a Children's Book Using AI How I Built an NFC Movie Library for my Kids Analyzing Link Rot in My Newsletter (After 31 Editions) How I Use Alfred to Search My Obsidian Notes Faster (with Spotlight!) Year in review: 2022 Serverless Anagram Solver with Cloudflare R2 and Pages Integrate Home Assistant with Apple Reminders How WebP Images Reduced My Bandwidth Usage by 50% Tracking gas usage with ESPHome, Home Assistant, and TCRT5000 My Sixth Year as YouTube Creator (statistics + retrospective) EZStore: a tiny serverless datastore for IoT data (DynamoDB + Lambda) ESP-IDF: Storing AWS IoT certificates in the NVS partition (for OTA) How to securely access your home network with Cloudflare Tunnel and WARP I Built a CO2 Sensor and It Terrifies Me Filtering spam on YouTube with TensorFlow & AI Building a killer NAS with an old Rackable Server How I Structure My ESPHome Config Files Howto Virtualize Unraid on a Proxmox host MAX17043: Battery Monitoring Done Right (Arduino & ESP32) Preventing Cumulative Layout Shifts with lazy loaded images (Eleventy + markdown-it) Migrating This Blog From Jekyll to Eleventy Good Home Automation Should be Boring ESP32 Cam: cropping images on device Retrospective: My Fifth Year on YouTube Secure Home Assistant Access with Cloudflare and Ubiquiti Dream Machine Shelly 2.5 + ESPHome: potential fire hazard + fix Impact of Adblockers on Google Analytics (vs. Plausible) Shelly 2.5: Flash ESPHome Over The Air! Tuya IR Hub: control Daikin AC (Home Assistant + ESPHome) Building Air Quality Sensor: Luftdaten + Home Assistant HEIC to JPG: Build a Quick Action with Automator Make Your Garage Door Opener Smart: Shelly 1, ESPHome and Home Assistant Static webhosting benchmark: AWS, Google, Firebase, Netlify, GitHub & Cloudflare Why I don't take sponsorships Monitoring my 3D printer with a Pi Zero, Home Assistant and TinyCore Linux ESP32: Keep WiFi connection alive with a FreeRTOS task Home Energy Monitor: V2 Retrospective: 4 years on YouTube
Smart lights behind a wall switch (Shelly, Z-Wave, ESPHome)
Xavier Decuy · 2022-10-07 · via Simply Explained

Using smart light bulbs means you can no longer use your physical wall switches because the bulbs need constant power. I think that's pretty dumb. Using a physical switch can be way faster than using an app to control the lights.

Here's how you can put an in-wall module (like a Shelly, or a similar Z-Wave module) between the switch and bulb so that you can use both in harmony.

I believe home automation should only add functionality to your existing infrastructure, not take options away. Installing smart lights is cool, but they should allow you to keep using the wall switches as well.

This setup also works perfectly with smart bulbs like Philips Hue, as long as you keep constant power to the bulb and use the in-wall module as an input/controller layer.

Wiring

Start by connecting the Shelly to the wall switch and the smart lights as intended. Connect the Shelly to mains power, the light bulb to the output terminal, and the switch to the SW input:

This is the standard setup for a Shelly-style in-wall switch module. With default behavior, these modules usually toggle the bulb power directly when the wall switch is toggled. That's not what I want, so ESPHome to the rescue!

Note: If you want to flash ESPHome to your Shelly devices, check out my blog post about how to flash it over-the-air. No wires needed!

The ESPHome Magic™

With ESPHome you can run automations on the Shelly itself. Here, I want the Shelly to send an event to Home Assistant whenever we use the wall switch. This can trigger an automation, which can turn on the smart light through Zigbee or whatever protocol it’s using.

However, when Home Assistant is not available (offline or the WiFi network is out), I want the Shelly to take control of the lights by toggling the relay inside. It doesn't happen often, but I don't want to sit in the dark when I mess up my Home Assistant configuration.

Here's a visualization of the automation:

And here is the ESPHome configuration to make that happen:

substitutions:
  devicename: shelly1-living
  friendly_name: Living
  channel_1: Living spots

esphome:
  name: $devicename
  platform: ESP8266
  board: esp01_1m

output:
  # The relay
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  # Expose the relay as a light to Home Assistant
  - platform: binary
    name: $light_name
    output: shelly_1_relay
    id: light_1

binary_sensor:
  # This switch is connected to IKEA GU10 light bulbs which ideally are always
  # powered on. This configuration is made in a way, that if Home Assistant is
  # not connected, the Shelly takes over the relay. Otherwise, we rely on an
  # automation in Home Assistant.
  - platform: gpio
    pin: GPIO5
    name: "${channel_1} input switch"
    internal: true  # Don't need switch state in HA
    filters:
      - delayed_on_off: 150ms

    # When the switch is toggled, check if we have a WiFi connection
    # and if Home Assistant is connected to the API
    on_state:
      then:
        if:
          condition:
            - wifi.connected: ~
            - api.connected: ~
          # If there's WiFi and HA is connected, make sure that the
          # relay is ON and send an event to Home Assistant. It's then
          # up to an automation to control the smart light.
          then:
            - light.turn_on: light_1
            - homeassistant.event:
                event: esphome.switch_pressed
                data:
                  slug: "${channel_1}"

		  # If the WiFi is down, or Home Assistant is not connected,
		  # take manual control of the relay!
          else:
            - light.toggle: light_1

Note: I would love to take credit for this idea, but I found it in Frenck's Home Assistant configuration repository on GitHub.

This ESPHome configuration is for the Shelly 1, but can easily be adapted for other Shelly devices. It can also work with push buttons instead of toggle switches, and you could even generate custom events when the button is held down, which could then dim the lights or do something else.

Home Assistant automation

With events flowing into Home Assistant, we can now create an automation to actually control the smart lights (in my case a Zigbee bulb):

- alias: "Control living spots through ESPHome events"
  trigger:
    - platform: event
	  event_type: esphome.switch_pressed
      event_data:
        slug: "Living spots"
  action:
    - service: light.toggle
      entity_id: light.living_spots_group

That's it!

I can now control my IKEA Zigbee switches with my dumb wall switch. And if things go wrong with Home Assistant or the WiFi, the Shelly will take control.

Stock Shelly firmware

While I haven't tested this, you could achieve a similar setup by using the stock firmware. The Shelly integration for Home Assistant also receives an event when you toggle your switch. Just set the button type to "detached".

The only limitation is that your wall switch won't work when Home Assistant (or your WiFi network) is down. But if you don't fancy flashing ESPHome to your devices, you might be okay with that.

Conclusion

That's it. You can now use smart light bulbs WITH physical wall switches. No need to choose between them. And when shit hits the fan, the Shelly will gracefully take control of lights, so you never have to sit in the dark waiting for your WiFi or home automation system to come back online.

Credit goes to Frenck for posting this approach on his GitHub.