Page 1 of 1

action when person arrives

Posted: Saturday 04 July 2020 16:25
by loeknl
I use an OnlineChecker script to see if my partners or my phone is at home. The script triggers a virtual switch (on is ‘at home’, off is ‘away’). I would like to have a light switch on if one of us comes at home during the night:
e.g. IF Time > 0:30h and time < 4:00h AND switch person1 OR person2 turns on THEN turn on light.

Problem is that i cannot find a way to Blocky use the ‘changes state’ as a trigger. Now the problem is the script keeps turning the light on because one of our phones are at home. When I use only ‘device’ as a trigger, turning off at our wish the ligt re-triggers the script and therefore keeping the ligt in a ‘on’ loop.
I also thought about setting a user variable if the device is switched off, to prevent a ‘on-loop’ but I cannot work that out either.

Does someone have a solution? i can imagine is is a quite common application..
Blockly.png
Blockly.png (80.27 KiB) Viewed 565 times

Re: action when person arrives

Posted: Saturday 04 July 2020 18:36
by waaren
loeknl wrote: Saturday 04 July 2020 16:25 Problem is that i cannot find a way to Blocky use the ‘changes state’ as a trigger. Now the problem is the script keeps turning the light on because one of our phones are at home. When I use only ‘device’ as a trigger, turning off at our wish the ligt re-triggers the script and therefore keeping the ligt in a ‘on’ loop.
I would not know how to solve it using Blockly. A dzVents solution could look like below script

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

return
{
    on =
    {
        devices =
        {
            [ 'phone1' ] = { 'between 00:45 and sunrise' }, -- change names of phone1, phone2
            [ 'phone2' ] = { 'between 00:45 and sunrise' },
        },

        logging =
        {
            level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is tested and OK
        },
    },

    execute = function(dz, item)
        local light = dz.devices('phoneLight') -- change to name of light

        if item.active and light.state == 'Off' then
            light.cancelQueuedCommands()
            light.switchOn()
            light.switchOff().afterMin(30) -- automatic switchOff after 30 minutes
        end
    end
}

Re: action when person arrives

Posted: Monday 06 July 2020 21:43
by loeknl
Thanks! Works perfect