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

Moderator: leecollings

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

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

Post 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
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

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

Post 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

Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
TeamKleijn
Posts: 15
Joined: Sunday 05 January 2020 13:03
Target OS: -
Domoticz version:
Contact:

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

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

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

Post by TeamKleijn »

Hello Bewoo,

It's working very good. Thanks a lot fro the clear script and documentation
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

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

Post by bewo »

:D
Thanks for the reply. Always nice to hear when something is working... ;-)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest