Help needed with dzVents

Moderator: leecollings

Post Reply
Fredom
Posts: 160
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Krimpen aan den IJssel
Contact:

Help needed with dzVents

Post 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
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help needed with dzVents

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Fredom
Posts: 160
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Krimpen aan den IJssel
Contact:

Re: Help needed with dzVents

Post 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
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help needed with dzVents

Post 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

Code: Select all

                   home.switchOff().silent()
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Fredom
Posts: 160
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Krimpen aan den IJssel
Contact:

Re: Help needed with dzVents

Post 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

Code: Select all

                   home.switchOff().silent()
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
}
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help needed with dzVents

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Fredom
Posts: 160
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Krimpen aan den IJssel
Contact:

Re: Help needed with dzVents

Post 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
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help needed with dzVents

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Fredom
Posts: 160
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Krimpen aan den IJssel
Contact:

Re: Help needed with dzVents

Post 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 .
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help needed with dzVents

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Fredom
Posts: 160
Joined: Saturday 19 September 2020 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Krimpen aan den IJssel
Contact:

Re: Help needed with dzVents

Post 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
Yours sincerely,
Fred

Rasberry Pi 3B+ - Debian Trixie - Domoticz 2025.2
RFLink - RFXCom - Zigbee (CC2531)
P1 Smart Meter - KaKu
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests