{"id":17981712,"url":"https://github.com/synesthesiam/nodemcu-home","last_synced_at":"2026-05-07T03:35:58.071Z","repository":{"id":149798876,"uuid":"199546316","full_name":"synesthesiam/nodemcu-home","owner":"synesthesiam","description":"NodeMCU Lua Code for Home Automation","archived":false,"fork":false,"pushed_at":"2019-07-30T01:16:16.000Z","size":318,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T13:11:28.218Z","etag":null,"topics":["esp8266","home-assistant","home-automation","lua","mpu6050","nodemcu"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/synesthesiam.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-07-30T00:41:31.000Z","updated_at":"2019-07-30T14:25:44.000Z","dependencies_parsed_at":"2023-06-02T16:30:17.893Z","dependency_job_id":null,"html_url":"https://github.com/synesthesiam/nodemcu-home","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synesthesiam%2Fnodemcu-home","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synesthesiam%2Fnodemcu-home/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synesthesiam%2Fnodemcu-home/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synesthesiam%2Fnodemcu-home/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synesthesiam","download_url":"https://codeload.github.com/synesthesiam/nodemcu-home/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247104312,"owners_count":20884205,"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","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":["esp8266","home-assistant","home-automation","lua","mpu6050","nodemcu"],"created_at":"2024-10-29T18:11:50.714Z","updated_at":"2026-05-07T03:35:58.021Z","avatar_url":"https://github.com/synesthesiam.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeMCU Lua Code for Home Automation\n\nThis repository contains code, firmware, and helper scripts for programming a [NodeMCU ESP8266 chip](https://github.com/nodemcu/nodemcu-firmware) (specifically [this one](https://www.amazon.com/gp/product/B010O1G1ES)).\n\n## Firmware\n\nThe included firmware was built with the NodeMCU [cloud build service](https://nodemcu-build.com/) to include a few extra modules (MQTT, HTTP, and others I can't remember).\n\n## Scripts\n\nThere are a few helper scripts in the `bin` directory for connecting to the ESP8266 and uploading firmware/code. You will need Python 2 installed for them to work. If necessary, a virtual environment will be created and the necessary software installed.\n\n### Serial Connection\n\nWith your ESP8266 connected, run:\n\n```bash\nbin/connect-serial.sh\n```\n\nto start a serial terminal session. This assumes the ESP8266 is connected on `/dev/ttyUSB0`. Press `CTRL + ]` to exit.\n\n### Upload Firmware\n\nTo upload the included firmware (in the `firmware` directory), just run:\n\n```bash\nbin/upload-firmware.sh\n```\n\n### Upload Code\n\nOnce you have the ESP8266 programmed, you can upload all of the `.lua` files in a directory with:\n\n```bash\nbin/upload-code.sh \u003cDIR\u003e\n```\n\nwhere `\u003cDIR\u003e` is the directory containing `init.lua`, etc.\n\n## Lua Code\n\nThe included code under `src` is for two different use cases:\n\n1. A magnetic door sensor ([reed switch](https://www.amazon.com/Gikfun-Sensor-Magnetic-Switch-Arduino/dp/B0154PTDFI))\n2. A gyro washer/dryer sensor ([MPU6050](https://www.amazon.com/gp/product/B008BOPN40))\n\nBoth projects uses the same `init.lua` script that automatically gets executed at boot. This script reads a `secrets.lua` file (not included), which contains the WiFi SSID and password to connect to. After a brief delay, it automatically connects to WiFi and runs `application.lua`, which contains project-specific code.\n\nThe `init.lua` script also supports downloading the `application.lua` code from an HTTP server, allowing for \"over the air\" updates (with a reboot). If you define `CODE_HOST` in `secrets.lua`, the ESP8266 will download `http://CODE_HOST/nodemcu/\u003cchipid\u003e/application.lua` on boot (where `\u003cchipid\u003e` is from [node.chipid()](https://nodemcu.readthedocs.io/en/master/modules/node/#nodechipid)).\n\n### Helper Functions\n\nThere are some shared helper functions defined in:\n\n* `mqtt.lua`\n    * Keeps an MQTT connection alive by pinging itself every second\n* `led.lua`\n    * Turn the built-in blue and red LEDs on and off\n\n### Door Sensor\n\nReads the state of a magnetic (reed) switch on GPIO5 (open high) and reports it via MQTT. The switch state is both polled every second and caught via interrupt.\n\nThe result is used by a [Home Assistant binary sensor](https://www.home-assistant.io/components/binary_sensor/).\n\nExcerpt from `configuration.yaml`:\n\n```yaml\nbinary_sensor:\n  - platform: mqtt\n    name: \"Back Door Sensor\"\n    state_topic: \"home-assistant/back-door\"\n    value_template: \u003e\n      {% if value != \"closed\" %}\n      ON\n      {% else %}\n      OFF\n      {% endif %}\n```\n\n### Washer/Dryer Sensor\n\nReads the gyro state of the MPU6050 every second and publishes it out as JSON via MQTT.\n\nThe results are tracked by a [Home Assistant filter sensor](https://www.home-assistant.io/components/filter/) to create a moving average. This (thresholded) value is then used by a [Home Assistant binary sensor](https://www.home-assistant.io/components/binary_sensor/) to determine whether the washer/dryer is on or off (mine are next to each other).\n\nExcerpt from `configuration.yaml`:\n\n```yaml\nsensor:\n  - platform: mqtt\n    name: laundry_motion_raw\n    state_topic: \"home-assistant/laundry\"\n    value_template: \"{{ value_json.gyro }}\"\n  - platform: filter\n    name: laundry_motion\n    entity_id: sensor.laundry_motion_raw\n    filters:\n      - filter: time_simple_moving_average\n        window_size: 00:05\n        precision: 2\n        \nbinary_sensor:\n  - platform: threshold\n    name: \"Laundry Sensor\"\n    entity_id: sensor.laundry_motion\n    upper: 5.0\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynesthesiam%2Fnodemcu-home","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynesthesiam%2Fnodemcu-home","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynesthesiam%2Fnodemcu-home/lists"}