Page 1 of 1

Clock thermostat program in dzvents script

Posted: Friday 29 December 2017 11:55
by dk78
Hello all,

I'm trying to get a script working that replace my clock thermostat program on my Plugwise Anna thermostat and use Domoticz instead. This because I can add extra's like temperatures, 'someone home' or other switches. But I have some issues with the setpoint setting. I manage to get the thermostat switching between presets, but not temperatures.

This is my script for testing to set the setpoint on 20 degrees when it's manual set to something higher then 20 degrees:

Code: Select all

return {
   on = {
      timer = { 'every minute'}
	},
	active = true,
	execute = function(domoticz, device, triggerInfo)

        local Anna = domoticz.devices('Anna-kachel')    -- plugwise Anna thermostaat
        local temp = domoticz.devices('Woonkamer')      -- plugwise Anna temperatuur

        local setpointValue = tonumber(Anna.state)
        
    	if setpointValue >= 20.5 then
			domoticz.log('De thermostaat stond ingesteld op:' .. setpointValue)
			device.Anna.updateSetPoint(20)
			domoticz.log('De thermostaat staat nu ingesteld op:' .. setpointValue)
		end
    end
}
}
Error logging:
2017-12-29 11:50:00.221 dzVents: Info: ------ Start internal script: Test-Anna:, trigger: every minute
2017-12-29 11:50:00.224 dzVents: Info: De thermostaat stond ingesteld op:21
2017-12-29 11:50:00.224 Error: dzVents: Error: An error occured when calling event handler Test-Anna
2017-12-29 11:50:00.224 Error: dzVents: Error: ...domoticz/scripts/dzVents/generated_scripts/Test-Anna.lua:15: attempt to index local 'device' (a nil value)
2017-12-29 11:50:00.224 dzVents: Info: ------ Finished Test-Anna
What am I doing wrong?

Also when I adjust the setpoint manually with Domoticz, it adjust on the thermostat, but in the logging this appears:
2017-12-29 11:49:29.485 Error: AnnaThermostat: Error getting current state!

Re: Clock thermostat program in dzvents script

Posted: Friday 29 December 2017 12:05
by SweetPants
Should device.Anna.updateSetPoint(20) not be Anna.updateSetPoint(20) ?

Re: Clock thermostat program in dzvents script

Posted: Friday 29 December 2017 12:14
by dk78
SweetPants wrote: Friday 29 December 2017 12:05 Should device.Anna.updateSetPoint(20) not be Anna.updateSetPoint(20) ?
:o I hope that everything is this easy :lol: Thanks!

Re: Clock thermostat program in dzvents script

Posted: Saturday 30 December 2017 10:33
by dk78
Should this work:

Code: Select all

		if (triggerInfo.trigger == 'at 22:20-22:25 on sat,sun,mon,tue,wed,thu,fri') and setpointValue ~= 16 then
			Anna.updateSetPoint(16)
I think I miss something because the triggerinfo won't trigger.

Re: Clock thermostat program in dzvents script

Posted: Saturday 30 December 2017 10:40
by SweetPants
I don't think this is gonna work.
Why not set the 'on timer' to 'at 22:20-22:25 on sat,sun,mon,tue,wed,thu,fri' then the script fires and check the setpointvalue in the script and do your thing.

Re: Clock thermostat program in dzvents script

Posted: Saturday 30 December 2017 10:45
by dk78
Because I need on different time, different setpoint. So I thought when I trigger every minute, I can use the triggerinfo to see when the script is triggered to set the correct setpoint. I'm not sure how I can solve this when I do it with the 'on timer'.

I want to set the temperature in the morning on 18 degrees, in the evening at 20 and during the night back to 16. Also during the day when nobody is home.

Or do I create separated scripts for every time trigger?

Re: Clock thermostat program in dzvents script

Posted: Saturday 30 December 2017 11:18
by SweetPants
When I read the Wiki, the 'triggerinfo.trigger' must be one of your 'on timer' rules (there can be multiple). I have not checked it, but maybe you can give it a try.

Re: Clock thermostat program in dzvents script

Posted: Saturday 30 December 2017 12:20
by dk78
I've tested some options and think now what I'm doing wrong. When you put 'every minute' in your 'on timer' options on top, that's always the one that triggers the script. When you place it down, it only gets triggered when the others are not. Then it works for me.

Re: Clock thermostat program in dzvents script

Posted: Saturday 30 December 2017 12:32
by SweetPants
dk78 wrote: Saturday 30 December 2017 12:20 I've tested some options and think now what I'm doing wrong. When you put 'every minute' in your 'on timer' options on top, that's always the one that triggers the script. When you place it down, it only gets triggered when the others are not. Then it works for me.
Glad to hear it works

Re: Clock thermostat program in dzvents script

Posted: Wednesday 03 January 2018 9:00
by dannybloe
You can use the matchesRule on the Time object. You can apply any timer rule in that function:

Code: Select all

if (domoticz.time.matchesRule('at 22:20-22:25 on sat,sun,mon,tue,wed,thu,fri') then
end

Re: Clock thermostat program in dzvents script

Posted: Wednesday 03 January 2018 10:57
by Denny64
Look at this thread...

http://www.domoticz.com/forum/viewtopic ... ng#p162368

I think you can do what you desire in a simple way.