add dummy to automatic script  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

add dummy to automatic script

Post by Larsoss »

hello guys,

I have a question .. I use the script below to automatically switch the lamps on LUX .. Works perfectly, no problem ..

However, I want to add a dummy sensor that I use. This one is geolocated from my phone .. and turns on / off nicely when I am or not near my house .. however I now want to have it switch on / off + lux when the dummy is on.

so dummy 'Lars phone & Desiree phone' = on and the lux is lower than 'xx' then the group can be on .. actually like the script already works but this addition ..

how / what / where should I put this?

Code: Select all

return {
            on      =   {   timer =   { "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00 " } },
       
    execute = function(dz)
        lowerLux          = 11 -- Onder welke niveau moet het script starten.
        upperLux          = 45 -- Boven de waarde gaan de lampen automatisch uit. 
        currentLux        = dz.devices(46).lux       --lux sensor
        woonkamerlampen   = dz.groups("Woonkamer")   --Dummy switch day/night.

        if currentLux < lowerLux then
            woonkamerlampen.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}

Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: add dummy to automatic script

Post by waaren »

Larsoss wrote: Thursday 17 September 2020 21:42 so dummy 'Lars phone & Desiree phone' = on and the lux is lower than 'xx' then the group can be on .. actually like the script already works but this addition ..
how / what / where should I put this?
Can you try this?

Code: Select all

return 
{
    on = 
    {   
        timer =   
        { 
            "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00", 
        }, 
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'lux',
    },
    
    execute = function(dz)
        local lowerLux          = 11 -- Onder welke niveau moet het script starten.
        local upperLux          = 45 -- Boven de waarde gaan de lampen automatisch uit. 
        local currentLux        = dz.devices(46).lux       --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")   --Dummy switch day/night.
        local phonesOn          = dz.devices('Lars phone & Desiree phone').state == 'On'
        
        if ( currentLux < lowerLux ) and phonesOn then
            woonkamerlampen.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: add dummy to automatic script

Post by Larsoss »

waaren wrote: Thursday 17 September 2020 22:30
Larsoss wrote: Thursday 17 September 2020 21:42 so dummy 'Lars phone & Desiree phone' = on and the lux is lower than 'xx' then the group can be on .. actually like the script already works but this addition ..
how / what / where should I put this?
Can you try this?

Code: Select all

return 
{
    on = 
    {   
        timer =   
        { 
            "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00", 
        }, 
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'lux',
    },
    
    execute = function(dz)
        local lowerLux          = 11 -- Onder welke niveau moet het script starten.
        local upperLux          = 45 -- Boven de waarde gaan de lampen automatisch uit. 
        local currentLux        = dz.devices(46).lux       --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")   --Dummy switch day/night.
        local phonesOn          = dz.devices('Lars phone & Desiree phone').state == 'On'
        
        if ( currentLux < lowerLux ) and phonesOn then
            woonkamerlampen.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}
Yes Waaren, that works .. Only 1 mistake in which I was perhaps not clear ... There are 2 dummies that switch, so 1 phone from Lars and 1 from Desiree ... Now they both have to be on for the script to turn on the lights But the intention is if one of the dummies is on .. Either lars foon or dees foon ....

Sorry I was not clear enough about what I wanted .. I suspect that an if / or should be added very simply?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: add dummy to automatic script

Post by waaren »

Larsoss wrote: Friday 18 September 2020 15:43 There are 2 dummies that switch, so 1 phone from Lars and 1 from Desiree ... Now they both have to be on for the script to turn on the lights But the intention is if one of the dummies is on .. Either lars foon or dees foon ....
This should do it for one or both phones.

Code: Select all

return 
{
    on = 
    {   
        timer =   
        { 
            "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00", 
        }, 
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'lux',
    },
    
    execute = function(dz)
        local lowerLux          = 11 -- Onder welke niveau moet het script starten.
        local upperLux          = 45 -- Boven de waarde gaan de lampen automatisch uit. 
        local currentLux        = dz.devices(46).lux       --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")   --Dummy switch day/night.
        local phoneLarsOn       = dz.devices('Lars phone').state == 'On'
        local phoneDesireeOn    = dz.devices('Desiree phone').state == 'On'
        
        if ( currentLux < lowerLux ) and ( phoneLarsOn or phoneDesireeOn ) then
            woonkamerlampen.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: add dummy to automatic script

Post by Larsoss »

Thank you..

This is working perfectly.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: add dummy to automatic script

Post by Larsoss »

waaren wrote: Friday 18 September 2020 15:54
Larsoss wrote: Friday 18 September 2020 15:43 There are 2 dummies that switch, so 1 phone from Lars and 1 from Desiree ... Now they both have to be on for the script to turn on the lights But the intention is if one of the dummies is on .. Either lars foon or dees foon ....
This should do it for one or both phones.

Code: Select all

return 
{
    on = 
    {   
        timer =   
        { 
            "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00", 
        }, 
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'lux',
    },
    
    execute = function(dz)
        local lowerLux          = 11 -- Onder welke niveau moet het script starten.
        local upperLux          = 45 -- Boven de waarde gaan de lampen automatisch uit. 
        local currentLux        = dz.devices(46).lux       --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")   --Dummy switch day/night.
        local phoneLarsOn       = dz.devices('Lars phone').state == 'On'
        local phoneDesireeOn    = dz.devices('Desiree phone').state == 'On'
        
        if ( currentLux < lowerLux ) and ( phoneLarsOn or phoneDesireeOn ) then
            woonkamerlampen.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}
I tought put it a extra group to it, but thats not at easy as i thougt..
what did i wrong? Because i put and to it..

Code: Select all

return 
{
    on = 
    {   
        timer =   
        { 
            "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00", 
        }, 
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Auto verlichting ON',
    },
    
    execute = function(dz)
        local lowerLux          = 11                            -- Onder welke niveau moet het script starten.
        local upperLux          = 45                            -- Boven de waarde gaan de lampen automatisch uit. 
        local currentLux        = dz.devices(46).lux            --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")        --Groep schakelaar Woonkamer.
        local tuin              = dz.groups("Tuin")             --Groep schakelaar Tuin.
        local phoneLarsOn       = dz.devices(150).state == 'On' --Dummy Telefoon Lars
        local phoneDesireeOn    = dz.devices(151).state == 'On' --Dummy Telefoon Dees
        
        if ( currentLux < lowerLux ) and ( phoneLarsOn or phoneDesireeOn ) then
            woonkamerlampen.switchOn().checkFirst() and tuin.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: add dummy to automatic script  [Solved]

Post by waaren »

Larsoss wrote: Friday 18 September 2020 20:29 I tought put it a extra group to it, but thats not at easy as i thougt..
what did i wrong? Because i put and to it..
You don't use the and. Just another line with the new command will do.

Code: Select all

return
{
    on =
    {
        timer =
        {
            "every 3 minutes on mon, tue, wed, thu, fri between 06:50 and 21:00",
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Auto verlichting ON',
    },

    execute = function(dz)
        local lowerLux          = 11                            -- Onder welke niveau moet het script starten.
        local upperLux          = 45                            -- Boven de waarde gaan de lampen automatisch uit.
        local currentLux        = dz.devices(46).lux            --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")        --Groep schakelaar Woonkamer.
        local tuin              = dz.groups("Tuin")             --Groep schakelaar Tuin.
        local phoneLarsOn       = dz.devices(150).state == 'On' --Dummy Telefoon Lars
        local phoneDesireeOn    = dz.devices(151).state == 'On' --Dummy Telefoon Dees

        if ( currentLux < lowerLux ) and ( phoneLarsOn or phoneDesireeOn ) then
            woonkamerlampen.switchOn().checkFirst()
            tuin.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest