From 9f04bd32175c8633a1ccacb67cb8430aac74a2c3 Mon Sep 17 00:00:00 2001 From: Roving Ronin <108674933+Roving-Ronin@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:51:11 +1000 Subject: [PATCH] Add on_boot selector - Add on_boot selector and default to ON, as has been added to v2 plug. https://github.com/athom-tech/athom-configs/discussions/87 --- athom-smart-plug.yaml | 46 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/athom-smart-plug.yaml b/athom-smart-plug.yaml index 9ce4b96..824c6c8 100644 --- a/athom-smart-plug.yaml +++ b/athom-smart-plug.yaml @@ -10,9 +10,9 @@ substitutions: # Project Name project_name: "Athom Technology.Smart Plug V3" # Projection version denotes the release version of the yaml file, allowing checking of deployed vs latest version - project_version: "v1.0.3" + project_version: "v1.0.4" # Restore the relay (GPO switch) upon reboot to state: - relay_restore_mode: RESTORE_DEFAULT_OFF + relay_restore_mode: RESTORE_DEFAULT_ON # Set the update interval for sensors sensor_update_interval: 10s # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. @@ -50,6 +50,29 @@ esphome: board_build.mcu: esp32c3 board_build.variant: esp32c3 board_build.flash_mode: dio + on_boot: + - priority: 600 + then: + - select.set_index: + id: power_mode + index: !lambda |- + return id(restore_mode)-1; + - lambda: |- + switch(id(restore_mode)) + { + case 1:{ + id(relay).turn_off(); + break; + } + case 2:{ + id(relay).turn_on(); + break; + } + default:{ + break; + } + } + esp32: board: esp32-c3-devkitm-1 @@ -109,6 +132,25 @@ globals: restore_value: yes initial_value: '0.0' + - id: restore_mode + type: int + restore_value: yes + initial_value: "2" # 0 = Always_Off. 1 = Restore_Power_Off. 2 = Always_On. + +select: + - platform: template + name: "Power On State" + id: "power_mode" + optimistic: true + options: + - Always Off + - Always On + - Restore Power Off State + on_value: + then: + - lambda: |- + id(restore_mode)=i+1; + binary_sensor: - platform: status name: "Status"