![]() |
|
turn lights with double pulse in a switch - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: turn lights with double pulse in a switch (/showthread.php?tid=5200) |
turn lights with double pulse in a switch - JoseJimenez94 - 12.01.2024 Hi guys, I have been testing our colleague's solution (https://forum.logicmachine.net/showthread.php?tid=31&highlight=count+pulse) to be able to turn on two different lights with the same button using a single pulse or double pulse, but I can't get it to work properly (and I don't know if there is something I haven't understood well) I have created a resident script (sleep interval 0), where the address 16/1/1 is the press that I make on the button, the addresses 1/1/10 and 1/1/120 are the lights and the address 16/1/2 is an address that I have created to perform the count : Code: if not client then
require('genohm-scada.eibdgm')
-- knx group write handler
function groupwrite(event)
local value
value = knxdatatype.decode(event.datahex, dt.bool)
--first room
if event.dst == "16/1/1" then
switcher("16_1_1", "1/1/10", "1/1/120", "16/1/2", value)
end
end
client = eibdgm:new()
client:sethandler('groupwrite', groupwrite)
function switcher(event_adress, light1, light2, counter_object, value)
nowTIME = os.time()
counter = grp.getvalue(counter_object)
state = value
if (state == false) then
counter = counter + 1
log(counter)
lastONtime = storage.get('lastONtime' .. event_adress)
if (nowTIME - lastONtime > 1) then
log('long press ' .. event_adress)
grp.write(light1, false)
grp.write(light2, false)
grp.update(counter_object, 0)
else
grp.update(counter_object, counter)
end
else
storage.set('lastONtime' .. event_adress, nowTIME)
end
end
end
client:step()Code: value = tonumber(event.datahex, 16)
if value > 0 then
light1 = '1/1/10'
light2 = '1/1/120'
switcher_adress = '16/1/1'
os.sleep(1)
value = event.getvalue()
if value == 1 then
log('single press '.. switcher_adress)
grp.write(light1, not(grp.getvalue(light1)))
elseif value == 2 then
log('double ' .. switcher_adress)
grp.write(light2, not(grp.getvalue(light2)))
end
-- reset counter
if value > 0 then
grp.update(event.dst, 0)
end
endI hope you can help me. Thank you so much RE: turn lights with double pulse in a switch - admin - 12.01.2024 See this: https://kb.logicmachine.net/scripting/single-double-press/ |