Page 1 of 1

Testing status of four switch devices and then i'm 'away'

Posted: Sunday 19 January 2020 0:39
by TeamKleijn
Hello All,

I have made a dummy switch and the following script.
The script have to be switch the dummy switch ''AwayFromHome' ON when everyone is gone from home. (All the below devices have to be OFF)
The numbers are not IDX numbers, they are part of the real names as i named the switches.

Code: Select all

commandArray = {}
if (otherdevices['053-Samsung_TV'] == 'Off' 
 and otherdevices['057-Denon_Receiver'] == 'Off'
 and otherdevices['021-MrEggHead'] == 'Off' 
 and otherdevices['022-JacolineSamsungS8'] == 'Off' 
 and otherdevices['023-SanneIphone8'] == 'Off' 
 and otherdevices['024-MarijkeSamsungS10'] == 'Off')
 then
    commandArray['AwayFromHome']='On'
    print('Nobody is at Home at this Moment')
   else
    commandArray['AwayFromHome']='Off'
    print('Somebody is at Home at this Moment')
end
return commandArray
it doesn't work :|, after paste the script in Events, save and start it. I'll switch the ''AwayFromHome'' switch manually on
after that, i switch my phone out for the wifi to get a trigger and hopely the 'AwayFromHome' switch goes on. (No it doesn't) what i'm doing wrong)

Thanks for advises

"Team Kleijn"
Rob

Re: Testing status of four switch devices and then i'm 'away'

Posted: Sunday 19 January 2020 16:17
by bewo
Hi Rob,

your scripts look's ok and probably should work. But there's an issue: In your way the Away-from-home-Switch would be triggered every time the scripts is executed, even when the status is already correct.
And i think it would be more comfortable when it's not necassary to list multiple "== 'Off' and so on...

A possible way would be:

Code: Select all

commandArray = {}

presence_devices = { 
    '053-Samsung_TV', '057-Denon_Receiver', '021-MrEggHead', 
    '022-JacolineSamsungS8', '023-SanneIphone8', '024-MarijkeSamsungS10'
}

-- Calculate the devices which are at home:
devices_at_home = 0
for Devices,Device in pairs(presence_devices) do
    if otherdevices[Device] == 'On' then
        devices_at_home = devices_at_home + 1
    end
end

-- Switch your dummy switch
if devices_at_home > 0 then
    if otherdevices['AwayFromHome'] == 'On' then
        commandArray['AwayFromHome'] = 'Off'
        print('Somebody is at Home at this Moment! Active devices: '..devices_at_home)
    end
else    
    if otherdevices['AwayFromHome'] == 'Off' then
        commandArray['AwayFromHome'] = 'On'
        print('Nobody is at Home at this Moment')
    end
end


return commandArray


Re: Testing status of four switch devices and then i'm 'away'

Posted: Tuesday 21 January 2020 22:56
by TeamKleijn
Hello Bewo,

I've pasted your script unchanged in my domoticz environment (have to choose for LUA script)
After activate it it switched the Away status off (Good).
Now tomorrow we 're all gone and the Away dummy switch have to be switched on.
For now the first impression is 'It's working'. :)

Thanks a lot and i'll hope the script is usefull for other forum members.
Tomorrow i'll be back and inform about the day status of the Away dummy switch

"Team Kleijn"
Rob

Re: Testing status of four switch devices and then i'm 'away'

Posted: Monday 27 January 2020 15:23
by TeamKleijn
Hello Bewoo,

It's working very good. Thanks a lot fro the clear script and documentation

Re: Testing status of four switch devices and then i'm 'away'

Posted: Monday 27 January 2020 15:27
by bewo
:D
Thanks for the reply. Always nice to hear when something is working... ;-)