Page 1 of 1

Lua script for switching when temp is high or low

Posted: Thursday 03 October 2019 11:52
by Matthiasfr
Hi all,

I'm using a netatmo weather station to monitor the temperature. When the temperature is below a certain threshold, the switches should go to 'on'. When the temperature is above a threshold, the switches should go 'off'. So I created this code. The state of the netatmo station is something like this '19.5;70;3;1012.5;7'. Therefor, I take the first three symbols of this string and convert this to a number. Unfortunately nothing is hapening. Someone an idea what's going wrong?

Code: Select all

commandArray = {}

if (devicechanged['Binnen']) then
--print('Temp is ' .. devicechanged_svalues['Binnen'])
temp = devicechanged['Binnen']
temp =  temp:sub( 1, 4 )
temp = tonumber(temp)

 if (temp < 25.0 and otherdevices['Zithoek'] == 'Off') then
  commandArray['Zithoek']='On'
  --print('Outside temperature is hot, switching fan on')
 end

end
return commandArray
Thanks in advance!

Re: Lua script for switching when temp is high or low

Posted: Thursday 03 October 2019 13:02
by waaren
Matthiasfr wrote: Thursday 03 October 2019 11:52 Someone an idea what's going wrong?
Try adding this directly beneath the commandArray = {} and watch the log to see what comes into your script.

Code: Select all

for key, value in pairs(devicechanged) do
      print ('Changed devices: ==>> key: ' ..  tostring(key) .. '; value: ==>>  ' .. tostring(value))
end

for key, value in pairs(otherdevices) do
      print ('Other devices: ==>> key: ' ..  tostring(key) .. '; value:  ==>> ' .. tostring(value))
end