diematic-server


Namediematic-server JSON
Version 3.1 PyPI version JSON
download
home_pagehttps://github.com/IgnacioHR/diematic_server
SummaryUnix daemon and supporting models for publishing data from Diematic DeDietrich boiler
upload_time2024-11-23 09:52:21
maintainerNone
docs_urlNone
authorIgnacio Hernández-Ros
requires_pythonNone
licenseMIT
keywords python home-automation iot influxdb restful modbus de-dietrich diematic mqtt
VCS
bugtrack_url
requirements aiohttp daemon influxdb pymodbus python-daemon PyYAML paho-mqtt
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # diematic

A Unix service written in Python to monitor De Dietrich boiler equiped with Diematic system using Modbus RS-845 protocol.
The service reads data from the boiler and makes it available to be consumed in three ways:
Optionally, the values fetched from the boiler are sent to an InfluxDB database.
Optionally, the values fetched from the boiler are sent to an MQTT broker. (TODO)
Optionally, a RESTful web server is installed and values can be obtained using GET and modified using POST requests.
Optionally, boiler parameters can be changed from the mqtt topics

![Screenshot](images/web-requests.png?raw=true)
![Screenshot](images/chronograf_screenshot.png?raw=true)

## Hardware requirements

 * A De Dietrich boiler with Diematic regulation and a mini-din socket
 * A mini-din cable 
 * A RS-845 to USB adapter
 * A nano-computer with a USB port and Python3 installed (Raspberry pi or similar)

Check tutorials in the "references" section below on how to do the hardware setup.

## Changes from version 2.X

 * Added support to integrate with mqtt broker
 * Added command line parameters with priority over provided values in the configuration file

## Http server

Satrting from version 3.0 the web server can be configured from the `diematic.yaml` configuration file by adding an `http` key as follows:

```
http:
    address: 0.0.0.0
    port: 8080
```

Once the service is running head to:

http://{HOSTNAME}:{PORT}/diematic/parameters

you can have access to all parameters indicated in the configuration file. Read the webserver.py documentation to know more about it.

## MQTT

Starting from version 3.0 the service can be configured to send data to an MQTT broker. The broker configuration goes in the diematic.yaml configuration file as follows:

```
mqtt:
  broker: your broker server
  port: 1883
  user: your mqtt user, optional
  password: your mqtt user credentials
  retain: false
  tls: false
  topic: diematic2mqtt/boiler
  discovery:
    prefix: homeassistant
```

If there is no `mqtt` key, mqtt will not be considered at all. Under the `mqtt` key only `broker` key is required. The value is the broker ip address or host name that can be resolved using dns. The `port` default value is 1883 or 8883 if `tls` key is set to true. If provided, the `user` and `password` keys are used to open connection to the broker. `retain` can be used to inform the broker to retain the values. `topic` key can be used to configure the topic under wich all information will be set. if `discovery` key is set, the server will publish MQTT Discovery information to the broker. The `prefix` key indicates the topic under wich home assistant is subscribed to receive MQTT Discovery information.

## Installation
```
git clone https://github.com/IgnacioHR/diematicd.git
cd diematicd
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
mkdir /etc/diematic
cp diematic.yaml /etc/diematic
cp diematicd.service /etc/systemd/system
systemctl enable diematicd
systemctl start diematicd
```

## Test
Run `python3 diematicd.py --help`
```
usage: diematicd.py [-h] [-b {none,configured,influxdb,mqtt}] [-d DEVICE] [-f]
                    [-l {critical,error,warning,info,debug}] [-c CONFIG]
                    [-w HOSTNAME] [-p PORT] [-s {loop,web,both}] [-a ADDRESS]
                    [-t {Raw,DiematicOneDecimal,DiematicModeFlag,ErrorCode,DiematicCircType,DiematicProgram,bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9,bitA,bitB,bitC,bitD,bitE,bitF}]
                    {status,start,stop,restart,reload,runonce,readregister}

positional arguments:
  {status,start,stop,restart,reload,runonce,readregister}
                        action to take

optional arguments:
  -h, --help            show this help message and exit
  -b {none,influxdb}, --backend {none,influxdb}
                        select data backend (default is influxdb)
  -d DEVICE, --device DEVICE
                        define modbus device
  -f, --foreground      Run in the foreground do not detach process
  -l {critical,error,warning,info,debug}, --logging {critical,error,warning,info,debug}
                        define logging level (default is critical)
  -c CONFIG, --config CONFIG
                        alternate configuration file
  -w HOSTNAME, --hostname HOSTNAME
                        web server host name, defaults to 0.0.0.0
  -p PORT, --port PORT  web server port, defaults to 8080
  -s {loop,web,both}, --server {loop,web,both}
                        servers to start
  -a ADDRESS, --address ADDRESS
                        register address to read whe action is readregister
  -t {Raw,DiematicOneDecimal,DiematicModeFlag,ErrorCode,DiematicCircType,DiematicProgram,bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9,bitA,bitB,bitC,bitD,bitE,bitF}, --format {Raw,DiematicOneDecimal,DiematicModeFlag,ErrorCode,DiematicCircType,DiematicProgram,bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9,bitA,bitB,bitC,bitD,bitE,bitF}
                        value format to apply for register read, default is
                        Raw

```

## InfluxDB preparation
### Minimal
```
CREATE DATABASE "diematic"
CREATE USER "diematic" WITH PASSWORD 'mySecurePas$w0rd'
GRANT ALL ON "diematic" TO "diematic"
CREATE RETENTION POLICY "one_week" ON "diematic" DURATION 1w REPLICATION 1 DEFAULT
```

### Additionnal steps for down-sampling
```
CREATE RETENTION POLICY "five_weeks" ON "diematic" DURATION 5w REPLICATION 1
CREATE RETENTION POLICY "five_years" ON "diematic" DURATION 260w REPLICATION 1

CREATE CONTINUOUS QUERY "cq_month" ON "diematic" BEGIN
  SELECT mean(/temperature/) AS "mean_1h", mean(/pressure/) AS "mean_1h", max(/temperature/) AS "max_1h", max(/pressure/) AS "max_1h"
  INTO "five_weeks".:MEASUREMENT
  FROM "one_week"."diematic"
  GROUP BY time(1h),*
END

CREATE CONTINUOUS QUERY "cq_year" ON "diematic" BEGIN
  SELECT mean(/^mean_.*temperature/) AS "mean_24h", mean(/^mean_.*pressure/) AS "mean_24h", max(/^max_.*temperature/) AS "max_24h", max(/^max_.*pressure/) AS "max_24h"
  INTO "five_years".:MEASUREMENT
  FROM "five_weeks"."diematic"
  GROUP BY time(24h),*
END
```


## References
- https://github.com/gmasse/diematic.git
- https://github.com/riptideio/pymodbus
- (french) http://sarakha63-domotique.fr/chaudiere-de-dietrich-domotise-modbus/amp/
- (french) https://www.dom-ip.com/wiki/Réalisation_d%27une_Interface_Web_pour_une_chaudière_De_Dietrich_équipée_d%27une_régulation_Diematic_3
- (french forum) https://www.domotique-fibaro.fr/topic/5677-de-dietrich-diematic-isystem/
- ~~(french forum) http://www.wit-square.fr/forum/topics/de-dietrich-communication-modbus-bi-ma-tre~~
- (french, modbus registers sheets, copy from previous forum) https://drive.google.com/file/d/156qBsfRGJvOpJBJu5K4WMHUuwv34bZQN/view?usp=sharing

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/IgnacioHR/diematic_server",
    "name": "diematic-server",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, home-automation, iot, influxdb, restful, modbus, de-dietrich, diematic, mqtt",
    "author": "Ignacio Hern\u00e1ndez-Ros",
    "author_email": "ignacio@hernandez-ros.com",
    "download_url": "https://files.pythonhosted.org/packages/e2/b3/7dfd42d06a4307818e48b38fa30060577cdfa1410629152d5eb086e159d8/diematic_server-3.1.tar.gz",
    "platform": null,
    "description": "# diematic\n\nA Unix service written in Python to monitor De Dietrich boiler equiped with Diematic system using Modbus RS-845 protocol.\nThe service reads data from the boiler and makes it available to be consumed in three ways:\nOptionally, the values fetched from the boiler are sent to an InfluxDB database.\nOptionally, the values fetched from the boiler are sent to an MQTT broker. (TODO)\nOptionally, a RESTful web server is installed and values can be obtained using GET and modified using POST requests.\nOptionally, boiler parameters can be changed from the mqtt topics\n\n![Screenshot](images/web-requests.png?raw=true)\n![Screenshot](images/chronograf_screenshot.png?raw=true)\n\n## Hardware requirements\n\n * A De Dietrich boiler with Diematic regulation and a mini-din socket\n * A mini-din cable \n * A RS-845 to USB adapter\n * A nano-computer with a USB port and Python3 installed (Raspberry pi or similar)\n\nCheck tutorials in the \"references\" section below on how to do the hardware setup.\n\n## Changes from version 2.X\n\n * Added support to integrate with mqtt broker\n * Added command line parameters with priority over provided values in the configuration file\n\n## Http server\n\nSatrting from version 3.0 the web server can be configured from the `diematic.yaml` configuration file by adding an `http` key as follows:\n\n```\nhttp:\n    address: 0.0.0.0\n    port: 8080\n```\n\nOnce the service is running head to:\n\nhttp://{HOSTNAME}:{PORT}/diematic/parameters\n\nyou can have access to all parameters indicated in the configuration file. Read the webserver.py documentation to know more about it.\n\n## MQTT\n\nStarting from version 3.0 the service can be configured to send data to an MQTT broker. The broker configuration goes in the diematic.yaml configuration file as follows:\n\n```\nmqtt:\n  broker: your broker server\n  port: 1883\n  user: your mqtt user, optional\n  password: your mqtt user credentials\n  retain: false\n  tls: false\n  topic: diematic2mqtt/boiler\n  discovery:\n    prefix: homeassistant\n```\n\nIf there is no `mqtt` key, mqtt will not be considered at all. Under the `mqtt` key only `broker` key is required. The value is the broker ip address or host name that can be resolved using dns. The `port` default value is 1883 or 8883 if `tls` key is set to true. If provided, the `user` and `password` keys are used to open connection to the broker. `retain` can be used to inform the broker to retain the values. `topic` key can be used to configure the topic under wich all information will be set. if `discovery` key is set, the server will publish MQTT Discovery information to the broker. The `prefix` key indicates the topic under wich home assistant is subscribed to receive MQTT Discovery information.\n\n## Installation\n```\ngit clone https://github.com/IgnacioHR/diematicd.git\ncd diematicd\npython3 -m venv venv\nsource venv/bin/activate\npip install -r requirements.txt\nmkdir /etc/diematic\ncp diematic.yaml /etc/diematic\ncp diematicd.service /etc/systemd/system\nsystemctl enable diematicd\nsystemctl start diematicd\n```\n\n## Test\nRun `python3 diematicd.py --help`\n```\nusage: diematicd.py [-h] [-b {none,configured,influxdb,mqtt}] [-d DEVICE] [-f]\n                    [-l {critical,error,warning,info,debug}] [-c CONFIG]\n                    [-w HOSTNAME] [-p PORT] [-s {loop,web,both}] [-a ADDRESS]\n                    [-t {Raw,DiematicOneDecimal,DiematicModeFlag,ErrorCode,DiematicCircType,DiematicProgram,bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9,bitA,bitB,bitC,bitD,bitE,bitF}]\n                    {status,start,stop,restart,reload,runonce,readregister}\n\npositional arguments:\n  {status,start,stop,restart,reload,runonce,readregister}\n                        action to take\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -b {none,influxdb}, --backend {none,influxdb}\n                        select data backend (default is influxdb)\n  -d DEVICE, --device DEVICE\n                        define modbus device\n  -f, --foreground      Run in the foreground do not detach process\n  -l {critical,error,warning,info,debug}, --logging {critical,error,warning,info,debug}\n                        define logging level (default is critical)\n  -c CONFIG, --config CONFIG\n                        alternate configuration file\n  -w HOSTNAME, --hostname HOSTNAME\n                        web server host name, defaults to 0.0.0.0\n  -p PORT, --port PORT  web server port, defaults to 8080\n  -s {loop,web,both}, --server {loop,web,both}\n                        servers to start\n  -a ADDRESS, --address ADDRESS\n                        register address to read whe action is readregister\n  -t {Raw,DiematicOneDecimal,DiematicModeFlag,ErrorCode,DiematicCircType,DiematicProgram,bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9,bitA,bitB,bitC,bitD,bitE,bitF}, --format {Raw,DiematicOneDecimal,DiematicModeFlag,ErrorCode,DiematicCircType,DiematicProgram,bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,bit9,bitA,bitB,bitC,bitD,bitE,bitF}\n                        value format to apply for register read, default is\n                        Raw\n\n```\n\n## InfluxDB preparation\n### Minimal\n```\nCREATE DATABASE \"diematic\"\nCREATE USER \"diematic\" WITH PASSWORD 'mySecurePas$w0rd'\nGRANT ALL ON \"diematic\" TO \"diematic\"\nCREATE RETENTION POLICY \"one_week\" ON \"diematic\" DURATION 1w REPLICATION 1 DEFAULT\n```\n\n### Additionnal steps for down-sampling\n```\nCREATE RETENTION POLICY \"five_weeks\" ON \"diematic\" DURATION 5w REPLICATION 1\nCREATE RETENTION POLICY \"five_years\" ON \"diematic\" DURATION 260w REPLICATION 1\n\nCREATE CONTINUOUS QUERY \"cq_month\" ON \"diematic\" BEGIN\n  SELECT mean(/temperature/) AS \"mean_1h\", mean(/pressure/) AS \"mean_1h\", max(/temperature/) AS \"max_1h\", max(/pressure/) AS \"max_1h\"\n  INTO \"five_weeks\".:MEASUREMENT\n  FROM \"one_week\".\"diematic\"\n  GROUP BY time(1h),*\nEND\n\nCREATE CONTINUOUS QUERY \"cq_year\" ON \"diematic\" BEGIN\n  SELECT mean(/^mean_.*temperature/) AS \"mean_24h\", mean(/^mean_.*pressure/) AS \"mean_24h\", max(/^max_.*temperature/) AS \"max_24h\", max(/^max_.*pressure/) AS \"max_24h\"\n  INTO \"five_years\".:MEASUREMENT\n  FROM \"five_weeks\".\"diematic\"\n  GROUP BY time(24h),*\nEND\n```\n\n\n## References\n- https://github.com/gmasse/diematic.git\n- https://github.com/riptideio/pymodbus\n- (french) http://sarakha63-domotique.fr/chaudiere-de-dietrich-domotise-modbus/amp/\n- (french) https://www.dom-ip.com/wiki/R\u00e9alisation_d%27une_Interface_Web_pour_une_chaudi\u00e8re_De_Dietrich_\u00e9quip\u00e9e_d%27une_r\u00e9gulation_Diematic_3\n- (french forum) https://www.domotique-fibaro.fr/topic/5677-de-dietrich-diematic-isystem/\n- ~~(french forum) http://www.wit-square.fr/forum/topics/de-dietrich-communication-modbus-bi-ma-tre~~\n- (french, modbus registers sheets, copy from previous forum) https://drive.google.com/file/d/156qBsfRGJvOpJBJu5K4WMHUuwv34bZQN/view?usp=sharing\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Unix daemon and supporting models for publishing data from Diematic DeDietrich boiler",
    "version": "3.1",
    "project_urls": {
        "Download": "https://github.com/IgnacioHR/diematic_server/archive/refs/tags/v3.1.tar.gz",
        "Homepage": "https://github.com/IgnacioHR/diematic_server"
    },
    "split_keywords": [
        "python",
        " home-automation",
        " iot",
        " influxdb",
        " restful",
        " modbus",
        " de-dietrich",
        " diematic",
        " mqtt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b3cd67a33b83d5272797f25acb5ff5b7e83f113715c06d0c23041dc3bdf4fd6",
                "md5": "778de1de7d48ba3faef91065db5d4df9",
                "sha256": "86ca0a61120d953941c25b6af16a63ca45c6ef9affff203edc69cd417a1f4a8b"
            },
            "downloads": -1,
            "filename": "diematic_server-3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "778de1de7d48ba3faef91065db5d4df9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 25805,
            "upload_time": "2024-11-23T09:52:19",
            "upload_time_iso_8601": "2024-11-23T09:52:19.697137Z",
            "url": "https://files.pythonhosted.org/packages/5b/3c/d67a33b83d5272797f25acb5ff5b7e83f113715c06d0c23041dc3bdf4fd6/diematic_server-3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e2b37dfd42d06a4307818e48b38fa30060577cdfa1410629152d5eb086e159d8",
                "md5": "60f7a4479242af3bb76ed4b1070220d3",
                "sha256": "e22623f9d3ecb4b3250c20e9df5958a19c1adaab1a41270ccf3abfd6014a2650"
            },
            "downloads": -1,
            "filename": "diematic_server-3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "60f7a4479242af3bb76ed4b1070220d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 27091,
            "upload_time": "2024-11-23T09:52:21",
            "upload_time_iso_8601": "2024-11-23T09:52:21.543095Z",
            "url": "https://files.pythonhosted.org/packages/e2/b3/7dfd42d06a4307818e48b38fa30060577cdfa1410629152d5eb086e159d8/diematic_server-3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 09:52:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "IgnacioHR",
    "github_project": "diematic_server",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    "==",
                    "3.11.2"
                ]
            ]
        },
        {
            "name": "daemon",
            "specs": [
                [
                    "==",
                    "1.2"
                ]
            ]
        },
        {
            "name": "influxdb",
            "specs": [
                [
                    "==",
                    "5.2.3"
                ]
            ]
        },
        {
            "name": "pymodbus",
            "specs": [
                [
                    "==",
                    "2.2.0"
                ]
            ]
        },
        {
            "name": "python-daemon",
            "specs": [
                [
                    "==",
                    "2.3.0"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": [
                [
                    "==",
                    "6.0.2"
                ]
            ]
        },
        {
            "name": "paho-mqtt",
            "specs": [
                [
                    "==",
                    "2.1.0"
                ]
            ]
        }
    ],
    "lcname": "diematic-server"
}
        
Elapsed time: 0.35682s