{"id":31794457,"url":"https://github.com/0xrelogic/homebrain","last_synced_at":"2026-02-17T12:31:36.327Z","repository":{"id":309421497,"uuid":"1036231560","full_name":"0xReLogic/HomeBrain","owner":"0xReLogic","description":"Prolog-based smart home rule engine and simulator (SWI‑Prolog). Devices, sensors, facts, rules, interactive loop.","archived":false,"fork":false,"pushed_at":"2025-08-11T19:09:33.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-10T19:45:55.981Z","etag":null,"topics":["iot","prolog"],"latest_commit_sha":null,"homepage":"https://0xReLogic.github.io/HomeBrain","language":"Prolog","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xReLogic.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-11T18:56:27.000Z","updated_at":"2025-08-15T15:45:00.000Z","dependencies_parsed_at":"2025-08-11T21:07:55.062Z","dependency_job_id":"ae424b7f-7092-4bac-b84b-4e0c4f8feadd","html_url":"https://github.com/0xReLogic/HomeBrain","commit_stats":null,"previous_names":["0xrelogic/homebrain"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0xReLogic/HomeBrain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xReLogic%2FHomeBrain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xReLogic%2FHomeBrain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xReLogic%2FHomeBrain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xReLogic%2FHomeBrain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xReLogic","download_url":"https://codeload.github.com/0xReLogic/HomeBrain/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xReLogic%2FHomeBrain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29543904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T12:21:34.159Z","status":"ssl_error","status_checked_at":"2026-02-17T12:21:02.057Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["iot","prolog"],"created_at":"2025-10-10T19:45:49.133Z","updated_at":"2026-02-17T12:31:36.320Z","avatar_url":"https://github.com/0xReLogic.png","language":"Prolog","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HomeBrain\n\n[![License](https://img.shields.io/github/license/0xReLogic/HomeBrain)](LICENSE)\n[![Last Commit](https://img.shields.io/github/last-commit/0xReLogic/HomeBrain)](https://github.com/0xReLogic/HomeBrain/commits)\n[![Issues](https://img.shields.io/github/issues/0xReLogic/HomeBrain)](https://github.com/0xReLogic/HomeBrain/issues)\n[![Stars](https://img.shields.io/github/stars/0xReLogic/HomeBrain)](https://github.com/0xReLogic/HomeBrain/stargazers)\n[![SWI‑Prolog](https://img.shields.io/badge/Prolog-SWI%E2%80%91Prolog-blue)](https://www.swi-prolog.org)\n\nHomeBrain is a Prolog-based rule engine and simulator for smart-home automation. It models devices, sensors, and global facts as a dynamic state, evaluates rules, prints decisions, and applies actions. Includes an interactive loop for hands-on simulation.\n\n## Features\n\n- Dynamic state predicates (mutable at runtime):\n  - `device(ID, Type, [Properties])`\n  - `sensor(ID, Type, [Properties])`\n  - `fact(Key, Value)`\n- Rulebook with readable schema:\n  - `rule(Name, [Conditions], [Actions]).`\n  - Conditions on time, sensors, devices, and facts\n  - Actions to update devices, sensors, and facts\n- Engine:\n  - Evaluates rules, prints matched rules and decisions\n  - Applies actions by updating dynamic state (retract/assert)\n- Interactive loop (`run_loop/0`):\n  - Run ticks and change inputs (time, motion, occupants, temperature)\n  - Inspect current state\n\n## Requirements\n\n- SWI-Prolog (tested with swipl for Windows)\n  - Add SWI-Prolog to PATH or invoke via absolute path\n\n## Project Structure\n\n- `house_state.pl` — Initial dynamic state: devices, sensors, and global facts\n- `rules.pl`       — Rulebook\n- `engine.pl`      — Engine: condition evaluation, decision printing, action application, interactive loop\n- `todo.txt`       — Original Indonesian plan + English updated roadmap\n- `.gitignore`     — Ignore build artifacts, logs, editor files\n\n## Quick Start\n\nRun the interactive loop from the project directory:\n\n```powershell\nswipl -q -s engine.pl -g run_loop -t halt\n```\n\nOr run a single tick:\n\n```powershell\nswipl -q -s engine.pl -g run_simulation_tick -t halt\n```\n\nIf SWI-Prolog is not in PATH, use the absolute path to `swipl.exe`.\n\n## State Model\n\n- Devices and sensors store properties as compound terms in a list, e.g. `[status(off), brightness(100)]`.\n- Global facts capture environment and context, e.g. `fact(time, '22:15')` or `fact(occupants_at_home, yes)`.\n\nExample from `house_state.pl`:\n\n```prolog\ndevice(bedroom_light, light, [status(off), brightness(100)]).\ndevice(bedroom_ac, ac, [status(off), target_temp(24)]).\n\nsensor(living_room_motion_sensor, motion, [status(no_motion)]).\nsensor(bedroom_temp_sensor, temperature, [value(29)]).\n\nfact(time, '22:15').\nfact(occupants_at_home, yes).\n```\n\n## Rules\n\nSchema:\n\n- `rule(Name, [Conditions], [Actions]).`\n- Conditions (examples):\n  - `condition(time, between, '21:00', '06:00')`\n  - `condition(time, equals, '22:30')`\n  - `condition(sensor, SensorId, Property, Op, Value)`  % `Op` in `\u003e`, `\u003c`, `equals`\n  - `condition(device, DeviceId, Property, equals, Value)`\n  - `condition(fact, Key, equals, Value)`\n- Actions (examples):\n  - `action(DeviceId, set_status, on|off|locked|unlocked)`\n  - `action(DeviceId, set_brightness, IntPercent)`\n  - `action(DeviceId, set_target_temp, IntCelsius)`\n  - `action(sensor(SensorId), set, prop(Key,Value))`\n  - `action(fact(Key), set, Value)`\n\nExample rules (`rules.pl`):\n\n```prolog\nrule('Turn on AC if hot at night',\n     [ condition(time, between, '21:00', '06:00'),\n       condition(sensor, bedroom_temp_sensor, value, '\u003e', 27),\n       condition(device, bedroom_ac, status, equals, off)\n     ],\n     [ action(bedroom_ac, set_status, on)\n     ]).\n\nrule('Night motion turns on living room light 50%',\n     [ condition(time, between, '22:00', '06:00'),\n       condition(sensor, living_room_motion_sensor, status, equals, motion),\n       condition(device, living_room_light, status, equals, off)\n     ],\n     [ action(living_room_light, set_brightness, 50),\n       action(living_room_light, set_status, on)\n     ]).\n\nrule('Simulate living room motion at 22:15',\n     [ condition(time, equals, '22:15')\n     ],\n     [ action(sensor(living_room_motion_sensor), set, prop(status, motion))\n     ]).\n\nrule('Set occupants to away at 22:15',\n     [ condition(time, equals, '22:15')\n     ],\n     [ action(fact(occupants_at_home), set, no)\n     ]).\n```\n\n## Engine\n\nKey predicates (`engine.pl`):\n\n- `run_simulation_tick/0` — load state/rules, evaluate rules, print decisions, apply actions\n- `check_condition/1` — evaluate supported condition forms\n- `apply_actions/1`, `apply_action/1` — update dynamic state (devices, sensors, facts)\n- `set_device_prop/3`, `set_sensor_prop/3`, `set_fact/2` — state mutation helpers\n- `run_loop/0` — interactive menu\n\nInteractive operations:\n\n- Run tick\n- Set time (HH:MM)\n- Toggle occupants_at_home\n- Set living room motion status (motion/no_motion)\n- Set bedroom temperature (number)\n- Show current state\n\n## Extending\n\n- Add rules: append to `rules.pl` using the same schema.\n- Add actions: extend `apply_action/1` and implement corresponding helpers if needed.\n- Add conditions: extend `check_condition/1` and supporting utilities.\n\nRecommended roadmap:\n\n- Persist state to a file (e.g., `current_state.pl`) after each tick\n- Rule priorities and conflict resolution\n- Debounce/cooldown for motion-triggered rules\n- Negation in conditions (e.g., `condition(not(...))`)\n- Scenes (composite actions) and relative actions (increase/decrease)\n- Logging/history of decisions to files for debugging\n- Optional: basic HTTP UI using SWI-Prolog HTTP libraries\n\n## License\n\nThis project is licensed under the MIT License. See `LICENSE` for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xrelogic%2Fhomebrain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xrelogic%2Fhomebrain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xrelogic%2Fhomebrain/lists"}