generated from nickdante8/fw-heater-on-oil
131 lines
3.7 KiB
YAML
131 lines
3.7 KiB
YAML
globals:
|
|
- id: led_state
|
|
type: std::string
|
|
initial_value: '"WIFI_SEARCHING"'
|
|
|
|
# Corrected led_status.yaml looping scripts
|
|
script:
|
|
# Pattern 1: Three rapid blinks (Looping)
|
|
- id: led_pattern_wifi_searching
|
|
mode: restart
|
|
then:
|
|
- while:
|
|
condition:
|
|
lambda: 'return true;'
|
|
then:
|
|
- repeat:
|
|
count: 3
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 100ms
|
|
- switch.turn_off: switch_led
|
|
- delay: 100ms
|
|
- delay: 1000ms
|
|
|
|
# Pattern 2: Fallback AP active (1 long blink + 3 rapid blinks loop)
|
|
- id: led_pattern_ap_fallback
|
|
mode: single
|
|
then:
|
|
- while:
|
|
condition:
|
|
lambda: 'return true;'
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 1000ms
|
|
- switch.turn_off: switch_led
|
|
- delay: 500ms
|
|
- repeat:
|
|
count: 3
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 100ms
|
|
- switch.turn_off: switch_led
|
|
- delay: 100ms
|
|
- delay: 1000ms
|
|
|
|
# Pattern 3: Two long blinks (Connected WiFi)
|
|
- id: led_pattern_wifi_connected
|
|
mode: single
|
|
then:
|
|
- while:
|
|
condition:
|
|
lambda: 'return true;'
|
|
then:
|
|
- repeat:
|
|
count: 2
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 600ms
|
|
- switch.turn_off: switch_led
|
|
- delay: 400ms
|
|
- delay: 1500ms
|
|
|
|
# Pattern 4: One rapid blink (Transient event for successful MQTT publish)
|
|
- id: led_event_mqtt_success
|
|
mode: queued
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 100ms
|
|
- switch.turn_off: switch_led
|
|
|
|
# Pattern 5: One long blink (Transient/State event for MQTT fail)
|
|
- id: led_event_mqtt_failed
|
|
mode: restart
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 1000ms
|
|
- switch.turn_off: switch_led
|
|
|
|
# Pattern 6: OTA update
|
|
- id: led_ota_update_progress
|
|
mode: restart
|
|
then:
|
|
- switch.turn_on: switch_led
|
|
- delay: 200ms
|
|
- switch.turn_off: switch_led
|
|
|
|
- id: set_led_state
|
|
parameters:
|
|
state_name: string
|
|
then:
|
|
# 1. Stop all active pattern loops
|
|
- script.stop: led_pattern_wifi_searching
|
|
- script.stop: led_pattern_wifi_connected
|
|
- script.stop: led_pattern_ap_fallback
|
|
- script.stop: led_event_mqtt_success
|
|
- script.stop: led_event_mqtt_failed
|
|
- script.stop: led_ota_update_progress
|
|
# 2. Update global state
|
|
- lambda: 'id(led_state) = state_name;'
|
|
# 3. Route to active pattern
|
|
- if:
|
|
condition:
|
|
lambda: 'return state_name == "WIFI_SEARCHING";'
|
|
then:
|
|
- script.execute: led_pattern_wifi_searching
|
|
- if:
|
|
condition:
|
|
lambda: 'return state_name == "WIFI_CONNECTED";'
|
|
then:
|
|
- script.execute: led_pattern_wifi_connected
|
|
- if:
|
|
condition:
|
|
lambda: 'return state_name == "AP_FALLBACK";'
|
|
then:
|
|
- script.execute: led_pattern_ap_fallback
|
|
- if:
|
|
condition:
|
|
lambda: 'return state_name == "MQTT_SUCCESS";'
|
|
then:
|
|
- script.execute: led_event_mqtt_success
|
|
- if:
|
|
condition:
|
|
lambda: 'return state_name == "MQTT_FAILED";'
|
|
then:
|
|
- script.execute: led_event_mqtt_failed
|
|
- if:
|
|
condition:
|
|
lambda: 'return state_name == "OTA_UPDATE";'
|
|
then:
|
|
- script.execute: led_ota_update_progress
|