Page 1 of 1
Help needed with dzVents
Posted: Monday 10 May 2021 16:47
by Fredom
Dear members
Who can get this script working for me?
The intention is that if a telephone comes into the house and 'Thuis' is Off,
a notification will be sent to Telegram with the name of the telephone.
And when 'Thuis' is On, no message goes to telegram.
Code: Select all
local phone =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
local allDevices = phone -- copy the phones table to table allDevices
table.insert(allDevices, 'Thuis') -- this will add this deviceName to the table allDevices
return
{
active = true,
on =
{
devices = allDevices,
},
execute = function(dz, devices)
local schakelaar = dz.devices('Thuis')
local atHome = Thuis.active
if schakelaar.active then
return
else
for _, phoneName in ipairs(phone) do
local phone = dz.devices(phoneName)
if not(schakelaar.active) then
dz.notify('Devices', 'Device ' .. phoneName .. ' komt binnen ')
end
end
end
}
Thanks in advance
Fredom
Re: Help needed with dzVents
Posted: Monday 10 May 2021 17:28
by waaren
Fredom wrote: Monday 10 May 2021 16:47
Who can get this script working for me?
Could look like below.
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
if atHome then
dz.log('Er is iemand thuis', dz.LOG_DEBUG)
return
elseif item.active then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORNAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().silent()
dz.log('Er komt iemand thuis', dz.LOG_DEBUG)
else -- just an extra check
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log('At least one phone active', dz.LOG_DEBUG)
home.switchOn().silent()
return
end
end
end
end
}
Re: Help needed with dzVents
Posted: Monday 10 May 2021 20:07
by Fredom
waaren wrote: Monday 10 May 2021 17:28
Fredom wrote: Monday 10 May 2021 16:47
Who can get this script working for me?
Could look like below.
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
if atHome then
dz.log('Er is iemand thuis', dz.LOG_DEBUG)
return
elseif item.active then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORNAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().silent()
dz.log('Er komt iemand thuis', dz.LOG_DEBUG)
else -- just an extra check
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log('At least one phone active', dz.LOG_DEBUG)
home.switchOn().silent()
return
end
end
end
end
}
Hi Waaren,
Thank you for the quick response and commitment.
When all telephones leave the house again, the 'Thuis' should switch Off again.
This is not happening now. Can this also be adjusted?
For the rest it works perfectly
Fredom
Re: Help needed with dzVents
Posted: Monday 10 May 2021 21:28
by waaren
Fredom wrote: Monday 10 May 2021 20:07
When all telephones leave the house again, the 'Thuis' should switch Off again.
This is not happening now. Can this also be adjusted?
Yes that is possible. Add as line 43
Re: Help needed with dzVents
Posted: Monday 10 May 2021 22:51
by Fredom
waaren wrote: Monday 10 May 2021 21:28
Fredom wrote: Monday 10 May 2021 20:07
When all telephones leave the house again, the 'Thuis' should switch Off again.
This is not happening now. Can this also be adjusted?
Yes that is possible. Add as line 43
Hi waaren,
Unfortunately it doesn't work (yet).
'Thuis' stays On when all phones are out of the house.
See script below
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
if atHome then
dz.log('Er is iemand thuis', dz.LOG_DEBUG)
return
elseif item.active then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORNAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().silent()
dz.log('Er komt iemand thuis', dz.LOG_DEBUG)
else -- just an extra check
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log('At least one phone active', dz.LOG_DEBUG)
home.switchOn().silent()
return
end
end
home.switchOff().silent()
end
end
}
Re: Help needed with dzVents
Posted: Monday 10 May 2021 23:35
by waaren
Fredom wrote: Monday 10 May 2021 22:51
Unfortunately it doesn't work (yet).
'Thuis' stays On when all phones are out of the house.
Can you check below version.
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
local function phonesActive()
local activePhones = 0
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log(phoneName .. ' active', dz.LOG_DEBUG)
activePhones = activePhones + 1
end
end
return activePhones
end
if item.active then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORMAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().checkFirst().silent()
dz.log(item.name:gsub('Mobiel ', '') .. ' komt thuis. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
return
elseif phonesActive() > 0 then
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
home.switchOn().checkFirst().silent()
else
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu geen mobiele telefoons meer binnen.', dz.LOG_DEBUG)
home.switchOff().checkFirst().silent()
end
end
}
Re: Help needed with dzVents
Posted: Tuesday 11 May 2021 8:40
by Fredom
waaren wrote: Monday 10 May 2021 23:35
Fredom wrote: Monday 10 May 2021 22:51
Unfortunately it doesn't work (yet).
'Thuis' stays On when all phones are out of the house.
Can you check below version.
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
local function phonesActive()
local activePhones = 0
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log(phoneName .. ' active', dz.LOG_DEBUG)
activePhones = activePhones + 1
end
end
return activePhones
end
if item.active then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORMAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().checkFirst().silent()
dz.log(item.name:gsub('Mobiel ', '') .. ' komt thuis. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
return
elseif phonesActive() > 0 then
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
home.switchOn().checkFirst().silent()
else
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu geen mobiele telefoons meer binnen.', dz.LOG_DEBUG)
home.switchOff().checkFirst().silent()
end
end
}
Hi waaren,
We are almost there.
'Home' Now also switches off when all phones are off.
Unfortunately when 'Home' is on and another phone comes in, another message comes from Telegram.
If there is 1 phone in then 'Home' will turn on after that no more notifications please.
Fredom
Re: Help needed with dzVents
Posted: Tuesday 11 May 2021 8:51
by waaren
Fredom wrote: Tuesday 11 May 2021 8:40
Unfortunately when 'Home' is on and another phone comes in, another message comes from Telegram.
If there is 1 phone in then 'Home' will turn on after that no more notifications please.
This should prevent the extra notifications.
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
local function phonesActive()
local activePhones = 0
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log(phoneName .. ' active', dz.LOG_DEBUG)
activePhones = activePhones + 1
end
end
return activePhones
end
if item.active then
if not(atHome) then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORMAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().silent()
end
dz.log(item.name:gsub('Mobiel ', '') .. ' komt thuis. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
elseif phonesActive() > 0 then
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
home.switchOn().checkFirst().silent()
else
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu geen mobiele telefoons meer binnen.', dz.LOG_DEBUG)
home.switchOff().checkFirst().silent()
end
end
}
Re: Help needed with dzVents
Posted: Tuesday 11 May 2021 11:46
by Fredom
waaren wrote: Tuesday 11 May 2021 8:51
Fredom wrote: Tuesday 11 May 2021 8:40
Unfortunately when 'Home' is on and another phone comes in, another message comes from Telegram.
If there is 1 phone in then 'Home' will turn on after that no more notifications please.
This should prevent the extra notifications.
Code: Select all
local phones =
{
'Mobiel Mariska',
'Mobiel Barney',
'Mobiel Nils',
'Mobiel Test'
}
return
{
active = true,
on =
{
devices = phones,
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'phones',
},
execute = function(dz, item)
local home = dz.devices('Thuis')
local atHome = home.active
local function phonesActive()
local activePhones = 0
for _, phoneName in ipairs(phones) do
if dz.devices(phoneName).active then
dz.log(phoneName .. ' active', dz.LOG_DEBUG)
activePhones = activePhones + 1
end
end
return activePhones
end
if item.active then
if not(atHome) then
dz.notify('Devices', 'Device ' .. item.name .. ' komt binnen ', dz.PRIORITY_NORMAL,'' ,'',dz.NSS_TELEGRAM)
home.switchOn().silent()
end
dz.log(item.name:gsub('Mobiel ', '') .. ' komt thuis. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
elseif phonesActive() > 0 then
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu ' .. phonesActive() .. ' mobiele telefoons binnen.', dz.LOG_DEBUG)
home.switchOn().checkFirst().silent()
else
dz.log(item.name:gsub('Mobiel ', '') .. ' vertrekt. Er zijn nu geen mobiele telefoons meer binnen.', dz.LOG_DEBUG)
home.switchOff().checkFirst().silent()
end
end
}
Hi waaren,
This resolved the notifications.
But now 'Thuis' is no longer turned On and Off .
Re: Help needed with dzVents
Posted: Tuesday 11 May 2021 12:42
by waaren
Fredom wrote: Tuesday 11 May 2021 11:46
This resolved the notifications.
But now 'Thuis' is no longer turned On and Off .
Please double check the copy / paste of my last posted version. When I test it the notifications only arrive when a first phone comes in and the home switch is switched On / Off with the expected conditions.
If you are sure the copy / paste was OK then I would like to see the resulting loglines.
Re: Help needed with dzVents
Posted: Tuesday 11 May 2021 19:03
by Fredom
waaren wrote: Tuesday 11 May 2021 12:42
Fredom wrote: Tuesday 11 May 2021 11:46
This resolved the notifications.
But now 'Thuis' is no longer turned On and Off .
Please double check the copy / paste of my last posted version. When I test it the notifications only arrive when a first phone comes in and the home switch is switched On / Off with the expected conditions.
If you are sure the copy / paste was OK then I would like to see the resulting loglines.
Hello Waaren,
The script works perfectly.
The problem was my WIFI.
Thank you very much for your dedication and expertise.
Groet
Fredom