Page 1 of 1

Christmas light by program

Posted: Tuesday 02 January 2024 17:19
by ssk17051980
I keep trying to make a script even with the help of chat-open-ai, but without success.
my script must turn on a switch, with idx=x, in the period 01.12 - 05.01, for a period of 8 hours, IF another switch with idx=y, is ON.
it is about Christmas lights, and idx=y is a switch that is ON when the sun goes down.
Does anyone have something like this already done and working?

Thank you

Re: Christmas light by program

Posted: Tuesday 02 January 2024 19:09
by willemd
Not sure if this timer works, please go ahead and test it.

Alternatively you just could use the "at sunrise" or "at sunset" trigger, then you don't need to check the y switch.

Code: Select all

local idxSunDownSwitch=y 
local idxLightsSwitch=x 

return {
	on = {
		timer {
		    'every minute on 01/12-05/01',
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'christmas light',
	},
	execute = function(domoticz, timer)
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
		if domoticz.devices(idxSunDownSwitch).state=='ON' then
		    if domoticz.devices(idxLightsSwitch).state=='OFF' then
		       domoticz.devices(idxLightsSwitch).switchOn()
	        end 
		else
		    if domoticz.devices(idxLightsSwitch).state=='ON' then
		       domoticz.devices(idxLightsSwitch).switchOff()
		    end     
		end    
	end
}

Re: Christmas light by program

Posted: Wednesday 03 January 2024 8:49
by gizmocuz
Indded, why not add a timer to your Cristmas light to go on 30 minutes before sunset ?

Re: Christmas light by program

Posted: Wednesday 03 January 2024 13:22
by ssk17051980
willemd wrote: Tuesday 02 January 2024 19:09 Not sure if this timer works, please go ahead and test it.

Alternatively you just could use the "at sunrise" or "at sunset" trigger, then you don't need to check the y switch.

Code: Select all

local idxSunDownSwitch=y 
local idxLightsSwitch=x 

return {
	on = {
		timer {
		    'every minute on 01/12-05/01',
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'christmas light',
	},
	execute = function(domoticz, timer)
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
		if domoticz.devices(idxSunDownSwitch).state=='ON' then
		    if domoticz.devices(idxLightsSwitch).state=='OFF' then
		       domoticz.devices(idxLightsSwitch).switchOn()
	        end 
		else
		    if domoticz.devices(idxLightsSwitch).state=='ON' then
		       domoticz.devices(idxLightsSwitch).switchOff()
		    end     
		end    
	end
}
gone test :D

thx

Re: Christmas light by program

Posted: Wednesday 03 January 2024 13:23
by ssk17051980
gizmocuz wrote: Wednesday 03 January 2024 8:49 Indded, why not add a timer to your Cristmas light to go on 30 minutes before sunset ?
i want to be ON in a specific interval

Re: Christmas light by program

Posted: Wednesday 03 January 2024 13:53
by willemd
Exactly, that's what he meant: go ON xx minutes before or after sunset, go OFF xx minutes before or after sunrise.

Reading the dzVents documentation will help

Re: Christmas light by program

Posted: Wednesday 03 January 2024 17:11
by waltervl
willemd wrote: Wednesday 03 January 2024 13:53 Exactly, that's what he meant: go ON xx minutes before or after sunset, go OFF xx minutes before or after sunrise.

Reading the dzVents documentation will help
You can do this with the normal timer function/button too, no need to program something.

Re: Christmas light by program

Posted: Thursday 04 January 2024 21:09
by ssk17051980

Code: Select all

local idxSunDownSwitch = 267  --indicate the sunrise and sunset /apus (ON/OFF) 
local idxLightsSwitch = 23    -- the switch that i want to control (ON/OFF)

return {
    on = {
        timer = {
            'every minute on 12/01-01/05',
        }
    },
    logging = {
        level = domoticz.LOG_INFO,
        marker = 'christmas light',
    },
    execute = function(domoticz, timer)
        domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)

        local sunDownSwitch = domoticz.devices(idxSunDownSwitch)
        local lightsSwitch = domoticz.devices(idxLightsSwitch)

        if sunDownSwitch.state == 'ON' then
            if lightsSwitch.state == 'OFF' then
                lightsSwitch.switchOn()
            end
        else
            if lightsSwitch.state == 'ON' then
                lightsSwitch.switchOff()
            end
        end
    end
}
not working

Re: Christmas light by program

Posted: Thursday 04 January 2024 23:30
by willemd
If you want help you need to provide some more feedback and info.
I tested the timer trigger and see my script is launched every minute, so that is not the problem.
Is yours launched as well? Is it activated?
Any error messages?
Any info in the log file?
Did you add debug info so that it is shown in the logfile?

Re: Christmas light by program

Posted: Thursday 11 January 2024 8:47
by ssk17051980
it's working in this form.
I have to change the interval now.
1 Dec - 10 January

Code: Select all

return {
    on = {
        timer = { 'daily' },
        devices = { 267 } -- Se activează și la schimbările de stare ale switch-ului cu idx-ul 267
    },
    execute = function(dz)
        local currentDate = os.date('*t')
        local switchIdxToControl = 23
        local requiredSwitchIdx = 267

        -- Verificăm dacă switch-ul cu idx-ul 267 este ON
        local requiredSwitchState = dz.devices(requiredSwitchIdx).state
        if requiredSwitchState == 'On' then
            -- Dacă suntem în decembrie sau ianuarie, pornim switch-ul cu idx-ul 23
            if currentDate.month == 12 or currentDate.month == 1 then
                dz.devices(switchIdxToControl).switchOn()
            else
                -- În orice altă lună, oprim switch-ul cu idx-ul 23
                dz.devices(switchIdxToControl).switchOff()
            end
        else
            -- Dacă switch-ul cu idx-ul 267 nu este ON, asigurăm că switch-ul cu idx-ul 23 este oprit
            dz.devices(switchIdxToControl).switchOff()
        end
    end
}