{"id":21177443,"url":"https://github.com/gpbenton/engmqttclient","last_synced_at":"2025-07-09T22:30:44.299Z","repository":{"id":211865253,"uuid":"51757858","full_name":"gpbenton/engMQTTClient","owner":"gpbenton","description":"MQTT client for Energenie ener314-rt board running on a raspberry Pi","archived":false,"fork":false,"pushed_at":"2020-12-27T15:52:10.000Z","size":108,"stargazers_count":21,"open_issues_count":3,"forks_count":10,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-05T08:01:35.087Z","etag":null,"topics":["c","energenie","iot","log4c","mqtt","mqtt-client","raspberry-pi"],"latest_commit_sha":null,"homepage":null,"language":"C","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/gpbenton.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}},"created_at":"2016-02-15T13:36:57.000Z","updated_at":"2023-09-08T17:07:03.000Z","dependencies_parsed_at":"2023-12-11T10:46:26.433Z","dependency_job_id":null,"html_url":"https://github.com/gpbenton/engMQTTClient","commit_stats":null,"previous_names":["gpbenton/engmqttclient"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gpbenton/engMQTTClient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbenton%2FengMQTTClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbenton%2FengMQTTClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbenton%2FengMQTTClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbenton%2FengMQTTClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpbenton","download_url":"https://codeload.github.com/gpbenton/engMQTTClient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbenton%2FengMQTTClient/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264504573,"owners_count":23618825,"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":["c","energenie","iot","log4c","mqtt","mqtt-client","raspberry-pi"],"created_at":"2024-11-20T17:16:08.889Z","updated_at":"2025-07-09T22:30:44.060Z","avatar_url":"https://github.com/gpbenton.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# engMQTTClient\nMQTT client for Energenie [ener314-rt board](https://energenie4u.co.uk/catalogue/product/ENER314-RT) running on a raspberry Pi\n\nPlease note that this is for the 'two way' ener314-rt board, which is different from 'one way' ener314 board, and does not work for the 'one way' board.\n\n![ener314-rt board](https://energenie4u.co.uk/res/images/products/large/ENER314-RT.jpg)\n\nengMQTTClient uses the mosquitto MQTT client library to do the MQTT handling.  Communication with the Energenie products is developed from the code in the energenie example directory eTRV/eTRV\\_TX/HopeRF-TX-RX\n\nIt also uses the [log4c](http://log4c.sourceforge.net/) logging library and the [cJSON](https://sourceforge.net/projects/cjson/) parser.\n\n## Status\nBeta.  Not really production ready, but in use at my house and others have downloaded, compiled and got it to work.  Feature requests are welcome, but as I only have one Pi and it used to run the heating and lights in my house, will only get developed when it can be taken offline.\n\nWorking : \n* sending ON/OFF commands to ENER002 remote controlled sockets.\n* MIH0013 (eTRV) commands \nCommands are sent using topics /energenie/eTRV/Command/_Command_/sensorId\nwhere _Command_ can be\n\n| Command | Payload | Comment |\n|--------|---------|---------|\n| Temperature | 4-30 (Ascii) | Set Target Temperature\n| Identify | None     | Makes the MIH0013 flash |\n| Exercise | None     | Causes Valve to go up and down.  Creates Diagnostic when finished.\n| Voltage  | None     | MIH0013 reports battery Voltage\n| Diagnostics | None   | Causes MIH0013 to report diagnostics\n| ValveState | \"0\", \"1\" or \"2\" (ascii) | 0=Set Valve Open 1=Closed 2=Normal Operation\n| PowerMode  | \"0\", \"1\" | 0=Low Power Mode off 1=On\n| ReportingInterval | 300-3600 (ascii) | Set the Reporting Interval (not tested)\n\nAs of the merge of issue 11, repeat commands that are issued for the same sensorId, will be replaced in the queue rather than added to it.  So, for example, issueing a Temperature command of 18 and then 20 for the same sensor will result in only the 20 being sent to the trv.\n\n* MIH0013 (eTRV) reports\nReports are received on Topic /energenie/eTRV/Report/_Report_/sensorId\nwhere _Report_ can be\n\n| Report | Payload | Comment |\n|--------|---------|---------|\n| Temperature | Ascii string | Measured Temperature in degrees Centigrade\n| TargetTemperature | Ascii String | Target Temperature set\n| Diagnostics | 2 bytes | byte 0 = low byte, 1 = high byte\n| Voltage | Ascii String | Reported Battery Voltage\n\n## Running\n\nThanks to excellent work by @setdetnet, the preferred method of running the program is now through [docker](docker/README.md).  The parameters below can still be added to the docker command if necessary.\n\nRun the program as root using\n\n        sudo LD_LIBRARY_PATH=/usr/local/lib ./engMQTTClient\n\nassuming log4c has been placed in /usr/local/lib as per default.\n\n### Parameters\n| Option | Parameter | Default     |Description |\n|--------|-----------|-------------|------------|\n| -h     | string    | localhost   | host address of MQTT Broker |\n| -p     | integer   | 1883        | port of MQTT Broker |\n| -r     | integer   | 8           | Number of times ook message is sent.  Increase if you are experiencing communication difficulties with switches |\n| -u     | string    | \"\"          | username to connect to MQTT Broker |\n| -P     | string    | \"\"          | password to connect to MQTT Broker |\n\n## Building\n\n### Prerequisites\n#### Log4c\nThe version from the raspian respository is too old to work, so you need to get the tarball and install that.  See the instructions at http://log4c.sourceforge.net/#installation\n\n#### BCM 2835 C Library\nDownload and install as per instructions from http://www.airspayce.com/mikem/bcm2835/index.html\n\n#### Mosquitto\n\nThe mosquitto packages in the raspian respository are also out of date.  To get the latest follow the instructions at http://mosquitto.org/2013/01/mosquitto-debian-repository/\n\nYou need the dev packages as well to compile engMQTTClient.\n```\nmosquitto - MQTT version 3.1/3.1.1 compatible message broker\nmosquitto-dbg - debugging symbols for mosquitto binaries\nmosquitto-dev - Development files for Mosquitto\nmosquitto-clients - Mosquitto command line MQTT clients\n```\n\n### Building engMQTTClient\n\nClone this repository and compile engMQTTClient using 'make'.\n\n### MQTT Topic structure\n\nFor ENER002 sockets, using its own protocol the structure is\n        /energenie/ENER002/_address_/_socketnum_\n\n        _address_ is a number 1-1048575 representing the 20 bit address field.  444102 corresponds to the default address used by the sample code.\n        _socketnum_ is 0-4.  0 addresses all the sockets accessed by address, 1-4 access individual sockets at that address.\n\nFor eTRV (and hopefully other OpenThings protocol devices) the structure to send command to device is\n        /energenie/eTRV/Command/_commandid_/_deviceid_\n\nTo receive commands the structure is\n        /energenie/eTRV/Report/_commandid_/_deviceid_\n\n        _commandid_ is the command sent or received (so far \"Identity\" or \"Temperature\")\n        _deviceid_ is the openThing id number for the device in decimal\n        \n## Usage\n\n### Command Line Example\n\nListen for Incoming eTRV reports\n```sh\nmosquitto_sub -v -h your_mosquitto_broker -t /energenie/#\n```\n\nTurn on socket\n```sh\nmosquitto_pub -h your_mosquitto_broker -t /energenie/ENER002/444102/4 -m On\n```\n\nIdentify eTRV (flashes led for 60s)\n```sh\nmosquitto_pub -h your_mosquitto_broker -t /energenie/eTRV/Command/Identify/329 -n\n```\n\n### Python Example\n\nInstall paho library\n```\nsudo pip install paho-mqtt\n```\n\nTurn Socket On\n```Python\n        import paho.mqtt.publish as publish\n\n        # Switch On\n        publish.single(\"/energenie/ENER002/444102/4\",\"On\", hostname=\"192.168.0.3\")\n```\n\nListen for eTRV temperature reports (can also be used to find out the address of your eTRVs)\n```Python\n\timport paho.mqtt.client as mqtt\n\timport subprocess\n\timport time\n\n\tbroker_address = \"192.168.0.3\"\n\tbroker_port = 1883\n\n\tdef on_connect(client, userdata, flags, rc):\n    \t\tclient.subscribe(\"/energenie/eTRV/Report/Temperature/#\")\n\n\tdef on_message(client, userdata, msg):\n    \t\tprint (msg.topic+\" \"+str(msg.payload)+ \"C\")\n\n\tclient = mqtt.Client()\n\tclient.on_connect = on_connect\n\tclient.on_message = on_message\n\tclient.connect(broker_address, broker_port, 60)\n\tclient.loop_forever()\n\n```\n\t\n### OpenHab example\n\n#### Controlling switches\n\nItem file\n\n        Switch Light_FF_Bed_Table \t\"Bedside Lamp\" \t(FF_Bed, Lights)\n         {mqtt=\"\u003e[raspberryPI:/energenie/ENER002/444102/1:command:ON:On],\u003e[raspberryPI:/energenie/ENER002/444102/1:command:OFF:Off]\"}\n\nSitemap file\n        \n        Switch item=Light_FF_Bed_Table label=\"Bedroom Light\" icon=\"switch\"\n\n#### Controlling eTRV\n\nItem file\n\n        Group Temperature_Chart \n        Number Temperature_329_set    \"Lounge Temperature Target [%.1f °C]\" \u003ctemperature\u003e (Temperature_Chart, FF_Bed)   \n                                      {mqtt=\"\u003e[raspberryPi:/energenie/eTRV/Command/Temperature/329:command:*:${command}]\"}\n        Number Temperature_329        \"Lounge Temperature [%.1f °C]\"   \u003ctemperature\u003e (Temperature, Temperature_Chart, FF_Bed)\n                                      {mqtt=\"\u003c[raspberryPi:/energenie/eTRV/Report/Temperature/329:state:default\"}\n\n        Number Temperature_Chart_Period\t\t\"Chart Period\"\n\n        Number eTRV_329_received_target   \"Lounge Received Target\" \u003ctemperature\u003e (Trv, FF_Bed, Temperature_Chart)\n                                          {mqtt=\"\u003c[raspberryPi:/energenie/eTRV/Report/TargetTemperature/329:state:default\"}\n        Number eTRV_329               \"Lounge TRV Control\"    (Trv, FF_Bed)\n                                          {mqtt=\"\u003e[raspberryPi:/energenie/eTRV/Command/Identify/329:command:1:0]\"}\n                                          \nSitemap file\n\n        Setpoint item=Temperature_329_set icon=\"temperature\" minValue=4 maxValue=30 step=1\n\tText item=Temperature_329\n\tSwitch item=eTRV_329 mappings=[1=\"Identify\"]\n\t\t\n\tSwitch item=Temperature_Chart_Period label=\"Chart Period\" mappings=[0=\"Hour\", 1=\"Day\", 2=\"Week\"]\n\tChart item=Temperature_Chart period=h refresh=6000 visibility=[Temperature_Chart_Period==0, Temperature_Chart_Period==\"Uninitialized\"]\n\tChart item=Temperature_Chart period=D refresh=30000 visibility=[Temperature_Chart_Period==1]\n\tChart item=Temperature_Chart period=W refresh=30000 visibility=[Temperature_Chart_Period==2]\n\t\n### Home Assistant example\n\nIn configuration.yaml\n\n```\nlight:\n  - name: \"Bedside Lamp\"\n    platform: mqtt\n    command_topic: \"/energenie/ENER002/444102/1\"\n    payload_on: \"On\"\n    payload_off: \"Off\"\n\nsensor lounge:\n  - platform: mqtt\n    state_topic: \"/energenie/eTRV/Report/Temperature/329\"\n    name: \"Lounge Temperature\"\n    unit_of_measurement: \"°C\"\n\n```\nAn larger example of a HomeAssistant package for an eTRV  is shown in the Wiki.\n\n## License\nThis code is published under the MIT License.  The last paragraph is important.  If running this code causes your device to fail, I'm not responsible.\n\nThe mosquitto MQTT library is released under the Eclipse Public License.\n\nThe log4c logging library is released under the LGPL license.\n\nThe cJSON JSON parser is released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpbenton%2Fengmqttclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpbenton%2Fengmqttclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpbenton%2Fengmqttclient/lists"}