Hi, I am going to connect two rather large devices: a heat pump (Nibe), and a ventilation system (Östbergs Heru), both via Modbus (via a RS485 serial-to-USB bridge). I can of course write userspace scripts that communicate with these, say in Python, and let these run in the background, but I would rather have it tied closer into domoticz.
This would require Modbus compatibility. Is it already present? Or can I add it? How about the above (complicated) systems, can I create templates for these?
Modbus
Moderator: leecollings
-
- Posts: 18
- Joined: Friday 29 July 2016 9:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: United Kingdom
- Contact:
Re: Modbus
I'm doing some work with Modbus, it has been something I wanted to do for a while because I have some PLCs which speak Modbus RTU that I want to control. Different to your sensors but I am making a start on things using minimalmodbus in Python:
http://minimalmodbus.readthedocs.io/en/ ... eadme.html
So far I have written a Python script that collects data from my PLC, but I haven't done the Domoticz part yet, my dilemma currently is how to inject that data in to Domoticz. My dilemma is: all the examples focus on a single sensor, switch or limited data points, but my PLC has 12 inputs and 6 outputs. How do I represent that or filter that into Domoticz?
Here is my code, please note that I am not a professional coder and this is my first attempt at Python.
Bob
http://minimalmodbus.readthedocs.io/en/ ... eadme.html
So far I have written a Python script that collects data from my PLC, but I haven't done the Domoticz part yet, my dilemma currently is how to inject that data in to Domoticz. My dilemma is: all the examples focus on a single sensor, switch or limited data points, but my PLC has 12 inputs and 6 outputs. How do I represent that or filter that into Domoticz?
Here is my code, please note that I am not a professional coder and this is my first attempt at Python.

Bob
Code: Select all
pi@raspberrypi:~/modbus/python$ cat readtest.py
#!/usr/bin/env python
import minimalmodbus
import serial
import time
inputCount = 12
outputCount = 6
regCount = 16 # Should be 256
middleCoil = 16 # Should be 256
flagCount = 32
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port name, slave address (in decimal)
instrument.serial.baudrate = 38400
instrument.timeout = 0.5
instrument.precalculate_read_size = False
instrument.write_long(9, 12451840)
while (1):
count = 0
print '= Input Registers ='
while (count < inputCount):
coil = instrument.read_bit(count, 2) # Registernumber, number of decimals
print 'input:', count+1, 'value:', coil
count = count + 1
# time.sleep(1)
count = 0
print '= Digital Outputs ='
while (count < outputCount):
coil = instrument.read_bit(count, 1) # Registernumber, number of decimals
print 'coil:', count+1, 'value:', coil
count = count + 1
# time.sleep(1)
count = 0
print '= Middle Coil ='
while (count < middleCoil):
coil = instrument.read_bit((256 + count), 1) # Registernumber, number of decimals
if (coil > 0):
print 'coil:', count+1, 'value:', coil
count = count + 1
count = 0
print '= Digital Flag ='
while (count < flagCount):
# This is broken somehow
# coil = instrument.read_bit((768 + count), 1) # Registernumber, number of decimals
if (coil > 0):
print 'value:', count+1, 'value:', coil
count = count + 1
count = 0
print '= Holding Registers ='
while (count < regCount):
coil = instrument.read_long(count, 3) # Registernumber, number of decimals
if (coil > 0):
print 'value:', count+1, 'value:', coil
count = count + 1
time.sleep(1)
-
- Posts: 3
- Joined: Friday 15 July 2016 10:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Modbus
Yes, exactly. A script like that would work, and with the python support compiled into domoticz one could use user variables and dummy sensors/switches to get the whole thing to work, but that seems overly complicated. This would be my fallback solution.
Ideally, though, I'd like to add native hardware support for modbus (which is a serial communication protocol) directly in domoticz, perhaps using the 1wire code (another serial protocol) as a template. Then it would be possible to add sensors within domoticz directly. But I need some sort of pointer to where the actual devices are specified, and crucially, how complicated devices like this need to be handled.
I own one complicated sensor (Popp z-weather) and I am not really satisfied with how that is treated: appears as several items in the web interface but if one of these are chosen for the front page, then all of them are.
Ideally, though, I'd like to add native hardware support for modbus (which is a serial communication protocol) directly in domoticz, perhaps using the 1wire code (another serial protocol) as a template. Then it would be possible to add sensors within domoticz directly. But I need some sort of pointer to where the actual devices are specified, and crucially, how complicated devices like this need to be handled.
I own one complicated sensor (Popp z-weather) and I am not really satisfied with how that is treated: appears as several items in the web interface but if one of these are chosen for the front page, then all of them are.
-
- Posts: 18
- Joined: Friday 29 July 2016 9:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: United Kingdom
- Contact:
Re: Modbus
Yes, the 1-Wire code looks good, I don't feel confident to start hacking around with it but I would be interested in offering a modest bounty if anyone is interested in doing it. I am only interested for personal purposes but it is significant enough that I would put money behind it.
Who is online
Users browsing this forum: No registered users and 1 guest