{"id":18925931,"url":"https://github.com/ts1/piir","last_synced_at":"2025-04-15T13:32:19.851Z","repository":{"id":45660331,"uuid":"291028281","full_name":"ts1/PiIR","owner":"ts1","description":"IR remote control for Raspberry Pi","archived":false,"fork":false,"pushed_at":"2021-04-10T02:13:22.000Z","size":407,"stargazers_count":34,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T22:06:28.073Z","etag":null,"topics":["pigpio","raspberry-pi","raspberrypi","raspbian","remote-control"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ts1.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}},"created_at":"2020-08-28T11:21:28.000Z","updated_at":"2025-02-27T07:39:55.000Z","dependencies_parsed_at":"2022-09-02T12:00:26.769Z","dependency_job_id":null,"html_url":"https://github.com/ts1/PiIR","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts1%2FPiIR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts1%2FPiIR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts1%2FPiIR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts1%2FPiIR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ts1","download_url":"https://codeload.github.com/ts1/PiIR/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249080272,"owners_count":21209498,"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":["pigpio","raspberry-pi","raspberrypi","raspbian","remote-control"],"created_at":"2024-11-08T11:13:53.347Z","updated_at":"2025-04-15T13:32:19.558Z","avatar_url":"https://github.com/ts1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PiIR\n\n[![PyPI version](https://badge.fury.io/py/PiIR.svg)](https://badge.fury.io/py/PiIR)\n![CI](https://github.com/ts1/PiIR/workflows/CI/badge.svg)\n\nIR remote control for Raspberry Pi.\n\nPiIR is a client program for [pigpio](http://abyz.me.uk/rpi/pigpio/), the excellent hardware-timed GPIO library. \nSome code are taken from its sample program `irrp.py`.\n\n## Features\n- Records and plays IR remote control code.\n- Decodes and encodes NEC, Sony, RC5, RC6, AEHA, Mitsubishi, Sharp and Nokia formats.\n- Dumps decoded and prettified data to help you analyze your air conditioner's remote.\n- Both command-line and programmatic control.\n\n## Requirements\n- Raspberry Pi (any model where pigpio works should work)\n- IR LED and/or receiver on GPIO (see [Hardware](#hardware) section)\n- Python \u003e= 3.6\n- Running pigpiod daemon\n\n## Installation\n```sh\nsudo pip3 install PiIR\n```\n\nStart pigpio daemon.\n```sh\nsudo systemctl enable pigpiod\nsudo systemctl start pigpiod\n```\n\n## Command line usage\n\nIn the following example, the transmit GPIO is 17 and the receive GPIO is 22.\nYou may need to change them to fit your hardware configuration.\n\n### Recoding\n\n```sh\npiir record --gpio 22 --file light.json\n```\n\nThis asks key names on your remote and to press the keys.\n\n```\nName of the key (blank to finish): on\nPress the key named \"on\".\nPress the same key again to verify.\nName of the key (blank to finish): off\nPress the key named \"off\".\nPress the same key again to verify.\nName of the key (blank to finish):\nSaved to \"light.json\".\n```\n\nAlternatively you can give key names in the command-line like this:\n\n```sh\npiir record --gpio 22 --file light.json on off cool warm bright dark full night\n```\n\nThe resulted data is saved to `light.json`.\nThe file will look like this:\n\n```json\n{\n  \"format\": {\n    \"preamble\": [\n      8,\n      4\n    ],\n    \"coding\": \"ppm\",\n    \"zero\": [\n      1,\n      1\n    ],\n    \"one\": [\n      1,\n      3\n    ],\n    \"postamble\": [\n      1\n    ],\n    \"pre_data\": \"2C 52\",\n    \"timebase\": 430,\n    \"gap\": 75000\n  },\n  \"keys\": {\n    \"on\": \"09 2D 24\",\n    \"off\": \"09 2F 26\",\n    \"cool\": \"39 90 A9\",\n    \"warm\": \"39 91 A8\",\n    \"bright\": \"09 2A 23\",\n    \"dark\": \"09 2B 22\",\n    \"full\": \"09 2C 25\",\n    \"night\": \"09 2E 27\"\n  }\n}\n```\n\n### Playing\n\n```sh\npiir play --gpio 17 --file light.json off\n```\n\nThis sends IR signal for `off` from `light.json`.\n\n### Analyzing\n\n```sh\npiir dump --gpio 22\n```\n\nThis prints decoded data of received signal like this:\n\n```json\n{\n  \"preamble\": [\n    8,\n    4\n  ],\n  \"coding\": \"ppm\",\n  \"zero\": [\n    1,\n    1\n  ],\n  \"one\": [\n    1,\n    3\n  ],\n  \"postamble\": [\n    1\n  ],\n  \"pre_data\": \"01 10 00 40 BF FF 00 CC 33\",\n  \"post_data\": \"00 FF 80 7F 03 FC 01 FE 88 77 00 FF 00 FF FF 00 FF 00 FF 00 FF 00\",\n  \"byte_by_byte_complement\": true,\n  \"timebase\": 420,\n  \"gap\": 49000,\n  \"data\": \"92 42 64 00 00 00 00 00 53 F1 00\"\n}\n```\n\nIt removes pre/post data and byte-by-byte complement from `data`, so you can focus on the actual data changes.\nIt shold help analyzing data from stateful remotes such as air conditioners.\nAn example of programmatic data generation using this result can be found in `piir/remotes`.\n\nFor more options try `-h`.\n\n## API\n\n### Sending\n\nTo send an IR signal recorded in a file:\n\n```python\nimport piir\n\nremote = piir.Remote('light.json', 17)\nremote.send('off')\n```\n\nThe first argument of `Remote` can be a content of JSON instead of a file name.\n\nYou can also send arbitrary data like this:\n\n```python\nremote.send_data('09 2E 27')\n```\n\nor\n\n```python\nremote.send_data(bytes([0x09, 0x2E, 0x27]))\n```\n\n### Recording\n\n```python\nfrom piir.io import receive\nfrom piir.decode import decode\n\nkeys = {}\n\nwhile True:\n    data = decode(receive(22))\n    if data:\n        break\nkeys['keyname'] = data\n```\n\n`receive` returns raw pulses as a `list`.\nIt may be noise and other meaningless pulses.\n`decode` tries to decode it as remote data and returns a `dict` if successful, otherwise returns `None`.\n\nWhen you recorded enough key data, you can call `prettify` to consolidate them into a JSON data that can be fed to `Remote`.\n\n```python\nfrom piir.prettify import prettify\nimport json\n\nprint(json.dumps(prettify(keys), indent=2))\n```\n\n```json\n{\n  \"format\": {\n    \"preamble\": [\n      16,\n      8\n    ],\n    \"coding\": \"ppm\",\n    \"zero\": [\n      1,\n      1\n    ],\n    \"one\": [\n      1,\n      3\n    ],\n    \"postamble\": [\n      1\n    ],\n    \"byte_by_byte_complement\": true,\n    \"timebase\": 560,\n    \"gap\": 76000,\n    \"carrier\": 38000\n  },\n  \"keys\": {\n    \"keyname\": \"80 12\"\n  }\n}\n```\n\nFor more information, consult [piir/cli.py](https://github.com/ts1/PiIR/blob/master/piir/cli.py).\n\n## Hardware\n\n![Photo](https://raw.githubusercontent.com/ts1/PiIR/master/img/photo.jpeg)\n\nI'm using Raspberry Pi Zero WH with four IR LEDs.\nEach LED is driven by a transistor connected to GPIO 17 at a measured current of 120mA.\n\nOn an unrelated note, the big gold thing is a carbon dioxide sensor.\n\n![Schematic of LED](https://raw.githubusercontent.com/ts1/PiIR/master/img/schema-led.png)\n\nAlso onboard is a 38KHz IR receiver from Sharp, connected to GPIO 22.\n\n![Schematic of receiver](https://raw.githubusercontent.com/ts1/PiIR/master/img/schema-receiver.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts1%2Fpiir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fts1%2Fpiir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts1%2Fpiir/lists"}