Lua script for switching when temp is high or low

Moderator: leecollings

Post Reply
Matthiasfr
Posts: 17
Joined: Saturday 10 August 2019 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua script for switching when temp is high or low

Post 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!
Attachments
Knipsel2.PNG
Knipsel2.PNG (99.76 KiB) Viewed 1077 times
Knipsel.PNG
Knipsel.PNG (50.06 KiB) Viewed 1077 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest