leosac/access-control

MQTT module

Maxhy opened this issue · 0 comments

Maxhy commented

A new MQTT module has been added. It is a basic implementation providing a bridge to an MQTT broker either to Publish or Subscribe on specific topics. That works well with the internal ZeroMQ orchestration used by Leosac.
The idea behind is to be able to link Leosac as a reliable Access Control system with Home Automation systems like Home Assistant, OpenHab, DomoticZ, ... either for metric records or to use sensors and connected relays as triggers on Leosac. Espressif devices (ESP32, ESP8266) can be flashed to ROMs with direct MQTT support as well, like ESPHome.

Such module adds dependency to Paho MQTT (both C and C++ libs) which is not available pre-built by default on Ubuntu/Debian repos for now as packages (will be on Debian Bookworm only) and then needs to be build manually. It has been added as git submodules but there is some CMake issue to build it automatically as the others. For now you will have to build & install both paho.mqtt.c and paho.mqtt.cpp with mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DPAHO_WITH_SSL=ON -DPAHO_BUILD_STATIC=ON && make && make install.
Then setup Leosac cmake with the parameter -DLEOSAC_BUILD_MODULE_MQTT=ON

Configuration sample:

<module>
  <name>MQTT</name>
  <file>libmqtt.so</file>
  <level>2</level>
  <module_config>            
    <servers>
      <server>
        <name>hass</name>
        <host>localhost</host>
        <port>1883</port>
        <client_id>leosac</client_id>
        <subscribe_prefix>homeassistant/</subscribe_prefix>
        <publish_prefix>leosac/</publish_prefix>
        <ssl>false</ssl>
      </server>
    </servers>
    <topics>
      <topic>
        <name>frontdoor</name>
        <subject>frontdoor</subject>
        <direction>publish</direction>
        <virtualtype>gpio</virtualtype>
        <payload>{ state: __PLACEHOLDER__ }</payload>
      </topic>
      <topic>
        <name>frontdoor_sensor</name>
        <subject>enocean/Front Door Sensor</subject>
        <direction>subscribe</direction>
        <virtualtype>gpio</virtualtype>
        <payload></payload>
      </topic>
      <topic>
        <name>basement_light</name>
        <subject>zigbee2mqtt/0x123456789abcdef</subject>
        <direction>subscribe</direction>
        <virtualtype>gpio</virtualtype>
        <payload>state</payload>
      </topic>
    </topics>
  </module_config>
</module>

I will let this thread open for comment / suggestion, and until the MQTT module build is enabled by default.