{"id":16397177,"url":"https://github.com/unreal4u/rpi3-magnetic-switch","last_synced_at":"2026-05-12T12:37:35.675Z","repository":{"id":146167602,"uuid":"170765415","full_name":"unreal4u/rpi3-magnetic-switch","owner":"unreal4u","description":"Code for the service that reads out a magnetic switch and turns on a relay","archived":false,"fork":false,"pushed_at":"2019-03-11T23:07:40.000Z","size":276,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-14T12:03:29.349Z","etag":null,"topics":["iot","mqtt","rpi3"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unreal4u.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-02-14T22:13:04.000Z","updated_at":"2019-10-01T11:39:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"753443e0-a670-4895-b5cf-9762944effaf","html_url":"https://github.com/unreal4u/rpi3-magnetic-switch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/unreal4u/rpi3-magnetic-switch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unreal4u%2Frpi3-magnetic-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unreal4u%2Frpi3-magnetic-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unreal4u%2Frpi3-magnetic-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unreal4u%2Frpi3-magnetic-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unreal4u","download_url":"https://codeload.github.com/unreal4u/rpi3-magnetic-switch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unreal4u%2Frpi3-magnetic-switch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32940061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T09:19:52.626Z","status":"ssl_error","status_checked_at":"2026-05-12T09:17:33.438Z","response_time":102,"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","mqtt","rpi3"],"created_at":"2024-10-11T05:09:23.115Z","updated_at":"2026-05-12T12:37:35.656Z","avatar_url":"https://github.com/unreal4u.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Raspberry Pi 3 Magnetic Switch + relay controller\n===========\n\nThis pure PHP implementation will read out a magnetic switch and depending on the input, it will control a relay,\nallowing for a light to be turned on or off.\n\nThe idea is that the light will turn on ASAP when the door is opened, and will turn the lights off with a configurable\ntimer when the door has been closed.\n\nIt will additionally inform a MQTT broker of the sensors and commands that are being sent.\n\nUsed materials\n--------\n\nThe materials used for this build are the following:\n\n* [Magnetic switch](https://www.aliexpress.com/item/Free-Shipping-5-pcs-MC-38-MC38-Wired-Door-Window-Sensor-Magnetic-Switch-Home-Alarm-System/32255881055.html?spm=a2g0s.9042311.0.0.27424c4dj3ALXd)\n* [Relay](https://www.aliexpress.com/item/Freeshipping-New-5V-2-Channel-Relay-Module-Shield-for-Arduino/1726504761.html?spm=a2g0s.9042311.0.0.27424c4dkd67Cr)\n* Raspberry Pi 3b+ (Although any old rPi should be able to handle this program)\n\nSchematics\n--------\n\nThe general connections are made using the following diagram:\n![Connections diagram](/magnetic-switch-kelder-schematics.png)\n\n**Disclaimer**: Please ignore any errors in above drawing, I'm not an electrician. That being said, above diagram is\nused to control devices dealing with AC voltage, if you don't even know what \"AC\" means, DO NOT use this guide and hire\nsomebody that knows about it!\n\n[AC voltages *CAN* kill you!](https://www.youtube.com/watch?v=trmxzUVT2eE)  \n[You don't believe me?](https://www.youtube.com/watch?v=snk3C4m44SY)\n\nPin layout is based on this diagram:\n![GPIO pin diagram](/rpi3-gpio-pins.png)\n\nHow to run the program\n--------\n\nThis program consists of 2 scripts: one that primarily checks out what the status of the door is and opens up the relay,\nwhile the other implements only a timer and will turn the relay down after the door has been closed.\n\nIt uses standard symfony components to achieve this. In the case of this program, calling the following script will\nstart the program:\n\n`sudo bin/console baseroom:door-sensor`\n\nIf you want to make it a cronjob, put the following line in your crontab:\n\n`*/2 * * * * sudo [ABSOLUTE_PATH_TO_APPLICATION]/bin/console readDoorSensor`\n\nThis script is run with sudo because it needs access to the GPIO. There might be more elegant ways to solve this issue,\nbut this one is the first one that came up to me and it works.\n\nOther information\n--------\n\nCheck out [PHP/GPIO](https://github.com/PiPHP/GPIO), without that repo, this would be impossible in its current form.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funreal4u%2Frpi3-magnetic-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funreal4u%2Frpi3-magnetic-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funreal4u%2Frpi3-magnetic-switch/lists"}