Page 1 of 1
How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 16:36
by Quax1507
Hi,
I Need to set a thermostat temperature from a value stored in a user variable inside LUA.
Unfortunatelly I did not find anything in the documentation
Quax1507
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 17:59
by jvdz
Replace xxx with the idx of the thermostat and fill in the appropriate variable name:
Code: Select all
commandArray['UpdateDevice']='xxx|0|'..tostring(uservariables['variablename'])
Jos
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 18:06
by Quax1507
Great!
Thanky You!
Solved

Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 20:28
by MikeF
I set up a very simple lua script to test this:
Code: Select all
local idx = 40
commandArray = {}
commandArray['UpdateDevice']='40|0|'..tostring(uservariables['value'])
return commandArray
and I get the dreaded 'Error: EventSystem: Warning!, lua script ... has been running for more than 10 seconds'!
Also, is there a way to stop this script from repeating (i.e., run only once)? I have tried this in the past by setting a flag, without any success.
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 20:42
by jvdz
What did you name the script? something like script_device_xxxx.lua?
You really should have some if condition to only perform the device update when required or else the update is performed each time which triggers the script ...etc etc.
In case the thermostat only needs updating when a uservariable changes. the file should be named like script_variable_xxx.lua and look like:
Code: Select all
local idx = "40"
commandArray = {}
if uservariablechanged['value'] then
print("changing thermostat to:" .. tostring(uservariables['value']))
commandArray['UpdateDevice']=idx..'|0|'..tostring(uservariables['value'])
end
return commandArray
Jos
edit: added ) on print statement
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 21:20
by Quax1507
I tried the suggestions and I also get "has been running for more than 10 seconds."
I cannot use "script_variable". The reason for that is that I save the actual thermostat setpoint into a user variable when window is opened. After that I set the setpoint to 12 degress.
When window is closed, I restore the setpoint from user variable.
Why do I get this "10 second" error? Is the script repeated multiple times or does the setpont command take too much time?
Quax
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 21:28
by jvdz
What else do you have in your script? Running any commands with os.execute() or something like that?
Jos
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 21:31
by Quax1507
Nope.
Here is my script
Code: Select all
-----------------------
------ Variablen ------
-----------------------
local heizkoerper = 'Dummy' --Name des Heizkörpers
local fensterkontakt = 'Türkontakt nn'
commandArray = {}
if devicechanged[fensterkontakt]=='On' then
commandArray['Variable:Bad_Heizkörper_Ablage'] = otherdevices_svalues[heizkoerper]
commandArray[1]={['UpdateDevice']='159|0|12.0'}
elseif devicechanged[fensterkontakt]=='Off' then
commandArray['UpdateDevice']='159|0|' .. tostring(uservariables['Bad_Heizkörper_Ablage'])
end
return commandArray
Quax
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 21:46
by jvdz
Not sure as do not have that issue myself with the thermostat I use.
Do you know if the device 159 update line(s) case the issue?
If so, does that have any script attached to get it updated?
Jos
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 21:51
by Quax1507
What do You mean with "update line(s)" ?
There is no other script attached to this Thermostat. At the moment it is a virtual thermostat for testing purposes.
Issue occurs with the physical Thermostat, too.
Quax
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 22:13
by jvdz
Quick search found this thread which seems to be similar
http://www.domoticz.com/forum/viewtopic ... =20#p58597
Also a virtual thermostat giving the same 10 sec error.
Jos
Re: How do I set thermostat temperature from user variable?
Posted: Monday 04 January 2016 23:38
by MikeF
jvdz said:
What did you name the script? something like script_device_xxxx.lua?
Yes - I changed it to script_variable_xxxx.lua, and that stopped it repeating. (BTW: your example is missing a ')' at the end of the print statement.)
I still get the 'running for more than 10 seconds' warning, but it now works - thanks!