Page 1 of 1

dzVents has me stumped - simple logic switch on/off

Posted: Sunday 22 October 2017 18:18
by rjblake
I've just take a look at using dzVents; but I'm missing something in my logic of how it works. For example, I'm trying to create a simple script to turn on a switch 10 minutes after sunset and turn off 10 minutes before sunrise. I think I have it working as 2 separate scripts; but surely I can create the logic in a single script? I'm sure it can be done; but for some reason my brain is malfunctioning today...Any tips?

Switch ON

Code: Select all

return {
    active = true,
    on = {
        timer = {
            '10 minutes after sunset',
        },
    },
    execute = function(domoticz, devices)
        
            domoticz.devices('Switch [WS01]').switchOn().checkFirst()
        
    end
}
Switch OFF

Code: Select all

return {
    active = true,
    on = {
        timer = {
            '10 minutes before sunrise',
        },
    },
    execute = function(domoticz, devices)
        
            domoticz.devices('Switch [WS01]').switchOff().checkFirst()
        
    end
}

Re: dzVents has me stumped - simple logic switch on/off

Posted: Sunday 22 October 2017 18:53
by emme
since sunrise and sunset are in the morning and in the afternoon, I would use AM or PM from the time/date object?
mine is just a guess.... :P
ciao
M

Code: Select all

return {
    active = true,
    on = {
        timer = {
            '10 minutes after sunset',
            '10 minutes before sunrise'
        },
    },
    execute = function(domoticz, devices)
            if os.date("%p") == 'AM' then  --sunrise
                domoticz.devices('Switch [WS01]').switchOff().checkFirst()
            else
                domoticz.devices('Switch [WS01]').switchOn().checkFirst()
            end
    end
}

Re: dzVents has me stumped - simple logic switch on/off

Posted: Sunday 22 October 2017 20:51
by rjblake
emme wrote: Sunday 22 October 2017 18:53 since sunrise and sunset are in the morning and in the afternoon, I would use AM or PM from the time/date object?
mine is just a guess.... :P
ciao
M

Code: Select all

return {
    active = true,
    on = {
        timer = {
            '10 minutes after sunset',
            '10 minutes before sunrise'
        },
    },
    execute = function(domoticz, devices)
            if os.date("%p") == 'AM' then  --sunrise
                domoticz.devices('Switch [WS01]').switchOff().checkFirst()
            else
                domoticz.devices('Switch [WS01]').switchOn().checkFirst()
            end
    end
}
Thanks for that - In the end, I think I've not gotten my brain back in gear some. I've applied the following code (tested based on 'at 19:00' type logic) which is working

Code: Select all

return {
	active = true,
	on = {
	    timer = {
	        '10 minutes after sunset', 
	        '10 minutes before sunrise'
	        },
	    },
	
	execute = function(domoticz, myDevice, triggerInfo)
		local myDevice = domoticz.devices('Switch [WS01]')

		if (triggerInfo.trigger == '10 minutes after sunset') then
		    myDevice.switchOn().checkFirst()
		elseif  (triggerInfo.trigger == '10 minutes before sunrise') then
		    myDevice.switchOff().checkFirst()
		end
	end
}

Re: dzVents has me stumped - simple logic switch on/off

Posted: Monday 23 October 2017 8:53
by dannybloe
Yes, the last one is how you 'should' do it. That's what the triggerInfo was intended for.

Re: dzVents has me stumped - simple logic switch on/off

Posted: Monday 23 October 2017 9:18
by emme
uh... trigger info.....

...my fault :P :P

Re: dzVents has me stumped - simple logic switch on/off

Posted: Monday 23 October 2017 20:13
by rjblake
dannybloe wrote: Monday 23 October 2017 8:53 Yes, the last one is how you 'should' do it. That's what the triggerInfo was intended for.
Yeah - finally got a better understanding of your dzVents (at least a basic level). Thanks for creating this awesome addition - now to look to convert my other LUA, PHP and Python scripts all to dzVents - nice winter project!

Re: dzVents has me stumped - simple logic switch on/off

Posted: Monday 23 October 2017 21:52
by dannybloe
Good luck and let’s make it ours. Not just mine.