Page 1 of 1

nighttime not working

Posted: Saturday 30 September 2017 18:52
by poudenes
Hi All,

In Domoticz i have my location so have a sunset and sunrise time in dashboard.
have this dzEvent script but it does not work its also running in daytime.
Can someone assist me?

Code: Select all

return {
    active = true,
    on = {
		timer = {'at nighttime'},
        devices = {'Keuken Sensor'}
    },
    execute = function(domoticz, device)

-- ALWAYS NIGHTTIME ONLY --
-- KITCHEN LIGHT OFF WHEN GONNA SLEEP	
    if
    domoticz.devices('Full Handmatige Modus').state == 'Off' and
    domoticz.devices('Scene Goodnight').state == 'On' and
    domoticz.devices('Keuken Sensor').state == 'Off' and 
    domoticz.devices('Kookplaat').state == 'On'
    then
        domoticz.devices('Kookplaat').switchOff().afterSec(3)
        domoticz.log('--==<[GOODNIGHT AAN KEUKEN LICHT UIT]>==--', domoticz.LOG_FORCE)

-- ALWAYS NIGHTTIME ONLY --
-- KITCHEN LIGHT ON WHEN KODI IS OFF	        
    elseif
    domoticz.devices('Keuken Sensor').state == 'On' and
    domoticz.devices('Kodi').state == 'Off' and
    domoticz.devices('Kookplaat').state == 'Off'
    then
        domoticz.devices('Kookplaat').switchOn().afterSec(1)
        domoticz.log('--==<[KEUKEN SENSOR AAN KEUKEN LICHT AAN]>==--', domoticz.LOG_FORCE)

-- ALWAYS NIGHTTIME ONLY --
-- KITCHEN LIGHT OFF WHEN KODI IS OFF 	        
    elseif 
    domoticz.devices('Keuken Sensor').state == 'Off' and
    domoticz.devices('Kookplaat').state == 'On' and
    domoticz.devices('Kodi').state == 'Off'
    then
        domoticz.devices('Kookplaat').switchOff().afterSec(1)
        domoticz.log('--==<[KEUKEN SENSOR UIT KEUKEN LICHT UIT]>==--', domoticz.LOG_FORCE)
        end
    end
}

Re: nighttime not working

Posted: Sunday 01 October 2017 18:45
by leby
Think it's because you also have

Code: Select all

devices = {'Keuken Sensor'}
as trigger, the script will trigger on change on this sensor if I have understood it correctly.

if you change to

Code: Select all

return {
    active = true,
    on = {
		timer = {'at nighttime'}
    },
    execute = function(domoticz, device)

-- ALWAYS NIGHTTIME ONLY --
-- KITCHEN LIGHT OFF WHEN GONNA SLEEP	
    if
    domoticz.devices('Full Handmatige Modus').state == 'Off' and
    domoticz.devices('Scene Goodnight').state == 'On' and
    domoticz.devices('Keuken Sensor').state == 'Off' and 
    domoticz.devices('Kookplaat').state == 'On'
    then
        domoticz.devices('Kookplaat').switchOff().afterSec(3)
        domoticz.log('--==<[GOODNIGHT AAN KEUKEN LICHT UIT]>==--', domoticz.LOG_FORCE)

-- ALWAYS NIGHTTIME ONLY --
-- KITCHEN LIGHT ON WHEN KODI IS OFF	        
    elseif
    domoticz.devices('Keuken Sensor').state == 'On' and
    domoticz.devices('Kodi').state == 'Off' and
    domoticz.devices('Kookplaat').state == 'Off'
    then
        domoticz.devices('Kookplaat').switchOn().afterSec(1)
        domoticz.log('--==<[KEUKEN SENSOR AAN KEUKEN LICHT AAN]>==--', domoticz.LOG_FORCE)

-- ALWAYS NIGHTTIME ONLY --
-- KITCHEN LIGHT OFF WHEN KODI IS OFF 	        
    elseif 
    domoticz.devices('Keuken Sensor').state == 'Off' and
    domoticz.devices('Kookplaat').state == 'On' and
    domoticz.devices('Kodi').state == 'Off'
    then
        domoticz.devices('Kookplaat').switchOff().afterSec(1)
        domoticz.log('--==<[KEUKEN SENSOR UIT KEUKEN LICHT UIT]>==--', domoticz.LOG_FORCE)
        end
    end
}
it should only trigger at night..

Re: nighttime not working

Posted: Sunday 01 October 2017 19:46
by dannybloe
You can restrict the device trigger to a time period as well:

Code: Select all

devices={ ['Keuken sensor'] ={'at nighttime'}]

Re: nighttime not working

Posted: Sunday 01 October 2017 20:56
by poudenes
Thanks both for the info.

So both are possible. 1 The whole execute at nighttime or specific on a device. Sounds interesting. Because i can combine some dzevent script now together.