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

Python and python framework

Moderator: leecollings

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 RTU / ASCII / TCP/IP

Post by Domoticx »

markh wrote: Wednesday 29 July 2020 18:49 ...I am not sure if we could add a separate field for the offset where the scale factor is located...
Sure, possible...when this request can be made into domoticz :roll: toherwise it would be chaotic in the modbus settings
https://github.com/domoticz/domoticz/issues/4137
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!)
Huff002
Posts: 12
Joined: Saturday 29 August 2020 14:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: [RELEASED] Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Huff002 »

malp wrote: Tuesday 21 August 2018 23:07 2018-08-21 23:33:38.790 Status: (Modbus-1) Started.
2018-08-21 23:33:38.884 Error: (Modbus) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/modbus-read/:/volume1/@appstore/py3k/usr/local/lib/python35.zip:/volume1/@appstore/py3k/usr/local/lib/python3.5/:/volume1/@appstore/py3k/usr/local/lib/python3.5/plat-linux:/volume1/@appstore/py3k/usr/local/lib/python3.5/lib-dynload'.
2018-08-21 23:33:38.885 Error: (Modbus-1) Module Import failed, exception: 'ImportError'
2018-08-21 23:33:38.885 Error: (Modbus-1) Module Import failed: ' Name: pymodbus'
2018-08-21 23:33:38.885 Error: (Modbus-1) Error Line details not available.
2018-08-21 23:35:00.924 Error: Modbus-1 hardware (5) thread seems to have ended unexpectedly
pymodbus and pymodbusTCP are installed:

Solution:
I added the following in the script:
sys.path.append('/usr/lib/python2.7/site-packages')
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/usr/local/lib/python3.5/dist-packages')

just specified the path where serial, pymodbus etc are located (in my case)
I have the exact same problem but but don't know which script is meant in the above solution.
Do I need to add this in plugin.py are some other script within Domoticz?
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 RTU / ASCII / TCP/IP

Post by Domoticx »

Huff002 wrote: Saturday 29 August 2020 14:10 I have the exact same problem but but don't know which script is meant in the above solution.
Do I need to add this in plugin.py are some other script within Domoticz?
The name of module you are missing is stated in the error messaage, read it again 8-)

Have you installed the depenancies?
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!)
Huff002
Posts: 12
Joined: Saturday 29 August 2020 14:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Huff002 »

The dependancies (pymodbus & pymodbusTCP) are installed.

The error in my logs:

Code: Select all

2020-08-29 15:06:07.528 Error: (ModbusREAD) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/modbus-read/:/volume1/@appstore/py3k/usr/local/lib/python35.zip:/volume1/@appstore/py3k/usr/local/lib/python3.5/:/volume1/@appstore/py3k/usr/local/lib/python3.5/plat-linux:/volume1/@appstore/py3k/usr/local/lib/python3.5/lib-dynload:/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages'.
2020-08-29 15:06:07.528 Error: (Modbus - SMA) Module Import failed, exception: 'ImportError'
2020-08-29 15:06:07.528 Error: (Modbus - SMA) Module Import failed: ' Name: pymodbus'
2020-08-29 15:06:07.528 Error: (Modbus - SMA) Error Line details not available.
For a start plugin.py failed to load. I think Domoticz is unable to find the file because of the incorrect path.
On my Synology the path is /volume1/domoticz/var/plugins/modbus-read
If I rename plugin.py to something random the error is the same, that confirms my expactation of the wrong path.

The path to the other files seems to be correct.

Code: Select all

admin@RackStation:/volume1/@appstore/py3k/usr/local/lib$ dir
total 2708
drwxr-xr-x  3 root root    4096 Jan 29  2018 .
drwxr-xr-x  5 root root    4096 Jan 29  2018 ..
lrwxrwxrwx  1 root root      20 Jan 29  2018 libpython3.5m.so -> libpython3.5m.so.1.0
-r-xr-xr-x  1 root root 2750840 Jan 29  2018 libpython3.5m.so.1.0
-r-xr-xr-x  1 root root    5848 Jan 29  2018 libpython3.so
drwxr-xr-x 36 root root    4096 Aug  1 13:40 python3.5

Still I don't understand in which script(s) I need to set the paths as suggested by malp
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 RTU / ASCII / TCP/IP

Post by Domoticx »

Huff002 wrote: Saturday 29 August 2020 15:22 The dependancies (pymodbus & pymodbusTCP) are installed.
Hmm the error:
2020-08-29 15:06:07.528 Error: (Modbus - SMA) Module Import failed: ' Name: pymodbus'

Have you installed pymodbus for python3 correctly?
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!)
Huff002
Posts: 12
Joined: Saturday 29 August 2020 14:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Huff002 »

Ik did not notice any errors after installing.

Is there a way to check if the installation was succesfull?
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 RTU / ASCII / TCP/IP

Post by Domoticx »

Huff002 wrote: Saturday 29 August 2020 19:16 Ik did not notice any errors after installing.

Is there a way to check if the installation was succesfull?
have you used pip3 (not pip) for python 3?

sudo pip3 install -U pymodbus pymodbusTCP

to check.... you can see some examples here:
https://www.google.com/search?&q=python ... +installed
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!)
eSbek
Posts: 20
Joined: Saturday 20 April 2019 14:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by eSbek »

Hey developers of the plugin,
Some time ago I modded v1.0.9 for my house ventilation system to use different values of the fan speeds whenever I need (not using fixed payload value). So I decided to read a dedicated domoticz user variable inside the python script and write the value by Modbus to my ventilation system (eg. hi humidity detected in the bathroom -> speed goes on higher values).
Please find the mod if you want to develop same approach in your latest plugins:
https://pastebin.com/5zwiepyu
Fireflies
Posts: 1
Joined: Thursday 08 October 2020 16:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Fireflies »

Thanks for developing this nice plugin. I am trying to use this plugin with an EASTRON SDM120M Modbus coupled to an RS485 USB stick on a Raspberry PI in Domoticz. I am able to read the values from the device directly in the commandline with a tool, leading me to the conclusion that the hardware configuration is correct. However, the plugin seems to crash when I make a device in Domoticz. I cannot figure out what is going wrong. This is what the Domoticz log shows:

Code: Select all

2020-10-08 16:54:09.306 Error: (Modbus2) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/modbus-device/:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload:/usr/local/lib/python3.7/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.7/dist-packages'.
2020-10-08 16:54:09.306 Error: (Test) Module Import failed, exception: 'SyntaxError'
2020-10-08 16:54:09.306 Error: (Test) Import detail: File: /home/pi/domoticz/plugins/modbus-device/modbusregister.py, Line: 19, offset: 19
2020-10-08 16:54:09.307 Error: (Test) Error Line ' if devide<>"":
2020-10-08 16:54:09.307 '
2020-10-08 16:55:17.009 Error: Test hardware (11) thread seems to have ended unexpectedly
Is there anybody that can help me to sort this issue?
jurg1505
Posts: 8
Joined: Sunday 07 July 2019 22:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by jurg1505 »

Hello, great work.

Is it possible to make a BACnet plugin ?
User avatar
Domoberry
Posts: 116
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Domoberry »

Hi Forum,
I'm using the Modbus (read) plugin with a Sinotimer DDS024MR 3 phase energy meter. This works very well, thanks goes to Domotixz! I have two practical questions, I'm probably overlooking something:
1) I'm reading two values from the DSS024MR: current power (in Watts) and total energy (in kWh). Hence, two hardware devices created for reading the power and energy registers from the energy meter.
For power I have selected in the hardware settings the Sensor Type "usage" and as a result, a device appears with a correct icon, the value and the axis indication 'Watt'. Perfect!
For energy, I have selected the Sensor Type 'kWh' and the result is not as expected: In the devices list a new device appears, which has as Data two values separated by a comma: 1,495.427.....
201119 EVSE kWh device data.JPG
201119 EVSE kWh device data.JPG (23.6 KiB) Viewed 2924 times
There is no error in the log.
The 495.427... is the correct number of kWh, I'm not sure what the 1 represents.
However, the corresponding icon in the Utility tab shows no value nor daily total as other kWh icons do.
201119 strange KwH icon.JPG
201119 strange KwH icon.JPG (16.14 KiB) Viewed 2924 times
Where did I take a wrong turn?
(workaround: set as 'custom' Sensor Type and add 'kWh' as axis label)

2) To change the address of the device (or other parameter like baud rate, number of impulses, etc.) I need to write to the Parameter Register table using function 0x010 (16). I tried to write register 12 (number of impulses) which can be either 400 or 1600. The device manual states the number format is IEEE754, 32bit, single precision, so 400 -> "0x43C80000" and 1600 -> "0x44C80000" as 'payload on' and 'payload off' for testing. However, the log reads :Modbus error communicating". More or less randomly trying 0x43C8 and 0x44C8 (as the DomoticX Github suggests a format like 0x0100) yields "Exception Response (144, 16, Illegal function)". Doing something wrong... Any idea?
Update: it seems Parameter Register 12 can only be read and yields 400; it might not be possible to write is. The DDS024MR manual I have does not specify a register to read/write the number of impulses at all...
So, I should try to write another register!

@Fireflies: the log you copied states a failure to load 'plugin.py' for modbus, could that be related?
wbouwens
Posts: 6
Joined: Wednesday 09 December 2020 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by wbouwens »

Hello,

i also have an ABB B23 kwh modbus meter. I would like to read it in domoticz but I cannot get it working. Maybe sprokky would like to pass me the settings?
webrazor
Posts: 61
Joined: Monday 09 November 2015 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by webrazor »

wbouwens wrote: Wednesday 09 December 2020 10:22 Hello,

i also have an ABB B23 kwh modbus meter. I would like to read it in domoticz but I cannot get it working. Maybe sprokky would like to pass me the settings?
I am having the same problem can get it to work with my ABB B23 kwh meter.
So any help would be really great.
wbouwens
Posts: 6
Joined: Wednesday 09 December 2020 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by wbouwens »

I have my abb modbus meter working. You must change te A+ pin to B en B- to A. He was not communicating before, once i changed the wires he starts working.
wbouwens
Posts: 6
Joined: Wednesday 09 December 2020 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by wbouwens »

Hi Webrazor,

yes i am dutch. i cant send private messages. send me your email and i will reply to you.
webrazor
Posts: 61
Joined: Monday 09 November 2015 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by webrazor »

wbouwens wrote: Saturday 12 December 2020 19:46 Hi Webrazor,

yes i am dutch. i cant send private messages. send me your email and i will reply to you.
I send you a private message with my email.
webrazor
Posts: 61
Joined: Monday 09 November 2015 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by webrazor »

Domoberry wrote: Thursday 19 November 2020 8:03 For power I have selected in the hardware settings the Sensor Type "usage" and as a result, a device appears with a correct icon, the value and the axis indication 'Watt'. Perfect!
For energy, I have selected the Sensor Type 'kWh' and the result is not as expected: In the devices list a new device appears, which has as Data two values separated by a comma: 1,495.427.....
201119 EVSE kWh device data.JPG
There is no error in the log.
The 495.427... is the correct number of kWh, I'm not sure what the 1 represents.
However, the corresponding icon in the Utility tab shows no value nor daily total as other kWh icons do.
I have the same issue, also value "1, 2834,454" and in domoticz it won't show anything.
Also tried the Custom sensor but them you won't have a daily kWh usage.
Kyrille
Posts: 14
Joined: Sunday 19 January 2020 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.01
Location: France
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Kyrille »

Thanks a lot for these plugins !

Please note that the current version for the write plugin has a major bug (registers address not taken into account, whatever the mode).

See issue #28 in Gitlab (https://github.com/DomoticX/domoticz-mo ... it-eff45a5).
Raspberry Pi 4 (8GB) & 3B+ (buster) / Conbee II / Z-Stick Gen 5 / RFXCOM 433 XL / Domoticz 2020.02
Pi zero 2 ordered
ericplan
Posts: 1
Joined: Sunday 10 January 2021 20:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by ericplan »

Hi, New to Domoticz, new to Python, I try to connect a SBC PCD7.H104D module. Basicly this module converts 4 S0 kWh meters to MODBUS. It is set to replace a 8 channel EMU ag S0 logger which is obsolete now.

I have a working Domoticz, up to date with a Youless installed. No problems on this side. Domoticz runs on a Raspberry Pi 3B.
I have installed the Modbus plugin from Github and the Modbus plugin startup is ok without warnings.
Device is connected with USB from Domoticx (RS485 RTU USB-A 2.0 Adapter 3-Pin met CP2104 USB chip en MAX485+TVS) with ca 40 cm. wire.
Device address is set to 99 with the rotary switches.

I tried different registers (even with fixed data such as serial), different Data types. RTU should be correct, is taken from the manual, read holding register (function 3) is also in the manual. Tried the debug function as well, it is receiving 0 bytes.

Logfile is consistent, whatever I try.

Code: Select all

2021-01-10 21:54:58.888 Error: (Modread) Modbus error decoding or received no data (RTU/ASCII/RTU over TCP)!, check your settings!
2021-01-10 21:54:58.910 Error: (Modread) Modbus error decoding or received no data!, check your settings!
Device has an activity LED which glows every 15 seconds, but it is faint. I'm looking for some clues how to troubleshoot this.

I'm not stuck to Domoticz. If there's another way (node-red?) to get this device to put it's data in a csv-file every 5 minutes, this is also ok.
Thanks

Edit 11-01-21
Tried with minimalmodbus today. There is no response, tomorrow check on the pi and the usb dongle

Edit 12-01-21
After more reading and more testing I suspect the usb dongle to be the culprit. I ordered another one. Different brand, different type, different supplier. Keep you posted.

Edit 14-01-21
Problem solved. Documentation is insufficient on one essential point: cable polarity. I assumed D to be + and /D to be the -. Today I found out I was wrong. Honeywell has the same converter with another name (EEM-CONVERTER) and slightly different documentation.
Screenshot 2021-01-14 at 14.30.57.png
Screenshot 2021-01-14 at 14.30.57.png (126.57 KiB) Viewed 2605 times
Screenshot 2021-01-14 at 14.31.32.png
Screenshot 2021-01-14 at 14.31.32.png (137.57 KiB) Viewed 2605 times
Now communication is working my target is to ad this device as modbus-device to read the registers. I'm afraid I will return with some questions.
BBrouwer
Posts: 1
Joined: Monday 18 January 2021 19:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by BBrouwer »

webrazor wrote: Tuesday 05 January 2021 9:37
Domoberry wrote: Thursday 19 November 2020 8:03 For power I have selected in the hardware settings the Sensor Type "usage" and as a result, a device appears with a correct icon, the value and the axis indication 'Watt'. Perfect!
For energy, I have selected the Sensor Type 'kWh' and the result is not as expected: In the devices list a new device appears, which has as Data two values separated by a comma: 1,495.427.....
201119 EVSE kWh device data.JPG
There is no error in the log.
The 495.427... is the correct number of kWh, I'm not sure what the 1 represents.
However, the corresponding icon in the Utility tab shows no value nor daily total as other kWh icons do.
I have the same issue, also value "1, 2834,454" and in domoticz it won't show anything.
Also tried the Custom sensor but them you won't have a daily kWh usage.

i have the same problem someone already have a solution for this?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest