Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Scripts/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
MAX_WATER_LEVEL = TANK_HEIGHT - TOP_EMPTY_DISTANCE
TWO_THIRD_LEVEL = MAX_WATER_LEVEL // 3 * 2 # Two-thirds full level

CHECK_INTERVAL_SECONDS = 5 # Check distance every 5 seconds
CHECK_INTERVAL_SECONDS = 0.5 # Check distance every 0.5 seconds
MAX_PRE_NIGHT_FILL_TIME = 600

NIGHT_12AM = 0
Expand Down
24 changes: 17 additions & 7 deletions Scripts/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def main():
morning8RunDone = True

# Afternoon valve operation
if now.hour == AFTERNOON_5PM and not aftrn5RunDone:
if now.hour == NOON_12PM and not aftrn5RunDone:
print("Afternoon run: Activating valves.")
gpio.output(VALVE1_PIN, True)
gpio.output(VALVE2_PIN, True)
Expand All @@ -182,7 +182,7 @@ def main():
aftrn5RunDone = True

# Evening valve operation
if now.hour == NIGHT_9PM and not evening9RunDone:
if now.hour == AFTERNOON_5PM and not evening9RunDone:
print("Evening run: Activating valves.")
gpio.output(VALVE1_PIN, True)
gpio.output(VALVE2_PIN, True)
Expand Down Expand Up @@ -217,16 +217,17 @@ def main():

waterLevel = TANK_HEIGHT - distance
motorStatus = rtDb.get("motorStatus", "OFF")
print(f"!!!! Motor Status {motorStatus}; Config Update Available: {configUpdateAvailable} !!!!")
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement with excessive exclamation marks appears to be temporary debugging code that should be removed or converted to proper logging before production.

Copilot uses AI. Check for mistakes.


if configUpdateAvailable:
# Apply config from rtDb.json both for Manual and Auto modes
if motorStatus == "ON":
gpio.output(MOTOR_PIN, True)
print(f"{currentMode} mode - Config update: Motor ON")
print(f">>> {currentMode} mode - Config update: Motor ON")
else:
gpio.output(MOTOR_PIN, False)
print(f"{currentMode} mode - Config update: Motor OFF")
print(f">>> {currentMode} mode - Config update: Motor OFF")

if currentMode == "Manual":
pass
Expand Down Expand Up @@ -269,10 +270,19 @@ def main():

lastCheckTime = currentTime

if configUpdateAvailable or motorStatus != lastMotorStatus or waterLevel != lastWaterLevel:
writeRtDb(motorStatus = motorStatus, tankLevel = waterLevel, configUpdateAvailable = False)
# Update database if there are changes
dbUpdates = {}
if motorStatus != lastMotorStatus:
dbUpdates["motorStatus"] = motorStatus
lastMotorStatus = motorStatus
lastWaterLevel = waterLevel

if waterLevel != lastWaterLevel:
dbUpdates["tankLevel"] = waterLevel
lastWaterLevel = waterLevel

if dbUpdates:
print(f"Updating DB with: {dbUpdates}")
writeRtDb(**dbUpdates)

# Smart sleep: shorter sleep when config updates are expected
if configUpdateAvailable:
Expand Down
13 changes: 4 additions & 9 deletions Scripts/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ def readRtDb():
return {}


def writeRtDb(motorStatus=None, tankLevel=None, configUpdateAvailable=None, mode=None):
def writeRtDb(**kwargs):
db = readRtDb()
if motorStatus is not None:
db["motorStatus"] = motorStatus
if tankLevel is not None:
db["tankLevel"] = tankLevel
if configUpdateAvailable is not None:
db["configUpdateAvailable"] = configUpdateAvailable
if mode is not None:
db["mode"] = mode
if not kwargs:
return # No changes to write
db.update(kwargs)
try:
with open(RT_DB_FILE, 'w') as f:
json.dump(db, f)
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
appVersion: 1.3.2.1009
appVersion: 1.3.3.1010