Page 1 of 1

beginner question

Posted: Wednesday 29 January 2020 1:23
by adval40
I started with dzvents since 2 days.
I want to switch a device with 'between 00:47 and 00:48',
this is of course an example

Code: Select all


return {
	on = {
		timer = {

		    'between 00:47 and 00:48' ,                                                          
	            },
         },
	execute = function(domoticz, timer)
	    domoticz.devices('Printer voorkamer')   .switchOn()
	end
       }

the .switchOn () command is wrong I don't know what the correct command is
thank you in advance

Re: beginner question

Posted: Wednesday 29 January 2020 6:48
by besix
Hello
switchOn command is Ok
only in execute you have to say when it should be On

Code: Select all

return {
	on = {
		timer = {

		    'between 00:47 and 00:48'                                                           
	            },
         },
	execute = function(domoticz, timer)
	    if domoticz.time.matchesRule('between 00:47 and 00:48') then
	    domoticz.devices( ' Printer voorkamer ' ).switchOn()
    end
end
} 

Re: beginner question

Posted: Wednesday 29 January 2020 8:32
by salvacalatayud
Why don't just put a timer to the switch instead? It is easy and you don't need any coding

Enviado desde mi Mi A2 mediante Tapatalk


Re: beginner question

Posted: Wednesday 29 January 2020 8:38
by waaren
adval40 wrote: Wednesday 29 January 2020 1:23 I want to switch a device with 'between 00:47 and 00:48',
the .switchOn () command is wrong I don't know what the correct command is
The switchOn() method is ok but you have spaces before .switchOn() that should not be there. Try this one.

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            'at 08:31-08:33',
        },
    },

    execute = function(dz)
        dz.devices('Printer voorkamer').switchOn()
    end
}

Re: beginner question

Posted: Wednesday 29 January 2020 8:41
by waaren
besix wrote: Wednesday 29 January 2020 6:48 switchOn command is Ok
only in execute you have to say when it should be On
I am sorry but no. In this script the matchesRule does not add any value. The script will only be executed 'at 00:47-00:48' so the matchesRule will always evaluate to true.