04.10.2016, 10:54
(This post was last modified: 04.10.2016, 10:55 by Erwin van der Zwart.)
Hi,
Here is a version with writing to KNX objects:
BR,
Erwin
Here is a version with writing to KNX objects:
Code:
-- Check all modbus meters for connection
-- Function to send changes to KNX
function writetoknx(name,active)
if name == 'Meter 1' then -- name must match modbus device name
grp.write('1/1/1', toboolean(active))
elseif name == 'Meter 2' then
grp.write('1/1/2', toboolean(active))
elseif name == 'Meter 3' then
grp.write('1/1/3', toboolean(active))
elseif name == 'Meter 4' then
grp.write('1/1/4', toboolean(active))
elseif name == 'Meter 5' then
grp.write('1/1/5', toboolean(active))
end
end
-- Get meter status
query = 'SELECT * FROM modbus_devices'
meter_state = db:getall(query)
previous_state = storage.get('meterstate')
if previous_state == nil then
for _, device in ipairs(meter_state) do
writetoknx(device.name,device.active)
end
storage.set('meterstate', meter_state)
else
for _, device in ipairs(meter_state) do
if device.active ~= previous_state[_].active then
writetoknx(device.name,device.active)
end
end
storage.set('meterstate', meter_state)
end
BR,
Erwin