Using a variable as a setpoint?

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

Moderator: leecollings

Post Reply
freakshock
Posts: 64
Joined: Friday 14 April 2017 13:39
Target OS: NAS (Synology & others)
Domoticz version:
Location: The Netherlands
Contact:

Using a variable as a setpoint?

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

Re: Using a variable as a setpoint?

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
freakshock
Posts: 64
Joined: Friday 14 April 2017 13:39
Target OS: NAS (Synology & others)
Domoticz version:
Location: The Netherlands
Contact:

Re: Using a variable as a setpoint?

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

Re: Using a variable as a setpoint?

Post by dannybloe »

I don't know what you mean with 'sleep mode'.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: Using a variable as a setpoint?

Post 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
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
CeesCKS
Posts: 7
Joined: Monday 15 January 2018 14:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11474
Location: Woerden, Netherlands
Contact:

Re: Using a variable as a setpoint?

Post 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
Cees
freakshock
Posts: 64
Joined: Friday 14 April 2017 13:39
Target OS: NAS (Synology & others)
Domoticz version:
Location: The Netherlands
Contact:

Re: Using a variable as a setpoint?

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

Re: Using a variable as a setpoint?

Post 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
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
freakshock
Posts: 64
Joined: Friday 14 April 2017 13:39
Target OS: NAS (Synology & others)
Domoticz version:
Location: The Netherlands
Contact:

Re: Using a variable as a setpoint?

Post by freakshock »

Great that works! Thanks Danny :D
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 1 guest