@@ -34,8 +34,12 @@ static const char *TAG = "v-smarteq";
3434
3535#include " vehicle_smarteq.h"
3636
37- // can can1 tx st 634 40 01 72 00
37+ // can can1 tx st 634 40 01 00 00
3838OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandClimateControl (bool enable) {
39+ return CommandClimateControlEQ (enable, false , 0 , false );
40+ }
41+
42+ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandClimateControlEQ (bool enable, bool restart, int minutes, bool trickle) {
3943
4044 if (!IsCANwrite ())
4145 {
@@ -61,12 +65,11 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandClimateControl(bool en
6165 }
6266 }
6367
64- if (StandardMetrics .ms_v_bat_soc ->AsInt (0 ) < 31 )
68+ if (StdMetrics .ms_v_bat_soc ->AsInt (can_soc ) < 31 )
6569 {
6670 char msg[100 ];
67- snprintf (msg, sizeof (msg), " Scheduled precondition skipped: Battery SOC too low (%d%%)" ,
68- StandardMetrics.ms_v_bat_soc ->AsInt (0 ));
69- ESP_LOGW (TAG , " %s" , msg);
71+ snprintf (msg, sizeof (msg), " Scheduled precondition skipped: HV SOC too low (%d%%)" , StdMetrics.ms_v_bat_soc ->AsInt (can_soc));
72+ ESP_LOGI (TAG , " %s" , msg);
7073 MyNotify.NotifyString (" alert" , " climatecontrol.schedule" , msg);
7174 m_climate_restart_ticker = 0 ;
7275 m_climate_restart = false ;
@@ -80,111 +83,94 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandClimateControl(bool en
8083 return Success;
8184 }
8285
83- OvmsVehicle::vehicle_command_t res = Fail;
84-
8586 if (enable && !IsOnHVACEQ ())
8687 {
88+ CommandWakeup ();
8789 uint8_t data[4 ] = {0x40 , 0x01 , 0x00 , 0x00 };
8890 canbus *obd;
8991 obd = m_can1;
90- res = Fail;
9192 for (int i = 0 ; i < 15 ; i++)
9293 {
9394 if (IsOnHVACEQ ())
9495 {
95- ESP_LOGI ( TAG , " Climate control started " );
96- res = Success ;
96+ StdMetrics. ms_v_env_awake -> SetValue ( true );
97+ ESP_LOGD ( TAG , " Climate control is now on " ) ;
9798 break ;
9899 }
99100 obd->WriteStandard (0x634 , 4 , data);
100101 vTaskDelay (200 / portTICK_PERIOD_MS);
101102 }
103+
104+ if (IsOnHVACEQ ())
105+ {
106+ // if true, climate will be restarted after 5 minutes by Ticker1, if false, climate will not be restarted after 5 minutes
107+ m_climate_restart = restart;
108+ m_climate_restart_ticker = minutes;
109+ if (trickle)
110+ {
111+ ESP_LOGI (TAG , " activated 12V trickle charging successfully" );
112+ Notify12Vcharge ();
113+ }
114+ else
115+ {
116+ // add 2 minutes to display time if restart is true, because climate will be restarted after 5/10 minutes
117+ int minutes_display = restart ? minutes + 2 : 5 ;
118+ char msg[100 ];
119+ snprintf (msg, sizeof (msg), " %d minutes precondition started, HV SOC is %d%%" , minutes_display, StdMetrics.ms_v_bat_soc ->AsInt (can_soc));
120+ ESP_LOGI (TAG , " %s" , msg);
121+ MyNotify.NotifyString (" info" , " climatecontrol.schedule" , msg);
122+ }
123+ return Success;
124+ }
125+ else
126+ {
127+ if (trickle)
128+ {
129+ ESP_LOGI (TAG , " Failed to activate 12V trickle charging" );
130+ MyNotify.NotifyString (" info" , " 12v.trickle.charge" , " Failed to activate 12V trickle charging!" );
131+ }
132+ else
133+ {
134+ ESP_LOGI (TAG , " Failed to activate precondition" );
135+ MyNotify.NotifyString (" info" , " climatecontrol.schedule" ," Failed to activate precondition!" );
136+ }
137+ return Fail;
138+ }
102139 }
103140 else
104141 {
105- res = NotImplemented;
106- }
107- // fallback to default implementation?
108- if (res == NotImplemented)
109- {
110- res = OvmsVehicle::CommandClimateControl (enable);
142+ // fallback to default implementation?
143+ return OvmsVehicle::CommandClimateControl (enable);
111144 }
112- return res;
113145}
114146
115147OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandHomelink (int button, int durationms) {
116- // This is needed to enable climate control via Homelink for the iOS app
148+ // This is needed to enable climate control via Homelink
117149 ESP_LOGI (TAG , " CommandHomelink button=%d durationms=%d" , button, durationms);
118- OvmsVehicle::vehicle_command_t res = NotImplemented;
119150
120151 switch (button)
121152 {
122153 case 0 :
123154 {
124- res = CommandClimateControl (true );
125-
126- if (res == Success)
127- {
128- m_climate_restart = false ;
129- m_climate_restart_ticker = 0 ; // 5 minutes default runtime, no ticker required
130- ESP_LOGI (TAG , " Precondition activated successfully" );
131- MyNotify.NotifyString (" info" , " climatecontrol.schedule" ,
132- " 5 minutes precondition started" );
133- }
134- else
135- {
136- ESP_LOGE (TAG , " Failed to activate precondition (result=%d)" , res);
137- MyNotify.NotifyString (" error" , " climatecontrol.schedule" ,
138- " precondition failed to start" );
139- }
140- break ;
155+ // 5 minutes default runtime, no ticker required
156+ CommandClimateControlEQ (true ,false ,0 ,false );
157+ return Success;
141158 }
142159 case 1 :
143160 {
144- res = CommandClimateControl (true );
145-
146- if (res == Success)
147- {
148- m_climate_restart = true ;
149- m_climate_restart_ticker = 8 ; // 10 minutes
150- ESP_LOGI (TAG , " Precondition activated successfully" );
151- MyNotify.NotifyString (" info" , " climatecontrol.schedule" ,
152- " 10 minutes precondition started" );
153- }
154- else
155- {
156- ESP_LOGE (TAG , " Failed to activate precondition (result=%d)" , res);
157- MyNotify.NotifyString (" error" , " climatecontrol.schedule" ,
158- " precondition failed to start" );
159- }
160- break ;
161+ // 10 minutes runtime, will be restarted after 5 minutes by Ticker60, so total runtime will be 10 minutes
162+ CommandClimateControlEQ (true ,true ,8 ,false );
163+ return Success;
161164 }
162165 case 2 :
163166 {
164- res = CommandClimateControl (true );
165-
166- if (res == Success)
167- {
168- m_climate_restart = true ;
169- m_climate_restart_ticker = 12 ; // 15 minutes
170- ESP_LOGI (TAG , " Precondition activated successfully" );
171- MyNotify.NotifyString (" info" , " climatecontrol.schedule" ,
172- " 15 minutes precondition started" );
173- }
174- else
175- {
176- ESP_LOGE (TAG , " Failed to activate precondition (result=%d)" , res);
177- MyNotify.NotifyString (" error" , " climatecontrol.schedule" ,
178- " precondition failed to start" );
179- }
180- break ;
167+ // 15 minutes runtime, will be restarted after 5 and 10 minutes by Ticker60, so total runtime will be 15 minutes
168+ CommandClimateControlEQ (true ,true ,13 ,false );
169+ return Success;
181170 }
182171 default :
183- res = OvmsVehicle::CommandHomelink (button, durationms);
184- break ;
172+ return OvmsVehicle::CommandHomelink (button, durationms);
185173 }
186-
187- return res;
188174}
189175
190176OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandWakeup () {
@@ -215,7 +201,7 @@ OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandWakeup() {
215201 vTaskDelay (200 / portTICK_PERIOD_MS);
216202 }
217203 res = Success;
218- can_awake = true ;
204+ StdMetrics. ms_v_env_awake -> SetValue ( true ) ;
219205 ESP_LOGI (TAG , " Vehicle is now awake" );
220206 }
221207 else
0 commit comments