I have a shelly I want to switch to normal mode (aka switch directly controls the relay instead of the bulbs) when it’s disconnected from the API. The on_client_connected actions all work when the device first boots, but afterward, if the API disconnects, it does not run the on_client_connected actions again.
I am using this yaml:
api:
encryption:
key:
on_client_disconnected:
then:
- lambda: |-
id(light_mode_restore_value) = id(mode).state;
id(light_mode_restore_sensor).publish_state(id(light_mode_restore_value));
id(api_status).publish_state("API Disconnected");
- select.set:
id: mode
option: "Normal Mode"
on_client_connected:
then:
- lambda: |-
ESP_LOGI("api", "Reconnected to HA, restoring mode: %s", id(light_mode_restore_value).c_str());
id(api_status).publish_state("API Connected");
- select.set: # Step 2: Set the select component to the saved value
id: mode
option: !lambda 'return id(light_mode_restore_value);' # Use the saved global value as the new option
I can still control the device with HA so I’m pretty sure the device isn’t still disconnected.
Any ideas?
