Page 1 of 1

Simple Script not working

Posted: Saturday 08 February 2025 21:23
by TeamKleijn
Hello all,

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.

Code: Select all

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
It doesn't work, why ???

Please Help

Rob
"Team Kleijn"

Re: Simple Script not working

Posted: Saturday 08 February 2025 22:43
by wim57
What is the trigger for your script?
You can use print statements for debugging, they show in the log.

Re: Simple Script not working

Posted: Sunday 09 February 2025 9:47
by HvdW

Code: Select all

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
        

Re: Simple Script not working

Posted: Sunday 09 February 2025 11:35
by jannl
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.

Re: Simple Script not working

Posted: Wednesday 12 February 2025 23:40
by TeamKleijn
HvdW wrote: Sunday 09 February 2025 9:47

Code: Select all

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.

I'm happy it's working as i wished.

"Team Kleijn"
Rob