Clock thermostat program in dzvents script

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

Moderator: leecollings

Post Reply
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Clock thermostat program in dzvents script

Post 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!
SweetPants

Re: Clock thermostat program in dzvents script

Post by SweetPants »

Should device.Anna.updateSetPoint(20) not be Anna.updateSetPoint(20) ?
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: Clock thermostat program in dzvents script

Post 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!
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: Clock thermostat program in dzvents script

Post 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.
SweetPants

Re: Clock thermostat program in dzvents script

Post 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.
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: Clock thermostat program in dzvents script

Post 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?
SweetPants

Re: Clock thermostat program in dzvents script

Post 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.
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: Clock thermostat program in dzvents script

Post 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.
SweetPants

Re: Clock thermostat program in dzvents script

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

Re: Clock thermostat program in dzvents script

Post 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
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
Denny64
Posts: 53
Joined: Friday 03 February 2017 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Italy
Contact:

Re: Clock thermostat program in dzvents script

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest