{"id":22703398,"url":"https://github.com/arshitarora/day-night-server","last_synced_at":"2025-10-05T20:15:23.478Z","repository":{"id":169390512,"uuid":"643810238","full_name":"ArshitArora/day-night-server","owner":"ArshitArora","description":"a python script to put the home \"server\" to sleep when wifi is disconnected at night, and wake up early the next day","archived":false,"fork":false,"pushed_at":"2023-06-09T04:42:45.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-16T19:27:48.970Z","etag":null,"topics":["automation","python-automation","scripts","self-hosted","server","sleep","sleep-computer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArshitArora.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-22T07:52:07.000Z","updated_at":"2023-07-03T17:47:50.000Z","dependencies_parsed_at":"2023-07-25T16:19:57.250Z","dependency_job_id":null,"html_url":"https://github.com/ArshitArora/day-night-server","commit_stats":null,"previous_names":["arshitarora/12hour-server","delicate-jerk/day-night-server","arshitarora/day-night-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ArshitArora/day-night-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArshitArora%2Fday-night-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArshitArora%2Fday-night-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArshitArora%2Fday-night-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArshitArora%2Fday-night-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArshitArora","download_url":"https://codeload.github.com/ArshitArora/day-night-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArshitArora%2Fday-night-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278510950,"owners_count":25999013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","python-automation","scripts","self-hosted","server","sleep","sleep-computer"],"created_at":"2024-12-10T08:10:31.417Z","updated_at":"2025-10-05T20:15:23.458Z","avatar_url":"https://github.com/ArshitArora.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 12-hour-server\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![](https://img.shields.io/github/license/RoguedBear/12-hour-server)](LICENSE)\n\n\n\n\u003e a python script to put the home \"server\" to sleep when wifi is disconnected at night, and wake up early the next day\n\nNote: This script will only run on Linux (more specifically, tested on Ubuntu/Debian). **WILL NOT RUN ON WINDOWS**\n\n## What does this script do?\n\n\nif you have an old computer/laptop you use as your home server, \nbut don't quite want it to run 24x7, but rather only when your internet (router) is active.\n\nIn other words:\n- Computer should go to sleep when you turn off your router\n- Computer should wake up when you turn on your internet router\n\nThis is what this program does.\n\n## How to use it?\n\n---\n- Clone the repository\n- Make a file `config.yaml` whose contents should be same as in [config[TEMPLATE].yaml](config%5BTEMPLATE%5D.yaml):\n    ```yaml\n    # wired, wireless, any: connection type you want the program to check for internet connectivity\n    connection type: any\n\n    # Provide time in 24hr format\n    night phase:\n      start time: 23:20\n      end time: 23:40\n      # this timeout will be used as the frequency to check internet connectivity\n      timeout: 7 # seconds\n    morning phase:\n      start time: 8:30\n      end time: 10:30\n      # this timeout will be used as the frequency to check internet connectivity\n      timeout: 300 # seconds\n\n    # This timeout will be used to change the default timeout.\n    timeout: 90\n\n    # connectivity function *optional, by default uses v2\n    # you probably don't even need this in your config. Refer advanced usage\n    connectivity_method: 'v2' # one of 'v2', 'v3', 'v2+v3'\n\n    # If this key is present, program's thread would periodically wake up, check phases again and set a backup wake timer\n    # of this interval (or less).\n    sleep_interval: 1800 # seconds\n\n    logging level: 10 # 10 for DEBUG, 20 for INFO, 30 for WARNING, 40 for ERROR, 50 for CRITICAL logging level\n\n    # Optional\n    telegram:\n      BOT_TOKEN: YOUR TOKEN HERE\n      CHAT_ID: YOUR CHAT ID HERE\n\n    ```\n- Install requirements.txt: `pip install -r requirements.txt`\n- Run `./smart_sleep.py` from repository root. Make sure you have python3.8+ \\\n**Note: Program will run as [sudo] because the underlying command `rtcwake` which sets waketimers needs [sudo] to run**\n\n## Viewing logs\n\n\nThe program creates 2 log files. one containing the normal logs (`logs.log`), and the other containing the ANSI color codes (`logs_color.log`)\nIf you want to see the logs of this program by ssh-ing into the server computer, then there are 2 ways for that:\n\n1) [To view logs with color] `less -R +F Path_to_repository_root/logs/logs_color.log`\n2) [To view plain logs without color] `tail -f Path_to_repository_root/logs/logs.log`\n\n## Reporting Issues:\n\nI haven't polished the program and fixed every bug because i needed this script to be made fast according to my needs.\nIf you encounter any bugs, feel free to open an issue or a pull request.\n\n**Disclaimer to \\*Potential\\* Contributors: This script is unnecessarily long and i apologise for that**\n\n## Advanced Usage\n\n### Connectivity methods\n\nup until release [v1.1.0-lw](https://github.com/RoguedBear/12-hour-server/releases/tag/v1.1.0-lw), the program used a\nmethod called `check_connected_to_internetV2`. This is the v2 method which checks for internet connectivity by\npolling `carrier` \u0026 `operstate` in directory `/sys/class/\u003cyour network device name\u003e/`\n\nSince i moved onto a complex network setup involving a secondary router that acts as a DHCP relay, `operstate`\n\u0026 `carrier` both showed `up`/`1` as their output. even if the main router was down and the device had no IP address\nassigned to it.\n\nSo to make the script work, the v3 method (`check_connected_to_internetV3`), now pings the default gateway to check if\nmain router is still up or not.\n\nYou'd be fine with using `connectivity_method` as `v2` as long as the device connects to the main router. Or, you can\nswitch to using the ping method by setting `connectivity_method` to `v3` if you want that. at the time of writing,\nhaven't put the ping method to much irl use and the v2 method works just as fine.\n\n**update:** 6 months in running the script on a daily basis, v3 works flawlessly. so you can use any.\n\n## Known issue:\n\n- the timings are right, but the date could be off. since im using `timedelta` instead of `time` or `datetime`. too far\n  into the project, not gonna bother changing it until i get an issue or pull request about it ¯\\_(ツ)_/¯\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farshitarora%2Fday-night-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farshitarora%2Fday-night-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farshitarora%2Fday-night-server/lists"}