https://www.domoticz.com/forum/viewtopi ... 63&t=19197
Everything works fine but you need to SSH and CronTab all kind of things.
I wrote a script in DzVents that does the same and is a lot easier to use. You need at least DzVents version 2.4.0.
Same as in the previous link you create a virtual switch for every device you want to monitor.
Make sure DzVents is activated in your Domoticz settings. Check the next link on instructions.
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
In the script you change 5 lines of code to your personal settings.
1. Change IP and Port to your Unifi Controller settings.
2. Change YourPassword and YourUsername to your password and username for Unifi Controller (I advice to create a separate read-only admin in your Unifi controller with only system stats access).
3. Change IP and Port to your Unifi Controller settings.
4. Change the mac addresses to addresses of devices you want to monitor. Mac addresses are case sensitive!!
5. Change the Id (Idx) of the devices you want to monitor, the position in DxIndx has to be the same as the position of the mac adress for that device in Mac.
You can add or remove device in step 4 and 5. Just make sure both, mac addresses and Idx numbers, match. So every mac address in Mac needs an Idx in DzInx on the same position.
Activate the script and the monitoring starts.
The Unifi Controller can take up to five minutes to detect a device leaving WiFi. The script runs every five minutes. Worst case it takes ten minutes to detect a device is not present on Wifi by Domoticz.
Code: Select all
return {
on = {
timer = { 'every 5 minutes' },
httpResponses = { 'loggedin' , 'data' }
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'https://192.168.1.1:8443/api/login', --Change IP and Port to your Unifi Controller settings
method = 'POST',
postData = { ['password'] = 'YourPassword' , ['username'] = 'YourUsername' }, --Change YourPassword en YourUsername to your password en username for Unifi Controller (I advice to create a separate read-only admin in your Unifi controller with only system stats access)
callback = 'loggedin'
})
end
if (item.isHTTPResponse and item.ok) then
if (item.trigger == 'loggedin') then
domoticz.openURL({
url = 'https://192.168.1.1:8443/api/s/default/stat/sta', --Change IP and Port to your Unifi Controller settings
method = 'GET',
callback = 'data'
})
else
local Mac = {'11:aa:22:bb:33:cc' , '11:aa:22:bb:33:cc' , '11:aa:22:bb:33:cc' , '11:aa:22:bb:33:cc' , '11:aa:22:bb:33:cc' } --Change to mac addresses of devices you want to monitor
local DzIndx = {11,12,13,22,33} --Change to Domiticz Idx, the position in DxIndx has to be the same as the mac adress for that device in Mac (previous line)
for i,y in ipairs(Mac)
do
home = string.find( item.data , Mac[i])
if (home == nil) then
domoticz.devices(DzIndx[i]).switchOff().checkFirst()
else
domoticz.devices(DzIndx[i]).switchOn().checkFirst()
end
end
end
end
end
}