Switches don't switch on

Moderator: leecollings

Post Reply
virtualite
Posts: 3
Joined: Monday 30 October 2017 18:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Switches don't switch on

Post by virtualite »

Dear Domoticz users,

I'v some problems with my first LUA script. Below i placed 2 parts of my script (i believe those are wrong) and complete script. Can you guys help me to fix the problems? No errors appears, but script is only working for a small part.

Code: Select all

if (otherdevices['Alarm'] == 'On') then
    if (otherdevices['Alarm Trigger'] == 'Off' and otherdevices['Eetkamerdeur'] == 'On' or otherdevices['Voordeur'] == 'On' or otherdevices['Keukendeur'] == 'On' or otherdevices['Woonkamer PIR'] == 'On') then
        commandArray['Alarm Trigger']='On'
    end

Code: Select all

elseif (timedifference(otherdevices_lastupdate['Alarm Trigger']) > 45 and otherdevices['Alarm Trigger'] == 'On' and otherdevices['Alarm'] == 'On') then
        commandArray['Alarm Switch']='On'
Below the complete LUA script

Code: Select all

time = os.date("*t")
function timedifference (s)
    year = string.sub(s, 1, 4)
    month = string.sub(s, 6, 7)
    day = string.sub(s, 9, 10)
    hour = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)
    t1 = os.time()
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    difference = os.difftime (t1, t2)
    return difference
end

commandArray = {}
-- Controle methodiek t.b.v. openstaande deuren of beweging
if (otherdevices['Alarm'] == 'On') then
    if (otherdevices['Alarm Trigger'] == 'Off' and otherdevices['Eetkamerdeur'] == 'On' or otherdevices['Voordeur'] == 'On' or otherdevices['Keukendeur'] == 'On' or otherdevices['Woonkamer PIR'] == 'On') then
        commandArray['Alarm Trigger']='On'
    end
-- Alarm activeren als aan voorwaarden wordt voldaan    
elseif (timedifference(otherdevices_lastupdate['Alarm Trigger']) > 45 and otherdevices['Alarm Trigger'] == 'On' and otherdevices['Alarm'] == 'On') then
        commandArray['Alarm Switch']='On'
-- Alarm deactiveren als aan voorwaarden wordt voldaan
elseif (otherdevices['Alarm Trigger'] == 'On' and otherdevices['Alarm'] == 'Off') then
        commandArray['Alarm Trigger']='Off'
end
return commandArray
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest