Re: Failing to understand
Posted: Saturday 25 January 2025 1:27
Isn't that what you require or is there something more complex I have misunderstood ?
Code: Select all
return {
on = {
devices = {
'Switch1',
'Switch2',
'Switch3',
'Switch4',
},
timer = {
'every 4 hours',
},
},
execute = function(domoticz, item)
local dz = domoticz
local dzd = dz.devices
local pump = dzd('Switch1')
local overflow = dzd('Switch2')
local headerFull = dzd('Switch3')
local tankLow = dzd('Switch4')
local chatter = item.isDevice and item.name or item.trigger
dz.log('Header Tank Script triggered by '..chatter, dz.LOG_INFO)
if overflow.state == 'Off' and headerFull.state == 'Off' and tankLow.state == 'Off' -- this ensures pump will only turn on if conditions are right
and chatter == 'every 4 hours' -- this ensure the pump only turns ON if the script was activated by the timer
then
pump.switchOn()
domoticz.log('Pump turning On triggered by '..chatter,dz.LOG_FORCE)
elseif chatter ~= 'every 4 hours'
then
pump.switchOff()
domoticz.log('Pump turning Off triggered by '..chatter,dz.LOG_FORCE)
end
if tankLow.state == 'On'
then
--put your notification method here
domoticz.log('Tank Low',dz.LOG_FORCE)
end
end
}
Code: Select all
return {
on = {
devices = {
'Switch2',
'Switch3',
'Switch4',
},
timer = {
'every 4 hours',
--'every 1 minutes' -- for testing
},
},
logging = {
level = domoticz.LOG_INFO,
marker = 'Filling the tank',
},
execute = function(domoticz, item)
local pump = domoticz.devices('Switch1') -- as it was said the Pump had to not trigger the script
local overflow = domoticz.devices('Switch2')
local headerFull = domoticz.devices('Switch3')
local tankLow = domoticz.devices('Switch4')
if item.isTimer then -- here are conditions for time
domoticz.log('Script is triggered by timer', domoticz.LOG_INFO)
if overflow.state == 'On' then -- or Off ? set what you need
pump.switchOn().checkFirst()
domoticz.log('Pump is turned on by timer and overflow', domoticz.LOG_INFO)
else
domoticz.log('Pump was NOT turned on by timer because of overflow', domoticz.LOG_INFO)
end
else -- here are conditions for devices
domoticz.log('Script is triggered by device '.. item.name, domoticz.LOG_INFO)
pump.switchOff().checkFirst()
domoticz.log('The pump was turned off the trigger device - '.. item.name, domoticz.LOG_INFO)
if item.name == 'Switch4' then -- put here the name of device
domoticz.log('The Tank level is LOW. You can put here any notification or turn the pump ON', domoticz.LOG_INFO)
end
end
end
}
habahabahaba wrote: Saturday 25 January 2025 14:31 Let me try
Code: Select all
return { on = { devices = { 'Switch2', 'Switch3', 'Switch4', }, timer = { 'every 4 hours', --'every 1 minutes' -- for testing }, }, logging = { level = domoticz.LOG_INFO, marker = 'Filling the tank', }, execute = function(domoticz, item) local pump = domoticz.devices('Switch1') -- as it was said the Pump had to not trigger the script local overflow = domoticz.devices('Switch2') local headerFull = domoticz.devices('Switch3') local tankLow = domoticz.devices('Switch4') if item.isTimer then -- here are conditions for time domoticz.log('Script is triggered by timer', domoticz.LOG_INFO) if overflow.state == 'On' then -- or Off ? set what you need pump.switchOn().checkFirst() domoticz.log('Pump is turned on by timer and overflow', domoticz.LOG_INFO) else domoticz.log('Pump was NOT turned on by timer because of overflow', domoticz.LOG_INFO) end else -- here are conditions for devices domoticz.log('Script is triggered by device '.. item.name, domoticz.LOG_INFO) pump.switchOff().checkFirst() domoticz.log('The pump was turned off the trigger device - '.. item.name, domoticz.LOG_INFO) if item.name == 'Switch4' then -- put here the name of device domoticz.log('The Tank level is LOW. You can put here any notification or turn the pump ON', domoticz.LOG_INFO) end end end }