From c5e52cc7ae8cf08ae5cb550ed1c6306cf8e74ff4 Mon Sep 17 00:00:00 2001 From: SylvainGa <49377866+SylvainGa@users.noreply.github.com> Date: Tue, 24 Sep 2024 21:31:15 -0400 Subject: [PATCH] Daily status can be omitted by setting daily_status to False in Email section --- check_tesla_windows_mqtt.ini | 3 +++ check_tesla_windows_mqtt.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/check_tesla_windows_mqtt.ini b/check_tesla_windows_mqtt.ini index 5cbe0a1..91d8991 100644 --- a/check_tesla_windows_mqtt.ini +++ b/check_tesla_windows_mqtt.ini @@ -28,6 +28,9 @@ password: # Recipient address that will receive the emails to: +# Sends a daily status message at sunset +daily_status: True + [Timers] # Frequency of the timer and watchdog threads in seconds. If it hasn't ran in that amount of time, # the script will self destruct and expect the systemd service will auto relaunch it. diff --git a/check_tesla_windows_mqtt.py b/check_tesla_windows_mqtt.py index a8889a2..11c38f8 100644 --- a/check_tesla_windows_mqtt.py +++ b/check_tesla_windows_mqtt.py @@ -561,6 +561,7 @@ def on_timer(): if (g_debug & 3) > 1: printWithTime("Tesla-Timer: Debug: It's night with " + str(tomorrow_sr - now_tz) + " until sunrise") if g_night == False or g_retry == 10: # First time going in since the sun has set, check if we're parked with the windows down and if so, close them + sendEmail = True if g_retry == 10: # If we got here because we timed out, reset it back to 0 g_retry = 0 g_night = True @@ -600,11 +601,15 @@ def on_timer(): emailBody = "Windows were closed at sunset (" + current_time + ")" emailSubject = "Tesla-Timer: " + emailBody - try: - sender = Emailer() - sender.sendmail(sendTo, emailSubject, emailBody) - except Exception as error: - printWithTime("Tesla-Timer: Unable to send email because of exception: " + type(error).__name__ + ")") + if sendDailyEmail == False: + sendEmail = False + + if sendEmail: + try: + sender = Emailer() + sender.sendmail(sendTo, emailSubject, emailBody) + except Exception as error: + printWithTime("Tesla-Timer: Unable to send email because of exception: " + type(error).__name__ + ")") printWithTime(emailSubject) @@ -732,6 +737,7 @@ def on_timer(): tessie_token = Config.get('Tesla', 'tessie_token') wake_at_start = int(Config.get('Tesla', 'wake_at_start')) sendTo = Config.get('Email', 'to') +sendDailyEmail = Config.getboolean('Email', 'daily_status') station_latitude = float(Config.get('MQTT', 'latitude')) station_longitude = float(Config.get('MQTT', 'longitude'))