Python plugin: Modbus RTU / ASCII / TCP/IP Topic is solved

Python and python framework

Moderator: leecollings

Post Reply
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Domoticx »

DOWNLOAD
You can download the plugin directly from here: https://github.com/DomoticX/domoticz-mo ... master.zip
Project @ GitHub: https://github.com/DomoticX/domoticz-modbus

OP updated 2020-05-26

Screenshot V2020.2E
modbus domoticz 2020.2 screen.jpg
modbus domoticz 2020.2 screen.jpg (247.68 KiB) Viewed 18136 times
MASTER Hardware
RTU RS485
- Raspberry Pi / Windows - USB RS485 to Serial stick: https://webshop.domoticx.nl/index.php?r ... 0RTU%20USB
TCP/IP
- Nothing specific

SLAVE Hardware (examples)
RTU RS485
- Relais module 12V, 4x250V/10A NO/NC Modbus RS485: http://domoticx.com/modbus-relaisbord/
- KWh meter – DDS238-1 ZN: http://domoticx.com/modbus-kwh-meter-dds238-1-zn/
- KWh meter – Eastron SDM120: http://domoticx.com/modbus-kwh-meter-eastron-sdm120/
- KWh meter – Socomec Countis E03: http://domoticx.com/modbus-kwh-meter-so ... untis-e03/
- D/A converter – HY4AO: http://domoticx.com/modbus-d-a-converter-hy4ao/

Create your own MODBUS SLAVES! :ugeek:
RTU RS485
- Arduino UNO/MEGA/NANO/MINI: http://domoticx.com/arduino-modbus-rs485-rtu-slave/
TCP/IP
- Arduino UNO/MEGA & Ethernet W5100 shield: http://domoticx.com/arduino-shield-ethe ... -ip-slave/
- Arduino UNO/MEGA/NANO/MINI & ENC28J60 module: http://domoticx.com/module-ethernet-lan ... -ip-slave/
- Wire the ENC28J60 module: http://domoticx.com/module-ethernet-lan ... -enc28j60/
TCP/IP Wireless
- ESP8266/NodeMCU/Wemos: http://domoticx.com/esp8266-wifi-modbus-tcp-ip-slave/

SIMULATOR
No hardware? try a Modbus simulator: https://sourceforge.net/projects/modrssim/
-----------------------------
So i am using Domoticz (again) now for 3 days (before that trying OpenHab) and see it's maturity has grown since the last years!, very nice! so i installed it all again....and still no Modbus, M-bus, KNX, KAKU TCP-200/300 support!

I also use pymodbus to readout and switch some Modbus stuff you can read here on this page: http://domoticx.com/io-interface/

So.....after many many hours of learning and experimenting...trial and error (since python 3 is pretty new for me) about how to build a Domoticz Python plugin, i have almost finished the first Modbus plugin for Domoticz !!

DomoticX - ConX domotica platform (in developement Q1/Q2 2020)
So...because we are releasing our new hardware domotica line-up for Q3-Q4 2020 called ConX....we also want to support Domoticz!
ConX uses USB to RS485 conversion and 12VDC or 24VDC PoE support for all your devices, it uses RJ45 jack and is RTU based! it's a all-in-one wired and robust domotica system suitable to be placed on a DIN rail.

It will be for sale in Q3-Q4 2020, so..stay tuned! :D
2020-05-07 - Domoticx ConX teaser poster.jpg
2020-05-07 - Domoticx ConX teaser poster.jpg (263.76 KiB) Viewed 18202 times
preview poster here (dutch @ linkedin): https://www.linkedin.com/pulse/domoticx ... -ebeltjes/

oh well the hub has updated/changed since the poster :mrgreen: , hey.... time flies!

About modbus thingies...

Last week we have made a practical board to test all modbus stuff out for or new platform ConX, in wich you can create and add you own modbus devices easily!, stay tuned!
DomoticX ConX test board.jpg
DomoticX ConX test board.jpg (304.55 KiB) Viewed 17893 times
Last edited by Domoticx on Tuesday 02 June 2020 11:01, edited 35 times in total.
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

Ps. There will be 2 universal plugins, one to READ and one to WRITE :D
modbus domoticz universal write 01.png
modbus domoticz universal write 01.png (146.07 KiB) Viewed 36014 times
modbus domoticz universal write 02.png
modbus domoticz universal write 02.png (64.21 KiB) Viewed 36014 times
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
miljume
Posts: 62
Joined: Thursday 03 December 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8742
Contact:

Re: Python plugin: Modbus Universal

Post by miljume »

Really great work!

Any chance you will include Modbus TCP support as well?
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

miljume wrote: Monday 08 January 2018 9:35 Really great work!

Any chance you will include Modbus TCP support as well?
Well that should be possible i have to merge/abuse some settings then :lol:

Also i don't have any Modbus TCP laying around, so i can write psuedo code so people can test it out!
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

So i had to crank some (serial) settings into eachother (stopbit, bytesize, parity) to make some room for more settings, because domoticz officially supports ONLY 6 extra fields....

Sneek peeks:
domoticz modbus portsettings.png
domoticz modbus portsettings.png (76.66 KiB) Viewed 35955 times
domoticz modbus methode.png
domoticz modbus methode.png (68.78 KiB) Viewed 35955 times
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

Alright....the Modbus WRITE v1.0.0 has been released! Enjoy! :D
https://github.com/DomoticX/domoticz-modbus

Now i will write the Universal READ plugin... ;)

Stay tuned!
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

Modbus WRITE examples

Settings RTU example
domoticz modbus rtu voorbeeld.png
domoticz modbus rtu voorbeeld.png (97.21 KiB) Viewed 35897 times
Settings TCP example:
domoticz modbus tcp voorbeeld.png
domoticz modbus tcp voorbeeld.png (97.87 KiB) Viewed 35897 times
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

Hi All,

Today i've finished the Modbus READ plugin, it works very nice! you can download it here: https://github.com/DomoticX/domoticz-modbus

Enjoy!
domoticz modbus universal read.png
domoticz modbus universal read.png (85.58 KiB) Viewed 35850 times
Supported Functions:
domoticz modbus universal read functions.png
domoticz modbus universal read functions.png (19.15 KiB) Viewed 35850 times
Supported Datatypes:
domoticz modbus universal read data types.png
domoticz modbus universal read data types.png (10.12 KiB) Viewed 35850 times
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx »

Tested the modbus READ plugin with the EASTRON SDM120 KWH Modbus meter:
http://domoticx.com/modbus-kwh-meter-eastron-sdm120/

Result (voltage):
domoticz modbus universal read test.png
domoticz modbus universal read test.png (17.38 KiB) Viewed 35848 times
Ps. if you wanna buy 8-) :
http://domoticx.nl/webwinkel/index.php? ... ct_id=1865
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by devros »

Great and what about 3 phase metter? any cheap supported device?
Ricard1
Posts: 62
Joined: Saturday 07 November 2015 12:30
Target OS: Windows
Domoticz version: Beta
Location: Sweden
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Ricard1 »

Hi @Domoticx

Big thanks for initiating Modbus support to Domotiz!

I am soon going to replace my home Ventilation unit and new one will have Modbus... :)

Best Regards,
Ricard
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

devros wrote: Thursday 11 January 2018 20:29 Great and what about 3 phase metter? any cheap supported device?
Hi devros,

It's a universal modbus plugin, so it wil work with all modbus appliances!
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Ricard1 wrote: Friday 12 January 2018 11:26 Hi @Domoticx

Big thanks for initiating Modbus support to Domotiz!

I am soon going to replace my home Ventilation unit and new one will have Modbus... :)

Best Regards,
Ricard
No problem ;) let me know if it works as it is intended or if you need any help.
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
EdddieN
Posts: 510
Joined: Wednesday 16 November 2016 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Scotland
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by EdddieN »

Is there a Like? This is fantastic! Great work
11101101 - www.machinon.com
winnie
Posts: 7
Joined: Saturday 13 January 2018 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by winnie »

Hi @Domoticx,

Thanks for sharing the plugin. It looks great !
But i have a problem. I can't fill in any parameter.

Any idea?
Thanks Erwin.
Attachments
Knipsel.PNG
Knipsel.PNG (373.46 KiB) Viewed 35719 times
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Hello Erwin,

That is really strange, i use the same domoticz version, and i got all the options :roll: , i assume you restarted domoticz like:

Code: Select all

sudo service domoticz.sh restart
Or rebooted it?

It seems the XLM layout (plugin) isn't loaded somehow.... i cannot recreate your situation on my pi...

Can you test:
Open a browser to the domoticz log window, and a putty session and use

Code: Select all

sudo service domoticz.sh restart
What does the log say?
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
winnie
Posts: 7
Joined: Saturday 13 January 2018 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by winnie »

Hello Domoticx,

Thanks for your suggestions.
I have restart domoticz several times wihout results.

Here a copy of the log file, baybe you see something wrong...
Greetz and thanks in advance,
Erwin;


2018-01-14 09:10:17.473 Domoticz V3.8153 (c)2012-2017 GizMoCuz
2018-01-14 09:10:17.473 Build Hash: 494fff7, Date: 2017-07-30 12:19:41
2018-01-14 09:10:17.473 Startup Path: /home/pi/domoticz/
2018-01-14 09:10:17.526 EventSystem: reset all events...
2018-01-14 09:10:17.613 PluginSystem: Started, Python version '3.4.2'.
2018-01-14 09:10:17.624 WebServer(HTTP) started on address: :: with port 8080
2018-01-14 09:10:17.630 WebServer(SSL) started on address: :: with port 443
2018-01-14 09:10:17.631 Proxymanager started.
2018-01-14 09:10:17.632 Camera: settings (re)loaded
2018-01-14 09:10:17.678 RxQueue: queue worker started...
2018-01-14 09:10:17.833 Incoming connection from: 127.0.0.1
2018-01-14 09:10:17.875 Incoming connection from: 192.168.0.121
2018-01-14 09:10:19.679 Wunderground: Worker started...
2018-01-14 09:10:19.681 Hardware Monitor: Started
2018-01-14 09:10:19.694 EventSystem: reset all events...
2018-01-14 09:10:19.695 EventSystem: reset all device statuses...
2018-01-14 09:10:19.894 RFLink: Using serial port: /dev/ttyACM0
2018-01-14 09:10:19.918 Python EventSystem: Module not found - Trying to initialize.
2018-01-14 09:10:19.920 Python EventSystem: Initalizing event module.
2018-01-14 09:10:19.920 EventSystem: Started
2018-01-14 09:10:20.028 PluginSystem: Entering work loop.
2018-01-14 09:10:20.814 RFLink: Controller Initialized!...
2018-01-14 09:10:20.890 RFLink Detected, Version: 1.1 Revision: 45 Build: 9
2018-01-14 09:10:22.179 Incoming connection from: 172.16.0.109
2018-01-14 09:11:00.451 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_zwembad.lua
2018-01-14 09:11:00.561 LUA: =====================================================
2018-01-14 09:11:00.561 LUA: >>> Handler: oled
2018-01-14 09:11:00.561 LUA: .....................................................
2018-01-14 09:11:00.561 LUA: Zwembadtemperatuur: 18.62
2018-01-14 09:11:00.612 LUA: .....................................................
2018-01-14 09:11:00.612 LUA: <<< Done
2018-01-14 09:11:00.612 LUA: -----------------------------------------------------
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

What could this be?

Code: Select all

Python EventSystem: Module not found - Trying to initialize.
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
winnie
Posts: 7
Joined: Saturday 13 January 2018 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by winnie »

I also noticed this error, find out if there is something to find about this.
Last edited by winnie on Wednesday 24 January 2018 21:41, edited 1 time in total.
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Indeed wierd..... i have a higher python version (stretch image) :roll:

This is my log:
2018-01-14 18:22:48.140 Domoticz V3.8153 (c)2012-2017 GizMoCuz
2018-01-14 18:22:48.140 Build Hash: 494fff7, Date: 2017-07-30 10:19:41
2018-01-14 18:22:48.140 Startup Path: /home/pi/domoticz/
2018-01-14 18:22:48.182 Sunrise: 07:42:00 SunSet:15:53:00
2018-01-14 18:22:48.182 EventSystem: reset all events...
2018-01-14 18:22:48.319 PluginSystem: Started, Python version '3.5.3'.
2018-01-14 18:22:48.327 Active notification Subsystems: (0/12)
2018-01-14 18:22:48.329 WebServer(HTTP) started on address: :: with port 8080
2018-01-14 18:22:48.334 WebServer(SSL) started on address: :: with port 443
2018-01-14 18:22:48.336 Proxymanager started.
2018-01-14 18:22:48.337 Starting shared server on: :::6144
2018-01-14 18:22:48.337 TCPServer: shared server started...
2018-01-14 18:22:48.337 RxQueue: queue worker started...
2018-01-14 18:22:49.240 Incoming connection from: 192.168.0.1
2018-01-14 18:22:50.338 EventSystem: reset all events...
2018-01-14 18:22:50.339 EventSystem: reset all device statuses...
2018-01-14 18:22:50.494 Python EventSystem: Module not found - Trying to initialize.
2018-01-14 18:22:50.494 Python EventSystem: Initalizing event module.
2018-01-14 18:22:50.494 EventSystem: Started
2018-01-14 18:22:50.683 PluginSystem: Entering work loop.

Also the same error (can be common though)

Code: Select all

2018-01-14 18:22:50.494 Python EventSystem: Module not found - Trying to initialize.
2018-01-14 18:22:50.494 Python EventSystem: Initalizing event module.
But it loads the plugins nicely!

Have you installed pymodbus:

Code: Select all

sudo pip3 install -U pymodbus
Aslo a thing noticed is that the log should say Modbus - Universal READ loaded. because it's stated in the python file:

Code: Select all

    def onStart(self):
        # Domoticz.Log("onStart called")
        if (len(Devices) == 0): Domoticz.Device(Name="ModbusDEV-READ", Unit=1, TypeName="Custom", Image=0, Used=1).Create() # Used=1 to add a switch immediatly!
        DumpConfigToLog()
        Domoticz.Log("Modbus - Universal READ loaded.")
        return
on plugin load and the message is also gone on my side (plugin loaded correctly though), really wierd, hopefully someone can shed a light on this
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest