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.
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
Yours sincerely,
Fred
Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
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
}
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
Yours sincerely,
Fred
Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
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?
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?
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
}
Yours sincerely,
Fred
Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
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
}
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
Yours sincerely,
Fred
Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
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.
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
}
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.
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 .
Yours sincerely,
Fred
Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
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.
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
Yours sincerely,
Fred
Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu