Page 1 of 1

Scheduling with dzVents

Posted: Tuesday 07 November 2017 21:29
by DannyElfman
Hi guys,

First, thanks again for these great tools (Domoticz+dzVents) !

I am not a coder. At all. Or I am the worst ever :)
But I try.
I have read the wiki in all directions and I lack some info (and scripting skills obviously).

I am building a script to switch on a device (zwave relay controlling my heating device) depending on the temperature. That I managed :)

And I want it on during specific period of the day. I did manage that part as well.

But, with my script, if the device is switched on 1 minute before the active timeframe ends, it will never be switched of ...

So I wanted to have a condition on the temperature and on the time but I just cannot figure it out ...

I went though this part of the wiki (https://www.domoticz.com/wiki/DzVents:_ ... ime_object) many times but I do not get it.

To be honest, I am not even capable to print in the log any value for domoticz.time

And I am not even sure this is the best way to go when I think about it ...

I ended up with switching the device to a non heating status using the timers button ....

Here is the disaster :

Code: Select all

return {

	active = true, 

	on = {
		timer = {
		    
			'every 10 minutes between 05:50 and 08:00',
			'every 10 minutes between 19:00 and 21:00'
		},
			},
	
	execute = function(domoticz, device)
			
		local sdbtemp = domoticz.devices(623) -- sdb temp
		local relais1 = domoticz.devices(236) -- sdb relais 1 mode confort si OFF et relais 2 off aussi
		local relais2 = domoticz.devices(243) -- relais 2 - toujours off.
		
		if (sdbtemp.temperature < 20 ) then
			relais1.switchOff()
			relais2.switchOff()
			domoticz.notify('Chauffage Sdb en mode confort')
		else  
		    relais1.switchOn()
		    relais2.switchOff()
		end
	end
}

Re: Scheduling with dzVents

Posted: Wednesday 08 November 2017 13:12
by BakSeeDaa
It's not tested and with reservation for that I've understood the problem correctly, maybe you can try something like this:

Code: Select all

return {
	active = true,
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = "sdb"
	},
	on = {
		timer = {
			'every 10 minutes between 05:50 and 08:00',
			'every 10 minutes between 19:00 and 21:00',
			'every 10 minutes',
		},
	},

	execute = function(domoticz, device, triggerInfo)

		local sdbtemp = domoticz.devices(623) -- sdb temp
		local relais1 = domoticz.devices(236) -- sdb relais 1 mode confort si OFF et relais 2 off aussi
		local relais2 = domoticz.devices(243) -- relais 2 - toujours off.

		if relais2.state == 'On' then relais2.switchOff() end

		domoticz.log('sdbtemp.temperature: '..tostring(sdbtemp.temperature), domoticz.LOG_DEBUG)
		domoticz.log('triggerInfo.trigger: '..triggerInfo.trigger, domoticz.LOG_DEBUG)

		local newState = 'On'

		if (sdbtemp.temperature < 20)
		or (triggerInfo.trigger == 'every 10 minutes') then
			newState = 'Off'
		end

		if relais1.state ~= newState then
			domoticz.log('Switching relais1 to: '..newState, domoticz.LOG_DEBUG)
			relais1.setState(newState)
			if newState == 'Off' then domoticz.notify('Chauffage Sdb en mode confort') end
		end
	end
}

Re: Scheduling with dzVents

Posted: Wednesday 08 November 2017 16:27
by DannyElfman
Oops, I did not get any notification :p

First , thanks a lot for taking the time. I mean, A LOT !
Second, I of course understand it cannot be tested, no worries :) . I'm glad I have help so :)
Third, it is difficult for me to explain something which is not that clear so kudos to you if you go my point ^^

I will check it asap, and will come back with my findings.

Re: Scheduling with dzVents

Posted: Thursday 09 November 2017 17:01
by arkoko
I think there overkill in proposed trigger condition:

Code: Select all

'every 10 minutes between 05:50 and 08:00',
'every 10 minutes between 19:00 and 21:00',
'every 10 minutes',
The last line makes first two useless.

Re: Scheduling with dzVents

Posted: Thursday 09 November 2017 17:28
by BakSeeDaa
arkoko wrote: Thursday 09 November 2017 17:01 I think there overkill in proposed trigger condition:

Code: Select all

'every 10 minutes between 05:50 and 08:00',
'every 10 minutes between 19:00 and 21:00',
'every 10 minutes',
The last line makes first two useless.
Not really.
The documentation wrote:dzVents lists the first timer definition that matches the current time. If there are more timer triggers that could have been triggering the script, dzVents only picks the first for this trigger property.
So,

Code: Select all

(triggerInfo.trigger == 'every 10 minutes')
will be true if none of the previously defined triggers has triggered. (E.g. it tells us that we are not within the specified time intervals and that will lead to setting the state of relais1 to 'Off')

Re: Scheduling with dzVents

Posted: Thursday 09 November 2017 20:08
by DannyElfman
Yep, that is how I understood it. But i did not get the time to put it in place yet. I will of course and will come back here to report :)

Re: Scheduling with dzVents

Posted: Thursday 09 November 2017 20:42
by arkoko
Oh, I see ... I didn't notice usage of trigger info ((triggerInfo.trigger) in the script body.
Sorry.