How do I set thermostat temperature from user variable?

Moderator: leecollings

Post Reply
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

How do I set thermostat temperature from user variable?

Post 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
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How do I set thermostat temperature from user variable?

Post by Quax1507 »

Great!
Thanky You!

Solved :-)
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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.
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
Last edited by jvdz on Tuesday 05 January 2016 9:21, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How do I set thermostat temperature from user variable?

Post by jvdz »

What else do you have in your script? Running any commands with os.execute() or something like that?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How do I set thermostat temperature from user variable?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: How do I set thermostat temperature from user variable?

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

Who is online

Users browsing this forum: No registered users and 1 guest