I want to conditionally Switch off the printer and screens poweer supply when the below Computers are not responding at pings anymore and if the 'Printer en Schermen Lock' isn't switched on (Virtual switch). If the three conditions are true, the switch 'Printer en Schermen (Son85)' should be gone off.
commandArray = {}
if (otherdevices['Computer_1'] == 'Off' and otherdevices['Computer_2'] == 'Off' and otherdevices['Printer en Schermen Lock'] == 'Off') then
commandArray['Printer en Schermen (Son85)'] = 'Off AFTER 5'
end
return commandArray
commandArray = {}
-- Logging function
function log(message)
print(os.date("%Y-%m-%d %H:%M:%S") .. " - " .. message)
end
if (otherdevices['Computer_1'] == 'Off' and otherdevices['Computer_2'] == 'Off' and otherdevices['Printer en Schermen Lock'] == 'Off') then
commandArray['Printer en Schermen (Son85)'] = 'Off AFTER 5'
log("All devices are off. Command to turn off 'Printer en Schermen (Son85)' after 5 minutes has been added.")
else
if otherdevices['Computer_1'] ~= 'Off' then
log("Computer_1 is not off.")
end
if otherdevices['Computer_2'] ~= 'Off' then
log("Computer_2 is not off.")
end
if otherdevices['Printer en Schermen Lock'] ~= 'Off' then
log("Printer en Schermen Lock is not off.")
end
end
return commandArray
I check the powerusage of the plug. If it is lower then the standby usage I switch it off.
When I switch it on, the computer is switched on because of a power resume setting in the bios, or I sent the magic WOL package. Depending on the computer.
But as wim asks, what triggers your script.
You can use print statements to check the status of the switches. And if it is a new switch, switch ut manually some times. It helped me in the past.
commandArray = {}
-- Logging function
function log(message)
print(os.date("%Y-%m-%d %H:%M:%S") .. " - " .. message)
end
if (otherdevices['Computer_1'] == 'Off' and otherdevices['Computer_2'] == 'Off' and otherdevices['Printer en Schermen Lock'] == 'Off') then
commandArray['Printer en Schermen (Son85)'] = 'Off AFTER 5'
log("All devices are off. Command to turn off 'Printer en Schermen (Son85)' after 5 minutes has been added.")
else
if otherdevices['Computer_1'] ~= 'Off' then
log("Computer_1 is not off.")
end
if otherdevices['Computer_2'] ~= 'Off' then
log("Computer_2 is not off.")
end
if otherdevices['Printer en Schermen Lock'] ~= 'Off' then
log("Printer en Schermen Lock is not off.")
end
end
return commandArray
I've installed this script into my Domoticz and after some little tweaks it works.
Thanks a lot HvdW for this information.