I'm starting coding in LUA, so sorry if my question is dumb.
I have window sensor xiaomi, temperature sensor xiaomi and Danfoss Living z-wave. I would like make a script:
- when window is closed and time from change status (from open to closed) is <5 min and temperature in room is <25 degrees then set temperautre 20 degrees on danfoss
- when window is opened and temperature in room is <25 degrees set temperature on danfoss to 5 degrees.
Basic script (below) is working:
Code: Select all
commandArray = {}
if (devicechanged['Sypialnia okno'] == 'Closed' and otherdevices['Sypialnia'] < '25')
then
commandArray [ 'SetSetPoint:43']='20' and print('Grzejnik 20 st')
elseif (otherdevices[ 'Sypialnia okno'] == 'Opened' and otherdevices[ 'Sypialnia']<'25')
then
commandArray [ 'SetSetPoint:43']='5' and print('Grzejnik 5 st')
end
return commandArray
Code: Select all
commandArray = {}
function timedifference(timestamp)
y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
return difference
end
local Sypialnia okno_changed = false
if (Sypialnia okno_changed ~= nil and devicechanged['Sypialnia okno']) then
mydevice_changed = true
end
s = otherdevices_lastupdate[ 'Sypialnia okno']
if (otherdevices[ 'Sypialnia okno'] == 'Closed' and timedifference (s) < 600 and not Sypialnia okno_changed and otherdevices[ 'Sypialnia']<'25')
then
commandArray [ 'SetSetPoint:43']='20' and print ("Grzejnik 20 st")
elseif (otherdevices[ 'Sypialnia okno'] == 'Opened' and otherdevices[ 'Sypialnia']<'25')
then
commandArray [ 'SetSetPoint:43']='5' and print("Grzejnik 5 st")
end
return commandArray
Danfoss in Domoticz is named: Sypialnia grzejnik and has idx 43
window sensor in Domoticz is named: Sypialnia okno
Thank You