Page 1 of 1

Outdoor light at nighttime

Posted: Wednesday 28 February 2018 19:12
by jandirkv
Hello I'm new to DZvents scripting. I have Lots of VBA experience but I cant get the sintax right. I want a script that turns on my outdoor light 15 minutes before Sunset and 15 minutes after Sunset. But when I use Siri to turn off my lights when i go to bed and want de outdoor light to turn on again. I made the following script.

return {
on = {
timer = { 'every 1 minutes'}
},
execute = function(domoticz,timer)
if (domoticz.time > '30 minutes before sunset' and domoticz.time < '15 minutes after sunrise' and domoticz.devices('Lamp Buiten').state) == 'Off' then
domoticz.devices('Lamp Wand 1').switchSelector(55)
else
if (domoticz.time > '16 minutes after sunrise' and domoticz.time < '16 minutes before sunset' and domoticz.devices('Lamp Buiten').state) == 'On' then
domoticz.devices('Lamp Buiten').switchOff()
end
end
end
}

Domoticz log give the following error: attempt to compare string with table.

I would appreciatie the help.

Re: Outdoor light at nighttime

Posted: Wednesday 28 February 2018 21:49
by SweetPants
Please put your code between code blocks to make it more readable

Re: Outdoor light at nighttime

Posted: Wednesday 28 February 2018 22:17
by jandirkv

Code: Select all

return {
on = {
timer = { 'every 1 minutes'}
},
execute = function(domoticz,timer)
if (domoticz.time > '30 minutes before sunset' and domoticz.time < '15 minutes after sunrise' and domoticz.devices('Lamp Buiten').state) == 'Off' then
domoticz.devices('Lamp Wand 1').switchSelector(55)
else
if (domoticz.time > '16 minutes after sunrise' and domoticz.time < '16 minutes before sunset' and domoticz.devices('Lamp Buiten').state) == 'On' then
domoticz.devices('Lamp Buiten').switchOff()
end
end
end
}

Re: Outdoor light at nighttime

Posted: Wednesday 28 February 2018 23:43
by NuNca
jandirkv wrote: Wednesday 28 February 2018 22:17

Code: Select all

return {
on = {
timer = { 'every 1 minutes'}
},
execute = function(domoticz,timer)
if (domoticz.time > '30 minutes before sunset' and domoticz.time < '15 minutes after sunrise' and domoticz.devices('Lamp Buiten').state) == 'Off' then
domoticz.devices('Lamp Wand 1').switchSelector(55)
else
if (domoticz.time > '16 minutes after sunrise' and domoticz.time < '16 minutes before sunset' and domoticz.devices('Lamp Buiten').state) == 'On' then
domoticz.devices('Lamp Buiten').switchOff()
end
end
end
}
think the problem is that == 'Off' and == 'On' are outside the ).

try this.

Code: Select all

return {
	on = {
		timer = { 'every minute'}
		},
	execute = function(domoticz,timer)
		if (domoticz.time > '30 minutes before sunset' and domoticz.time < '15 minutes after sunrise' and domoticz.devices('Lamp Buiten').state == 'Off') then
			domoticz.devices('Lamp Wand 1').switchSelector(55)
		else
			if (domoticz.time > '16 minutes after sunrise' and domoticz.time < '16 minutes before sunset' and domoticz.devices('Lamp Buiten').state == 'On') then
				domoticz.devices('Lamp Buiten').switchOff()
			end
		end
end

Re: Outdoor light at nighttime

Posted: Thursday 01 March 2018 19:43
by jandirkv
Thank you for your help nunca. I tried your code but still no luck. Log still gives the following error: 'attempt to compare string with table'

Re: Outdoor light at nighttime

Posted: Thursday 01 March 2018 23:39
by NuNca
No problem, I didn't check the rest of the code. but the time rules don't seem to check out.

Here is another try, did test it and seems to work for me.

Code: Select all

return {
	on = {
		timer = { 'every minute'}
		},
	execute = function(domoticz,timer)
		if (domoticz.time.matchesRule('between 30 minutes before sunset and 15 minutes after sunrise') and domoticz.devices('Lamp Buiten').state == 'Off') then
			domoticz.devices('Lamp Wand 1').switchSelector(55)
		else
			if (domoticz.time.matchesRule('between 16 minutes after sunrise and 16 minutes before sunset') and domoticz.devices('Lamp Buiten').state == 'On') then
				domoticz.devices('Lamp Buiten').switchOff()
			end
		end
	end
}

Re: Outdoor light at nighttime

Posted: Friday 02 March 2018 7:38
by tlpeter
Try something like this (this is not a tested and used script so you need to fix it for your self!!!)

Code: Select all

return {
    active = true,
    on = {
        devices =   {'Keuken'}
    },
    execute = function(domoticz, roomSwitch)
        
        if
            (roomSwitch.state == 'On') then
                domoticz.devices('Keukenkastjes wit').dimTo(100)
        elseif
            (roomSwitch.state == 'Off') and (domoticz.time.matchesRule('at sunset-22:00')) then
                domoticz.devices('Keukenkastjes wit').dimTo(20)
        elseif
            (roomSwitch.state =='Off') and (domoticz.time.matchesRule('at 22:01-23:59')) then
                domoticz.devices('Keukenkastjes wit').dimTo(0)
        elseif
            (roomSwitch.state =='Off') and (domoticz.time.matchesRule('at 00:00-sunset')) then
                domoticz.devices('Keukenkastjes wit').dimTo(0)
                
        
        end
    end
}

Re: Outdoor light at nighttime

Posted: Saturday 03 March 2018 20:23
by jandirkv
NuNca wrote: Thursday 01 March 2018 23:39 No problem, I didn't check the rest of the code. but the time rules don't seem to check out.

Here is another try, did test it and seems to work for me.

Code: Select all

return {
	on = {
		timer = { 'every minute'}
		},
	execute = function(domoticz,timer)
		if (domoticz.time.matchesRule('between 30 minutes before sunset and 15 minutes after sunrise') and domoticz.devices('Lamp Buiten').state == 'Off') then
			domoticz.devices('Lamp Wand 1').switchSelector(55)
		else
			if (domoticz.time.matchesRule('between 16 minutes after sunrise and 16 minutes before sunset') and domoticz.devices('Lamp Buiten').state == 'On') then
				domoticz.devices('Lamp Buiten').switchOff()
			end
		end
	end
}
I tried it but it did not work for me. The outdoorlamp was not turned on this evening. I see you used the matchesrules Command. Is there a user manual besides the very limited one on the domoticz site where I can find commands like that.

Re: Outdoor light at nighttime

Posted: Wednesday 28 March 2018 20:45
by jandirkv
Thank you all for the help. I finally figured it out. I was running the stable version and that version had dzvents 2.2.0 which did not support the between rule. I update to the beta and now al my scripts work.