dzVents has me stumped - simple logic switch on/off

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

Moderator: leecollings

Post Reply
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

dzVents has me stumped - simple logic switch on/off

Post 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
}
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post 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
}
The most dangerous phrase in any language is:
"We always done this way"
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

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

Post 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
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

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

Post by dannybloe »

Yes, the last one is how you 'should' do it. That's what the triggerInfo was intended for.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post by emme »

uh... trigger info.....

...my fault :P :P
The most dangerous phrase in any language is:
"We always done this way"
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

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

Post 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!
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

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

Post by dannybloe »

Good luck and let’s make it ours. Not just mine.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest