Outdoor light at nighttime

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

Moderator: leecollings

Post Reply
jandirkv
Posts: 27
Joined: Monday 19 February 2018 6:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9117
Contact:

Outdoor light at nighttime

Post 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.
SweetPants

Re: Outdoor light at nighttime

Post by SweetPants »

Please put your code between code blocks to make it more readable
jandirkv
Posts: 27
Joined: Monday 19 February 2018 6:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9117
Contact:

Re: Outdoor light at nighttime

Post 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
}
NuNca
Posts: 4
Joined: Wednesday 07 June 2017 23:01
Target OS: NAS (Synology & others)
Domoticz version: beta
Contact:

Re: Outdoor light at nighttime

Post 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
jandirkv
Posts: 27
Joined: Monday 19 February 2018 6:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9117
Contact:

Re: Outdoor light at nighttime

Post 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'
NuNca
Posts: 4
Joined: Wednesday 07 June 2017 23:01
Target OS: NAS (Synology & others)
Domoticz version: beta
Contact:

Re: Outdoor light at nighttime

Post 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
}
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Outdoor light at nighttime

Post 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
}
jandirkv
Posts: 27
Joined: Monday 19 February 2018 6:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9117
Contact:

Re: Outdoor light at nighttime

Post 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.
jandirkv
Posts: 27
Joined: Monday 19 February 2018 6:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9117
Contact:

Re: Outdoor light at nighttime

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest