From 082c51ba77e8e9081345a6bb2ef180548fe4f01a Mon Sep 17 00:00:00 2001 From: Aiden <37043404+tarontop@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:23:17 +0800 Subject: [PATCH] Add optional power restore mode Add optional power restore mode --- athom-smart-plug-v2.yaml | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/athom-smart-plug-v2.yaml b/athom-smart-plug-v2.yaml index 0dce24f..c362cde 100644 --- a/athom-smart-plug-v2.yaml +++ b/athom-smart-plug-v2.yaml @@ -27,7 +27,28 @@ esphome: project: name: "${project_name}" version: "${project_version}" - + on_boot: + - priority: -100 + 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; + } + } esp8266: board: esp8285 restore_from_flash: true @@ -68,6 +89,24 @@ globals: type: float restore_value: yes initial_value: '0.0' + - id: restore_mode + type: int + restore_value: yes + initial_value: "3" + +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