(18.04.2024, 11:40)BrentW Wrote:(26.02.2024, 12:45)tomnord Wrote:Code:SW: 20230607
Hi Tomnord,
Any update on how you went with this integration?
We are also integrating with the UH50 using Mbus and the meters do have some peculiar behaviours.
Brent
I got it to work, had some issues with cables. All values ar updatet each 15min, but previous value is stored in mBus buffer.
Script below with separated GA's.
Code:
-- config init
if not meters then
require('mbus')
-- time to wait between each meter read
sleeptime = 10
-- use /dev/RS232 serial port with 2400 baud rate
mbus.init('/dev/RS232', 2400)
-- meter definition
-- addr - short address
-- id - number from data table where value resides
-- div - optional divisor for convertion to the final value
meters = {
{ ga = '3/0/0', addr = 10, id = 4, div = 10}, -- kW, dpt 14.
{ ga = '3/0/1', addr = 10, id = 2}, -- kWh dpt 12.
{ ga = '3/0/2', addr = 10, id = 5, div = 1000 }, -- m3h dpt 14
{ ga = '3/0/3', addr = 10, id = 6 }, --T1 dpt 12.
{ ga = '3/0/4', addr = 10, id = 7 }, -- T2 dpt 12.
{ ga = '3/1/0', addr = 20, id = 4, div = 10 }, -- kW
{ ga = '3/1/1', addr = 20, id = 2}, -- kWh
{ ga = '3/1/2', addr = 20, id = 5, div = 1000 }, --m3h
{ ga = '3/1/3', addr = 20, id = 6 }, --T1
{ ga = '3/1/4', addr = 20, id = 7 }, --T2
{ ga = '3/2/0', addr = 30, id = 4, div = 10 }, --kW
{ ga = '3/2/1', addr = 30, id = 2}, --kWh
{ ga = '3/2/2', addr = 30, id = 5, div = 1000 }, --m3h
{ ga = '3/2/3', addr = 30, id = 6 }, --T1
{ ga = '3/2/4', addr = 30, id = 7 }, --T2
}
-- reset meter values on first run
for _, meter in ipairs(meters) do
meter.value = 0
end
end
-- read each meter
for _, meter in ipairs(meters) do
res = mbus.getdata(meter.addr)
-- read ok
if type(res) == 'table' then
data = res.data[ meter.id ]
value = nil
-- get current value
if type(data) == 'table' then
value = tonumber(data.value)
end
-- value is valid and different from previous read
if value and meter.value ~= value then
-- apply divisor if set
div = meter.div
dpt = div and dt.float32 or dt.uint32
if div then
value = value / div
end
-- update group address value
grp.update(meter.ga, value, dpt)
meter.value = value
--log(meter.ga, meter.value, dpt)
end
end
-- wait for next read
os.sleep(sleeptime)
end