Skip to content

Commit 30dc3da

Browse files
committed
refactor: rewrite project and add docs
1 parent 96736d6 commit 30dc3da

File tree

6 files changed

+432
-223
lines changed

6 files changed

+432
-223
lines changed

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,58 @@
1-
# Offline fallback shelly zha control
1+
# ESPHome: Offline fallback mechanism to control Zigbee device via shelly
22

3-
This project aims to provide an offline fallback option for controlling a zha lamp using a shelly. In the event that zha or the network goes offline, the Shelly switch will automatically trigger its relay to toggle the light. When the network is online, the switch will use zha to directly control the light, preserving the smooth fade effect of compatible lamps.
3+
In this project, I provide an [ESPHome](https://esphome.io/)-based configuration to control a Zigbee device via a Shelly or similar device, while ensuring it remains operational offline.
44

5+
## What you need
6+
7+
1. An ESPHome compatible device which has a switch and a relay
8+
2. Zigbee Device connected via [ZHA](https://www.home-assistant.io/integrations/zha/) in [Home Assistant](https://www.home-assistant.io/)
9+
3. Knowledge how to flash ESPHome
10+
4. The Zigbee device needs to turn on after power loss. Most lamps have this as their default configuration
11+
12+
## How this works
13+
14+
I created a flow diagram to design the fallback process:
15+
16+
![Flow Diagram](assets/Flow%20Diagram.webp)
17+
18+
To explain it, when one of the following cases is true:
19+
20+
- ESPHome device is no longer connected to Home Assistant
21+
- ZHA marked the Zigbee device as "unavailable"
22+
- Toggling the Zigbee device fails after 2s
23+
24+
Then, we use the relay on the Shelly instead to control the device. If the device's last known state was on, we simply turn off the relay. If the last known state was off, we toggle the relay off and then back on. This approach ensures the device is in the expected state, even if Zigbee or WiFi stops working.
25+
26+
## How to use
27+
28+
```yaml your-esphome-config.yaml
29+
# {... Your esphome configuration}
30+
31+
packages:
32+
# Optional: Predefined base for a Shelly 1L only
33+
Shelly1L:
34+
url: https://github.com/TheNoim/OfflineShelly
35+
files: [shelly-1l.yaml]
36+
ref: "1.0" # Release tag you want to use
37+
refresh: 1d
38+
# Offline mechanism
39+
OfflineShelly:
40+
url: https://github.com/TheNoim/OfflineShelly
41+
files: [offline-shelly.yaml]
42+
ref: "1.0" # Release tag you want to use
43+
refresh: 1d
44+
# You can also use it for multiple devices: https://esphome.io/components/packages#packages-as-templates
45+
# If you use multiple devices: The prefix needs to be different for each device. The relay can be the same
46+
vars:
47+
prefix: deckenlampe # Even if you don't want to control multiple device, you need to specify a prefix. It needs to follow the rules for an ESPHome id https://esphome.io/guides/configuration-types.html#config-id
48+
zigbee_entity: light.arbeitszimmer_deckenlampe_light # Zigbee entity id in hass
49+
relay_id: deviceid # ESPHome relay id. Needs to be a switch
50+
51+
binary_sensor:
52+
- id: !extend switchid1 # ID from switch1
53+
on_state:
54+
then:
55+
# Script name format: ${prefix}_toggle
56+
script.execute: deckenlampe_toggle
57+
# For multiple devices: just use a list and run script for each prefix
58+
```

0 commit comments

Comments
 (0)