File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,11 +137,22 @@ void SecTouchFan::control(const fan::FanCall &call) {
137137
138138 // if new state and no speed
139139 if (call.get_state ().has_value () && !call.get_speed ().has_value ()) {
140- // OFF
141- ESP_LOGI (TAG, " [State Update for %d] - Requesting just state OFF but device is already OFF. Requesting anyway" ,
142- this ->level_id );
143- turn_off_sec_touch_hardware_fan ();
144- return ;
140+ if (call.get_state ().value () == 0 && old_state == 0 ) {
141+ // OFF
142+ ESP_LOGI (TAG, " [State Update for %d] - Requesting just state OFF but device is already OFF. Requesting anyway" ,
143+ this ->level_id );
144+ turn_off_sec_touch_hardware_fan ();
145+ return ;
146+ }
147+
148+ if (call.get_state ().value () == 1 && old_state == 0 ) {
149+ // ON
150+ ESP_LOGI (TAG, " [State Update for %d] - Requesting just state ON" , this ->level_id );
151+ // Use the current speed if it exists, otherwise use 1
152+ // TODO Use a configuration https://github.com/distante/esphome-components/issues/10
153+ int speed_to_set = (this ->speed > 0 ) ? this ->speed : 1 ;
154+ this ->speed = speed_to_set;
155+ }
145156 }
146157
147158 // ON
You can’t perform that action at this time.
0 commit comments