- Reorganized project: codesys/, docs/codesys|redesign|integration|reference/, scripts/ - CODESYS project and exports in codesys/ - Documentation index in docs/README.md - Redesign and light naming configuration - Water boiler control and safety design Co-authored-by: Cursor <cursoragent@cursor.com>
2.5 KiB
2.5 KiB
fb_switch Analysis Summary
Quick Assessment
Current Approach: ⚠️ Needs Improvement
Main Issue: Toggle-based control causes state desynchronization with Home Assistant.
Key Problems
1. State Desynchronization
- Problem: HA sends ON/OFF commands, but CODESYS toggles
- Result: HA thinks light is ON, sends ON again → CODESYS toggles it OFF
- Impact: Lights don't match HA state
2. No Status Feedback
- Problem: Status comes from toggle button, not actual relay
- Result: Can't detect relay hardware failures
- Impact: HA may show wrong status
3. Mixed Control Sources
- Problem: HA and Zigbee both use same toggle mechanism
- Result: Conflicting behaviors
- Impact: Unpredictable control
What You Need
✅ Control from Home Assistant (ON/OFF switches)
✅ Control from Zigbee switches (toggle behavior)
✅ Status feedback (actual relay state)
Recommended Solution
Option 1: Full Redesign (Recommended)
- Separate ON/OFF commands for HA
- Edge detection for Zigbee (toggle)
- Read actual relay status from EtherCAT
- Clear priority system
Pros: Clean, maintainable, extensible
Cons: Requires more changes
Option 2: Simplified Improvement
- Add ON/OFF commands alongside toggle
- Keep most existing structure
- Add status feedback
Pros: Less changes, faster to implement
Cons: Less clean, still some complexity
Quick Fix (Minimal Changes)
If you need a quick fix while planning the redesign:
-
In Node-RED: Convert HA ON/OFF to edge pulses
// Only send toggle on state change if (currentState !== newState) { sendToggle = true; } -
Add status readback: Read actual EtherCAT output state
lights.l_1_status := EtherCAT_Output_Channel_1; -
Update HA: Use state topic for status feedback
Decision Matrix
| Approach | Complexity | Time | Maintainability | Recommended For |
|---|---|---|---|---|
| Full Redesign | High | 2-3 days | Excellent | Long-term solution |
| Simplified | Medium | 1 day | Good | Quick improvement |
| Quick Fix | Low | 2-4 hours | Fair | Temporary solution |
My Recommendation
Start with Quick Fix → Then implement Simplified → Plan Full Redesign
This gives you:
- Immediate working solution
- Better solution in short term
- Best solution for long term
See: Full Redesign Recommendation for detailed implementation.