{"id":17077866,"url":"https://github.com/seblucas/i2c2mqtt","last_synced_at":"2025-08-09T10:28:05.743Z","repository":{"id":43736772,"uuid":"116125264","full_name":"seblucas/i2c2mqtt","owner":"seblucas","description":"Get values from sensors in your i2c bus and send it to your MQTT broker ","archived":false,"fork":false,"pushed_at":"2022-02-20T22:47:03.000Z","size":22,"stargazers_count":7,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T14:41:24.837Z","etag":null,"topics":["bh1750","bme280","i2c","mqtt","python","si7021"],"latest_commit_sha":null,"homepage":null,"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/seblucas.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":"2018-01-03T10:41:15.000Z","updated_at":"2023-12-11T20:22:14.000Z","dependencies_parsed_at":"2022-08-21T21:20:13.884Z","dependency_job_id":null,"html_url":"https://github.com/seblucas/i2c2mqtt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seblucas%2Fi2c2mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seblucas%2Fi2c2mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seblucas%2Fi2c2mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seblucas%2Fi2c2mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seblucas","download_url":"https://codeload.github.com/seblucas/i2c2mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248626831,"owners_count":21135741,"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":["bh1750","bme280","i2c","mqtt","python","si7021"],"created_at":"2024-10-14T12:17:27.756Z","updated_at":"2025-04-12T20:23:52.154Z","avatar_url":"https://github.com/seblucas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i2c2mqtt\nGet values from sensors in your i2c bus and send it to your MQTT broker\n\n# Usage\n\n## Prerequisite\n\nYou simply need Python3 (never tested with Python2.7) and the only dependencies are `smbus` (to access the i2c) and `paho-mqtt` (for MQTT broker interaction) so this line should be enough  :\n\n```bash\npip3 install paho-mqtt cffi smbus-cffi\n```\n\nYou may have to also install `libffi-dev` and `python3-dev` because it may need to recompile some stuff. If you're using Debian the you can use `python-smbus`\n\n## Using the script\n\nEasy, first try a dry-run command :\n\n```bash\n./i2c2mqtt.py -d \u003cDEVICE\u003e -d \u003cANOTHER_DEVICE\u003e -n -v\n```\n\nFor now the device can be :\n\n * bh1750\n * si7021\n * bme280\n\nPR welcomed to add more.\n\nand then a real command to add to your crontab :\n\n```bash\n./netatmo2MQTT.py -d \u003cDEVICE\u003e\n```\n\n## Help\n\n```bash\nseb@minus~/src/i2c2mqtt# ./i2c2mqtt.py --help\nusage: i2c2mqtt.py [-h] [-d DEVICES] [-m HOST] [-n] [-t TOPIC] [-T TOPIC] [-v]\n\nRead current temperature,illuminance and humidity from i2c sensors and send\nthem to a MQTT broker.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -d DEVICES, --device DEVICES\n                        Specify the devices to probe in the I2C bus. Can be\n                        called many times. (default: None)\n  -m HOST, --mqtt-host HOST\n                        Specify the MQTT host to connect to. (default:\n                        127.0.0.1)\n  -n, --dry-run         No data will be sent to the MQTT broker. (default:\n                        False)\n  -t TOPIC, --topic TOPIC\n                        The MQTT topic on which to publish the message (if it\n                        was a success). (default: sensor/i2c)\n  -T TOPIC, --topic-error TOPIC\n                        The MQTT topic on which to publish the message (if it\n                        wasn't a success). (default: error/sensor/i2c)\n  -v, --verbose         Enable debug messages. (default: False)\n```\n\n## Docker\n\nI added a sample Dockerfile, I personaly use it with a `docker-compose.yml` like this one :\n\n```yml\nversion: '3'\n\nservices:\n  cron-i2c:\n    build: https://github.com/seblucas/i2c2mqtt.git\n    image: i2c-python3-cron:latest\n    restart: always\n    environment:\n      CRON_STRINGS: \"1,16,31,46 * * * * i2c2mqtt.py -d bh1750 -d bme280 -m mosquitto -t sensor/i2c\"\n      CRON_LOG_LEVEL: 8\n    devices:\n      - \"/dev/i2c-1:/dev/i2c-1\"\n```\n\n# Credits\n\n * bme280.py comes from [this repository](https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/bme280.py)\n * bh1750.py also comes from [this repository](https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/bh1750.py)\n * si7021.py was mostly written by me.\n\n# License\n\nThis program is licenced with GNU GENERAL PUBLIC LICENSE version 3 by Free Software Foundation, Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseblucas%2Fi2c2mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseblucas%2Fi2c2mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseblucas%2Fi2c2mqtt/lists"}