Beginner: Check for current switch state
Posted: Sunday 19 August 2018 17:12
I want to create (another) presence detection script. All smartphones use geofencing to notify Domoticz if they ware at home using a virtual switch.
If one smartphone is at home, the virtual switch SomeoneHome needs to be turned on. But, if all Smartphones are away, the SomeoneHome switch needs to be turned off.
I have an extra virtual switch that can be manually set, for if we have a guest and none of the smartphones is at home (babysitter for example)
The first part works, the second not.
I guess the last part of the script is only triggered when the state of all devices change.. so how do I check for the current state of 3 devices of one of them is changed..
If one smartphone is at home, the virtual switch SomeoneHome needs to be turned on. But, if all Smartphones are away, the SomeoneHome switch needs to be turned off.
I have an extra virtual switch that can be manually set, for if we have a guest and none of the smartphones is at home (babysitter for example)
The first part works, the second not.
Code: Select all
return {
on = {
devices = {
'Geofence A',
'Geofence B',
'Guest at Home'
}
},
execute = function(domoticz, device)
if ((device.name == 'Geofence A' and device.state == 'On') or
(device.name == 'Geofence B' and device.state == 'On') or
(device.name == 'Guest at Home' and device.state == 'On')) then
domoticz.devices('SomeoneHome').switchOn()
domoticz.log('Device ' .. device.name .. ' was turned On', domoticz.LOG_INFO)
end
if ((device.name == 'Geofence A' and device.state == 'Off') and
(device.name == 'Geofence B' and device.state == 'Off') and
(device.name == 'Guest at Home' and device.state == 'Off')) then
domoticz.devices('SomeoneHome').switchOff()
domoticz.log('Device ' .. device.name .. ' was turned Off', domoticz.LOG_INFO)
end
end