{"id":17647377,"url":"https://github.com/plapointe6/hamqttdevice","last_synced_at":"2025-03-17T13:11:04.693Z","repository":{"id":40505365,"uuid":"293638451","full_name":"plapointe6/HAMqttDevice","owner":"plapointe6","description":"A library that provides tools to simplify MQTT discovery implementation for Home Assistant to your device.","archived":false,"fork":false,"pushed_at":"2024-09-15T22:45:56.000Z","size":29,"stargazers_count":45,"open_issues_count":4,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-05T04:13:22.174Z","etag":null,"topics":["arduino","arduino-library","home-assistant","iot","iot-device"],"latest_commit_sha":null,"homepage":"","language":"C++","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/plapointe6.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}},"created_at":"2020-09-07T21:44:40.000Z","updated_at":"2024-12-01T11:10:24.000Z","dependencies_parsed_at":"2024-10-23T14:08:29.106Z","dependency_job_id":null,"html_url":"https://github.com/plapointe6/HAMqttDevice","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/plapointe6%2FHAMqttDevice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plapointe6%2FHAMqttDevice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plapointe6%2FHAMqttDevice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plapointe6%2FHAMqttDevice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plapointe6","download_url":"https://codeload.github.com/plapointe6/HAMqttDevice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244039206,"owners_count":20387834,"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":["arduino","arduino-library","home-assistant","iot","iot-device"],"created_at":"2024-10-23T11:13:11.337Z","updated_at":"2025-03-17T13:11:04.660Z","avatar_url":"https://github.com/plapointe6.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HAMqttDevice\n\nA simple library that allow an easy json generation of MQTT Discovery payloads intended to be sent to Home Assistant.\n\n## How to use\n\nIf you are here, you probably already know about MQTT Discovery in Home assistant (https://www.home-assistant.io/docs/mqtt/discovery/).\nIf you want to implement MQTT Discovery with Home Assistant in your device, this library is for you.\n\nThis library is quite simple, it only helps to generate json payload, the communication part is not embeded into it.\n\nSo, first you need to create your MQTT Discovery device.\n\nLets take a look to the constructor : \n```c++\nHAMqttDevice(\n    const String\u0026 name,                         // Name of the device (ex: \"My Nice Lamp\")\n    const DeviceType type,                      // The type of the device (See below)\n    const String\u0026 haMQTTPrefix = \"ha\"          // The prefix configured in Home Assistant. (\"discovery_prefix\" in configuration.yaml)\n);\n```\n\nHere is the device types : \n```c++\nenum DeviceType { ALARM_CONTROL_PANEL, BINARY_SENSOR, CAMERA, COVER, FAN, LIGHT, LOCK, SENSOR, SWITCH, CLIMATE, VACUUM };\n```\n\nTo create the device (a simple binary sensor in this exemple) :\n```c++\nHAMqttDevice binarySensor(\"My Binary Sensor\", HAMqttDevice::BINARY_SENSOR);\n```\n\nIt is possible to register state, command, and attributes topic.\nTake note that when registering the state or command topic is mandatory for the device type, it will be done automatically.\n```c++\nHAMqttDevice\u0026 enableCommandTopic();         // If we enable the command topic registration\nHAMqttDevice\u0026 enableStateTopic();           // If we enable the state topic registration \nHAMqttDevice\u0026 enableAttributesTopic();      // If we enable the attribute topic registration\n```\n\nEnabling attributes topic.\n```c++\nbinarySensor.enableAttributesTopic();\n```\n\nIt is also possible to add custom configuration variables (availables config variables for a binary sensor: https://www.home-assistant.io/integrations/sensor.mqtt/)\n```c++\nbinarySensor.addConfigVar(\"device_class\", \"door\");\nbinarySensor.addConfigVar(\"retain\", \"false\");\n```\n\nYou can now generate the config payload for Home Assistant discovery : \n```c++\nSerial.println(\"Config topic : \" + binarySensor.getConfigTopic());\nSerial.println(\"Config payload : \" + binarySensor.getConfigPayload());\n```\n\nOutput :\n```\nConfig topic : ha/binary_sensor/my_binary_sensor/config\nConfig payload : {\"~\":\"ha/binary_sensor/my_binary_sensor\",\"name\":\"My Binary Sensor\",\"stat_t\":\"~/state\",\"json_attr_t\":\"~/attr\",\"device_class\":\"door\",\"retain\":\"false\"}\n```\n\n## Full blown exemples\n\nI use this library in pair with ESPMQTTClient since more than a year now and I am in a point where everything is stable and functionnal.\nYou can see this library in action with some of my iot devices from this repo : https://github.com/plapointe6/CustomHADevicesCollection\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplapointe6%2Fhamqttdevice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplapointe6%2Fhamqttdevice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplapointe6%2Fhamqttdevice/lists"}