dgtlmoon/changedetection.io · warning · ValueError

Invalid day_of_week: '{day_of_week}'. Must be a valid weekda

Error message

Invalid day_of_week: '{day_of_week}'. Must be a valid weekday name.

What it means

ValueError raised by am_i_inside_time in changedetectionio/time_handler.py when the day_of_week argument (after .capitalize()) is not a key of the Weekday enum. Valid names are the weekday strings accepted by the Weekday enum (e.g. 'monday'..'sunday', case-insensitive thanks to capitalize).

Source

Thrown at changedetectionio/time_handler.py:39

        duration: int = 15,
) -> bool:
    """
    Determines if the current time falls within a specified time range.

    Parameters:
        day_of_week (str): The day of the week (e.g., 'Monday').
        time_str (str): The start time in 'HH:MM' format.
        timezone_str (str): The timezone identifier (e.g., 'Europe/Berlin').
        duration (int, optional): The duration of the time range in minutes. Default is 15.

    Returns:
        bool: True if the current time is within the time range, False otherwise.
    """
    # Parse the target day of the week
    try:
        target_weekday = Weekday[day_of_week.capitalize()]
    except KeyError:
        raise ValueError(f"Invalid day_of_week: '{day_of_week}'. Must be a valid weekday name.")

    # Parse the start time
    try:
        hour, minute = map(int, time_str.split(':'))
        if not (0 <= hour <= 23 and 0 <= minute <= 59):
            raise ValueError
    except (ValueError, AttributeError):
        raise ValueError(f"Invalid time_str: '{time_str}'. Must be in 'HH:MM' format.")

    # Get the current time in the specified timezone
    try:
        now_tz = arrow.now(timezone_str.strip())
    except Exception as e:
        raise ValueError(f"Invalid timezone_str: '{timezone_str}'. Must be a valid timezone identifier.")

    # Check if the current day matches the target day or overlaps due to duration
    current_weekday = now_tz.weekday()
    # Create start datetime for today in target timezone

View on GitHub (pinned to 5d9c7c6da7)

Solutions

  1. Use full English weekday names exactly: monday, tuesday, wednesday, thursday, friday, saturday, sunday
  2. Strip whitespace and lowercase before storing/submitting the value
  3. Validate schedule config against the allowed list before saving the watch
  4. If abbreviations are needed, map them yourself ('mon'->'monday') before calling am_i_inside_time

Example fix

# before
am_i_inside_time('mon', '09:00', '1', 'utc')
# after
am_i_inside_time('monday', '09:00', '1', 'utc')
Defensive patterns

Strategy: validation

Validate before calling

VALID_DAYS = {'monday','tuesday','wednesday','thursday','friday','saturday','sunday'}
if day_of_week.strip().lower() not in VALID_DAYS:
    raise ValueError('day must be a full weekday name')

Type guard

def is_valid_weekday(s: str) -> bool:
    return s.strip().lower() in {'monday','tuesday','wednesday','thursday','friday','saturday','sunday'}

Try / catch

from changedetectionio.time_handler import am_i_inside_time
try:
    inside = am_i_inside_time(day, '09:00', '1', 'UTC')
except ValueError as e:
    return bad_request(str(e))

Prevention

When it happens

Trigger: Calling am_i_inside_time with day_of_week like 'mon', 'tuesday ', 'weekday', 'Mon-day', or a non-English day name — Weekday['Mon'] raises KeyError which is converted to this ValueError.

Common situations: Watch time-schedule settings edited via API/script with abbreviated day names; locale differences (users entering localized day names); trailing spaces or empty strings from form parsing; malformed JSON in watch 'time_between_check' schedule config.

Related errors


AI-assisted analysis of dgtlmoon/changedetection.io@5d9c7c6da7 (2026-08-27). Data as JSON: /api/errors/74c60bae4c822d0b. Report an issue: GitHub.