Created
November 9, 2023 08:07
-
-
Save tserong/e9ba97753c5c554c3a601979192dcae4 to your computer and use it in GitHub Desktop.
Set the minum state of charge to the specified value, or zero if it's a maintenance day and the --check-maintenance paramenter is set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import dbus | |
import logging | |
import requests | |
from datetime import datetime | |
# Note that when log output lands in /var/log/messages via cron, lines are | |
# truncated at about 250 characters for some reason. | |
logging.basicConfig(level=logging.INFO, format='set-minsoc.py: %(levelname)s: %(message)s') | |
logger = logging.getLogger(__name__) | |
HOURS = 60 * 60 | |
DAYS = 60 * 60 * 24 | |
def is_maintenance_day(): | |
# If it's less than 24 hours until maintenance is due when | |
# this script is run, we know today is a maintenance day | |
status = requests.get(f'http://{args.bms_ip}:3000/rest/1.0/status').json() | |
strip_pump_run_target = status['list'][0]['strip_pump_run_target'] | |
strip_pump_run_timer = status['list'][0]['strip_pump_run_timer'] | |
next_strip = strip_pump_run_target - strip_pump_run_timer | |
return next_strip / DAYS < 1.3 | |
def set_min_soc(): | |
try: | |
bus = dbus.SystemBus() | |
o = bus.get_object('com.victronenergy.settings', | |
'/Settings/CGwacs/BatteryLife/MinimumSocLimit') | |
if args.check_maintenance and is_maintenance_day(): | |
o.SetValue(0) | |
logger.info("Set MinSOC 0% (maintenance day)") | |
else: | |
o.SetValue(args.min_soc) | |
logger.info(f"Set MinSOC {args.min_soc}%") | |
except Exception as e: | |
logger.error(e) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser("Set MinSoC") | |
parser.add_argument("bms_ip", help="ZCell BMS IP address") | |
parser.add_argument("min_soc", help="Minimum SOC to set") | |
parser.add_argument("--check-maintenance", help="Sets MinSOC to zero if it's a maintenance day", | |
action="store_true") | |
args = parser.parse_args() | |
set_min_soc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment