# Exception

hours_since_last_water = db_helper.get_watered()

if hours_since_last_rules > time_since_rules_check:
    if hours_since_last_water > exception_hours_between_watering:
        hold_watering = False
    else:
        hold_watering = True

# If allowed, trigger relay to run sprinkler for 30 mins

if hold_watering == False:
    start_time = time.time()
    relay.ON_1()
    time.sleep(watering_duration)
    relay.OFF_1()
    end_time = time.time()
    watered = True
    duration = end_time - start_time

# Add record to database

insert_stmt = """
INSERT INTO watering_log
(watered, duration, hours_since_last_rules,  hours_since_last_water)
VALUES
({},{},{},{})""".format(watered, duration, hours_since_last_rules,
                        hours_since_last_water)

db_helper.insert_data(insert_stmt)