random on / random duration

Moderator: leecollings

Post Reply
mash47
Posts: 13
Joined: Wednesday 04 December 2019 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.10717
Location: Sheffield, UK
Contact:

random on / random duration

Post by mash47 »

dzVents allows randomised switch times using withinMin(minutes) etc but I've been unable to find anything in dzVents for a randomised duration. Here's the code to operate a switch with random on times and random duration ...

Code: Select all

return {
	on = {
	    timer = {'every 30 minutes'}
	},
	execute = function(dz)
	    local n = tostring(math.random(5, 15))
	    if( dz.time.matchesRule('between sunset and 23:00') ) then
	        dz.devices(15).switchOn().withinMin(15).forMin(n)
	    end
  	end
}
imdos
Posts: 34
Joined: Thursday 03 August 2017 21:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: random on / random duration

Post by imdos »

Well; as you have already found. The randomised duration is within! There is: withinMin(minutes); this enables to switch off or on within a random time.

But I guess it might influence too much with your current idea.

If you have:

Code: Select all

dz.devices(15).switchOn().withinMin(15)
dz.devices(15).switchOff().withinMin(15)
This might already switch off the light before the switch on.
Making use of: Raspbian(SSD), dz Beta, Woonveilig, Z-Wave(alarm+multi-sensor), RFLink(blinds), P1, Yeelight, Xiaomi temp sensors, Tasmota(SonoFF, Blitzwolf SHP2, Shelly1)
mash47
Posts: 13
Joined: Wednesday 04 December 2019 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.10717
Location: Sheffield, UK
Contact:

Re: random on / random duration

Post by mash47 »

imdos wrote: Thursday 19 December 2019 11:38 If you have:

Code: Select all

dz.devices(15).switchOn().withinMin(15)
dz.devices(15).switchOff().withinMin(15)
This might already switch off the light before the switch on.
Yes I agree, that is why I used the math.random(n, m) function to ensure that the randomised duration was applied after the switch had been turned on. It also has the advantage of being able to specify a minimum duration.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest