Reading thermostat value in lua

Moderator: leecollings

Post Reply
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Reading thermostat value in lua

Post by Thomasdc »

Hi!

I'm trying to configure my heating system to switch on and off with a certain hysteresis..

but i can't find out how that i need to read out the virtual thermostat value
i've tried so much allready..

this is the code at this moment:

Code: Select all

local Temperature = 'Temperatuur living'
local Temperature_SP = 'Thermostaat'
local Heating = 'KachelSP'
local AutoMode = 'HeatingAuto'

local Calc_Temperature = otherdevices[string.format('%s_Temperature', Temperature)]
local Calc_Temperature_SP = otherdevices[string.format('%s_Temperature', Temperature_SP)]
local Temp_Hys = 'TemperatuurHys'

commandArray = {}

Calc_TempHys = tonumber(uservariables[Temp_Hys])
Calc_Temperature = tonumber(Calc_Temperature)
Calc_Temperature_SP = tonumber(Calc_Temperature)


if otherdevices[AutoMode] == 'On' then
  if ( Calc_Temperature > (Calc_Temperature_SP + Calc_TempHys) ) then
     commandArray[Heating] = 'On'
     print('Auto Mode  Heating , Turned on Stove ')
    elseif ( Calc_Temperature < ( Calc_Temperature_SP - Calc_TempHys)) then
     commandArray[Heating] = 'Off'
     print('Auto Mode  Heating , Turned Off Stove ')
    end
end


return commandArray
can someone explain how this works:
otherdevices[string.format('%s_Temperature', Temperature_SP)] ?

it's something i found on an example but i dont really understand what it does..

any help is welcome!
Thanks!
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Reading thermostat value in lua

Post by freijn »

is
'Temperatuur living'

also the name of your theromostat?
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Reading thermostat value in lua

Post by Thomasdc »

freijn wrote: Thursday 09 November 2017 14:46 is
'Temperatuur living'

also the name of your theromostat?
'Temperatuur living' --> temperature sensor
'Thermostaat' --> the virtual thermostat
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Reading thermostat value in lua

Post by freijn »

ok

put a

print (otherdevices[string.format('%s_Temperature', Temperature_SP)])

and see what appears in the log file?

What are you seeing?
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Reading thermostat value in lua

Post by Thomasdc »

the only thing i see in the log file is this

Code: Select all

2017-11-09 18:45:00.316 Error: EventSystem: in KachelSp: [string " ..."]:21: attempt to perform arithmetic on local 'Calc_Temperature_SP' (a nil value)

the ' print (otherdevices[string.format('%s_Temperature', Temperature_SP)]) ' doesnt appear in the log,
(i did put it just under the line ' commandArray = {} '
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Reading thermostat value in lua

Post by freijn »

Can you move up the

commandArray = {}


So it becomes :

commandArray = {}
local Temperature = 'Temperatuur living'
local Temperature_SP = 'Thermostaat'
local Heating = 'KachelSP'
local AutoMode = 'HeatingAuto'


and try again ?
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Reading thermostat value in lua

Post by Thomasdc »

same error:
2017-11-10 18:24:00.308 Error: EventSystem: in KachelSp: [string " ..."]:23: attempt to perform arithmetic on local 'Calc_Temperature_SP' (a nil value)
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Reading thermostat value in lua

Post by Thomasdc »

Someone who can help me figure it out?

or someone who can share his script with me?
i'm sure there are a lot of you who uses a temperature sensor, virtual thermostat and a hysteresis to control the heating?

my biggest problem are:
How to read out the virtual thermostat (setpoint) and the temperature sensor.. (but i think that may allready work, the code only gives error on the thermostat value)

Thanks!
Thomasdc
Posts: 133
Joined: Wednesday 11 March 2015 19:13
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Reading thermostat value in lua

Post by Thomasdc »

for anyone wondering what i was doing wrong..

this is working:

Code: Select all

local Temperature = 'Temperatuur living'
local Temperature_SP = 'Thermostaat'
local Heating = 'KachelSP'
local AutoMode = 'HeatingAuto'

local Temp_Hys = 'TemperatuurHys'

commandArray = {} 

Calc_TempHys = tonumber(uservariables[Temp_Hys])


if otherdevices[AutoMode] == 'On' then
    
local iThermostatSetPoint = tonumber( otherdevices_svalues[Temperature_SP] )
local iTemperature = tonumber( otherdevices_svalues[Temperature])

   print('testing value'..iThermostatSetPoint)
   
  if ( iTemperature > (iThermostatSetPoint + Calc_TempHys) ) then
    commandArray[Heating] = 'Off'
     print('Auto Mode  Heating , Turned off Stove ')
    elseif ( iTemperature < (iThermostatSetPoint - Calc_TempHys)) then
     commandArray[Heating] = 'On'
     print('Auto Mode  Heating , Turned On Stove ')
   end
end


return commandArray
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest