Simple Script not working

Moderator: leecollings

Post Reply
TeamKleijn
Posts: 14
Joined: Sunday 05 January 2020 13:03
Target OS: -
Domoticz version:
Contact:

Simple Script not working

Post 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"
wim57
Posts: 27
Joined: Monday 25 September 2017 12:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Simple Script not working

Post by wim57 »

What is the trigger for your script?
You can use print statements for debugging, they show in the log.
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Simple Script not working

Post 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
        
Bugs bug me.
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Simple Script not working

Post 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.
TeamKleijn
Posts: 14
Joined: Sunday 05 January 2020 13:03
Target OS: -
Domoticz version:
Contact:

Re: Simple Script not working

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest