Page 1 of 1

Using a variable as a setpoint?

Posted: Tuesday 09 January 2018 15:54
by freakshock
Hi all,

I would like to use a Domoticz uservariable as a setpoint for my thermostat.
I can't seem to find the correct syntax for this in the wiki.
Right now my thermostat always changes to the same hardcoded value:

Code: Select all

domoticz.devices('Thermostat').updateSetPoint(17)
But I would like it to change to whatever is in the uservariable 'Nighttemp'.

Can anyone help me with the correct syntax for dzVents?

Re: Using a variable as a setpoint?

Posted: Tuesday 09 January 2018 16:06
by dannybloe

Code: Select all

return {
	on = {
		variables = { 'MySetpointVar' } -- integer variable
	},
	execute = function(domoticz, variable)
		domoticz.devices('Thermostat').updateSetPoint(variable.value) 
	end
}
This script will make sure that whenever you edit the variable in the GUI, the setpoint is updated.

Re: Using a variable as a setpoint?

Posted: Tuesday 16 January 2018 14:46
by freakshock
Thanks for your suggestion Danny, your script works for when I want the change in the variable to directly change the setpoint.
However, I want to be able to choose the setpoint for the coming night, when my domoticz goes into 'sleep mode'.
Is this also possible?

Re: Using a variable as a setpoint?

Posted: Tuesday 16 January 2018 14:51
by dannybloe
I don't know what you mean with 'sleep mode'.

Re: Using a variable as a setpoint?

Posted: Tuesday 16 January 2018 15:13
by JuanUil
Hi
I am using this in my ICY Thermostat.

Code: Select all

-- Temperatuur instellingen
dagtemperatuur   = uservariables["dagtemperatuur"]
nachttemperatuur = uservariables["nachttemperatuur"]
vorstbeveiliging = uservariables["vorstbeveiliging"]

Code: Select all

-- Dagtemperatuur instellen voor werkdagen en weekend
	if (werkweek and dag ~= 'Sun'and uur==7 and min>=0 and min<2 and setpoint<dagtemperatuur) then
		setpoint=dagtemperatuur
		set = "6|0|" .. setpoint
		commandArray ['UpdateDevice']= '6|0|' .. setpoint  
	elseif ((weekend or dag=='Sun')and uur==8 and min>=0 and min<2 and setpoint<dagtemperatuur) then
		setpoint=dagtemperatuur
		set = "6|0|" .. setpoint
		commandArray ['UpdateDevice']= '6|0|' .. setpoint  
	end

Re: Using a variable as a setpoint?

Posted: Tuesday 16 January 2018 15:23
by CeesCKS
Hi,

Did you consider to use the "Timers" option from the Thermostat device to change the setpoint value at a given time stamp without programming any code.

Cees

Re: Using a variable as a setpoint?

Posted: Tuesday 16 January 2018 20:27
by freakshock
@ Danny,

Sleep mode is just a simple dummy switch I use to switch off my devices for the night, and also to lower the thermostat setpoint.
What I want to be able to do in this case, is to set a variable setpoint, so I can choose the setpoint setting for the coming night in advance.

This is part of my current script for my 'sleep mode':

Code: Select all

return {

	on = {
		devices = {
			
			'Sleepmode'},
	
		
	execute = function(domoticz) 
	
		if (domoticz.devices('Sleepmode').state == 'On' then 
		
		    domoticz.devices('LivingRoomLight').switchOff()
		    domoticz.devices('Thermostaat').updateSetPoint(17) --[b] I want to set this to a uservariable 'Night_temp[/b]'
How would that look like in dzVents code? Thanks for your patience !

Re: Using a variable as a setpoint?

Posted: Wednesday 17 January 2018 8:55
by dannybloe
Then it's probably something like this:

Code: Select all

return {
	on = {
		devices = { 'Sleepmode' },
	},		
	execute = function(domoticz) 
		if (domoticz.devices('Sleepmode').state == 'On' then 
			domoticz.devices('LivingRoomLight').switchOff()
			local nightTimeSetpoint = domoticz.variables('Night_temp').value
		   	domoticz.devices('Thermostaat').updateSetPoint(nightTimeSetpoint) 
		 end
	end
}

Re: Using a variable as a setpoint?

Posted: Friday 19 January 2018 10:52
by freakshock
Great that works! Thanks Danny :D