added a 10 minute warning post
This commit is contained in:
parent
dcb7f0f9d3
commit
6e5ccf49af
21
solar_bot.py
21
solar_bot.py
|
@ -59,7 +59,16 @@ def get_shutdown():
|
|||
time_to_shutdown = ts - time_now
|
||||
time_to_date = datetime.datetime.utcfromtimestamp(time_to_shutdown).strftime('%H:%M:%S')
|
||||
|
||||
return shutdown_date, time_to_date
|
||||
warning_time = ts - 600
|
||||
warning_to_date = datetime.datetime.utcfromtimestamp(warning_time).strftime('%Y-%m-%d %H:%M:%S')
|
||||
return shutdown_date, time_to_date, warning_to_date
|
||||
|
||||
def warn_shutdown():
|
||||
try:
|
||||
mastodon = Mastodon(access_token = settings.access_secret, api_base_url = settings.instance_url)
|
||||
mastodon.toot('Warning\nSystem Shutdown in 10minutes')
|
||||
except:
|
||||
logging.info('Failed to send toot')
|
||||
|
||||
def send_toot():
|
||||
logging.info('Preparing Toot')
|
||||
|
@ -73,7 +82,7 @@ def send_toot():
|
|||
max_power_today = r.get('max_power_today')
|
||||
load_power = load_current * batt_v_V
|
||||
|
||||
final_date, time_date = get_shutdown()
|
||||
final_date, time_date, warning_time = get_shutdown()
|
||||
|
||||
toot_to_send = 'Solarcene.community Power Data\nBattery Voltage: {}V\nBattery Current: {}mA\nPanel Voltage: {}V\nPanel Power: {}W\nLoad Current: {}A\nLoad Power: {}W\nYield Today: {}kWh\nMax Power Today: {}W\nUpdated every 60 minutes\n\nShutdown planned for {}UTC (in {})'.format(batt_v_V, main_current, panel_voltage, panel_power, load_current, load_power, yield_today, max_power_today, final_date, time_date)
|
||||
logging.info(toot_to_send)
|
||||
|
@ -90,7 +99,7 @@ def start_toot():
|
|||
logging.info('Sleeping for 60 seconds to allow mastodon to fully start')
|
||||
time.sleep(60)
|
||||
try:
|
||||
final_date, time_date = get_shutdown()
|
||||
final_date, time_date, warning_time = get_shutdown()
|
||||
mastodon = Mastodon(access_token = settings.access_secret, api_base_url = settings.instance_url)
|
||||
mastodon.toot('System Online\n\nShutdown planned for: {}UTC (in {})'.format(final_date, time_date))
|
||||
except:
|
||||
|
@ -103,11 +112,17 @@ if __name__ == '__main__':
|
|||
args = parser.parse_args()
|
||||
scheduler.add_job(send_toot, trigger='cron', minute=1)
|
||||
|
||||
|
||||
logging.info('Starting')
|
||||
mastodon_login()
|
||||
logging.info('Logged In')
|
||||
|
||||
os.system("shutdown -h 20:15")
|
||||
|
||||
final_date, time_date, warning_time = get_shutdown()
|
||||
print(warning_time)
|
||||
scheduler.add_job(warn_shutdown, trigger='date', run_date=warning_time )
|
||||
|
||||
start_toot()
|
||||
|
||||
ve = Vedirect(args.port, args.timeout)
|
||||
|
|
Loading…
Reference in New Issue