Help needed -- lua script on Synology

Moderator: leecollings

Post Reply
steef84
Posts: 37
Joined: Friday 30 August 2013 20:24
Target OS: NAS (Synology & others)
Domoticz version: DS213+
Contact:

Help needed -- lua script on Synology

Post by steef84 »

Hi,

running Domoticz on my Synology for quite some time now. I'm using Jumbotroll his compiled package.
I wanted to try a lua script found here https://gathering.tweakers.net/forum/li ... 9#47264699, but i can't manage to get it working.

I recreated this with my own switches etc, and enabled a variable integer with value 0 named "Schemer_licht_aan". I also have the switches 'IemandThuis', 'State - IsDonker' and 'Vakantietimer' available. They are on/off switches..

Code: Select all

local presence_switch = 'IemandThuis'
local isdark_switch = 'State - IsDonker'
local Vakantie_timer = 'Vakantietimer'


vSchemer_licht_aan = tonumber(uservariables['Schemer_licht_aan'])

function sleep(n)
  os.execute("sleep " .. tonumber(n))
end

commandArray = {}

if devicechanged[isdark_switch] then
    if (otherdevices[isdark_switch] == 'Off' and otherdevices['Zon op-onder'] == 'Off' and vSchemer_licht_aan >= 1) then
        commandArray['Group:Huiskamer']='Off'
        commandArray['Group:Huiskamer']='Off' AFTER 15
        commandArray['Vakantietimer']= 'Off'
        commandArray['Variable:Schemer_licht_aan'] = tostring(0)
        print('<font color="blue">LICHT - Het is licht geworden - Alle lampen uit!!</font>')
    
    elseif (otherdevices[presence_switch] == 'On' and otherdevices['Vakantie'] == 'Off' and otherdevices[isdark_switch] == 'On' and vSchemer_licht_aan == 0) then
         commandArray['Vakantietimer']= 'On'
        commandArray['Group:Huiskamer']='On'
        commandArray['Group:Huiskamer']='On AFTER 10'
        commandArray['Variable:Schemer_licht_aan'] = tostring(1)
        print('<font color="blue">THUIS - Het is donker en er is iemand Thuis - Lichten gaan aan!!</font>')
 
    elseif (otherdevices[presence_switch] == 'Off' and otherdevices['Vakantie'] == 'Off' and otherdevices[isdark_switch] == 'On' and vSchemer_licht_aan == 0) then
        commandArray['Vakantietimer']= 'On'
         commandArray['Scene:Sfeertje']= 'On'
        commandArray['Scene:Sfeertje']= 'On' AFTER 10
        commandArray['TV kijken']='On'
        commandArray['Variable:Schemer_licht_aan'] = tostring(2)
        print('<font color="blue">NIET-THUIS - Er is niemand Thuis - Het is donker - Sfeerlicht gaat aan!!</font>')

    elseif (otherdevices['Vakantie'] == 'On' and otherdevices[isdark_switch] == 'On' and vSchemer_licht_aan == 0) then
        commandArray['Vakantietimer']= 'On'
        commandArray['Scene:Sfeertje']= 'On'
        commandArray['Scene:Sfeertje']= 'On' AFTER 10
        commandArray['TV kijken']='On'
        commandArray['Slaapkamer bedlamp']='On'
        commandArray['Slaapkamer bedlamp']='On' AFTER 10
        commandArray['Variable:Schemer_licht_aan'] = tostring(2)
        print('<font color="blue">VAKANTIEMODE - Er is niemand Thuis - Het is donker - Licht beneden & boven gaan aan -- TV gaat aan!!</font>')
    end
end

if devicechanged[presence_switch] then  
    if (otherdevices[presence_switch] == 'Off' and otherdevices['Vakantie'] == 'Off' and otherdevices[isdark_switch] == 'On' and vSchemer_licht_aan == 1) then
       commandArray['Vakantietimer']= 'On'
        commandArray['Scene:Sfeertje']= 'On'
		commandArray['PowerOff']='On'
        commandArray['Variable:Schemer_licht_aan'] = tostring(2)
        print('<font color="blue">WEGGAAN - De laatste persoon heeft heeft het huis verlaten- Het is donker - Sfeerlicht gaat aan !!</font>')
    
    elseif (otherdevices[presence_switch] == 'On' and otherdevices['Vakantie'] == 'Off' and otherdevices[isdark_switch] == 'On' and vSchemer_licht_aan == 2) then
       commandArray['Vakantietimer']= 'On'
        commandArray['Group:Huiskamer']='On'
        commandArray['Group:Huiskamer']='On' AFTER 10
        commandArray['Variable:Schemer_licht_aan'] = tostring(1)
        print('<font color="blue">THUISKOMEN - Het is donker en er komt iemand thuis - Lichten gaan aan!!</font>')
    end
end

if devicechanged[Vakantie_timer] then
    if (otherdevices['Vakantietimer'] == 'Off' and otherdevices['Vakantie'] == 'On' and otherdevices[isdark_switch] == 'On' and vSchemer_licht_aan == 2) then
        commandArray['Group:Huiskamer']='Off'
        commandArray['Group:Huiskamer']='Off' AFTER 15
        commandArray['PowerOff']='On'
        commandArray['Slaapkamer bedlamp']='Off'
        commandArray['Slaapkamer bedlamp']='Off' AFTER 10
        commandArray['Variable:Schemer_licht_aan'] = tostring(1)
        print('<font color="blue">VAKANTIEMODE - Er is niemand Thuis - Slaapstand actief - Alle lichten gaan uit!!</font>')
    end
end

return commandArray
Now comes the error in my my log:

Code: Select all

2016-06-27 20:52:01.862 Error: EventSystem: in script_device_verlichting: [string "local presence_switch = 'IemandThuis' ..."]:17: syntax error near '15'
.

I can't seem to fix this problem. When I change the local switches for the real name switches the error seems so change to

Code: Select all

2016-06-27 20:58:32.243 Error: EventSystem: in script_device_test2: [string "vSchemer_licht_aan = tonumber(uservariables['..."]:12: syntax error near '15'
Anyone recogines this as a Synology specific error? Or is it me completely missing something?

Thanks in advance
- Stefan
User avatar
jvdz
Posts: 2330
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Help needed -- lua script on Synology

Post by jvdz »

Line 17 should read:

Code: Select all

        commandArray['Group:Huiskamer']='Off AFTER 15'
Same issue on lines 32,40,43,60,72

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
steef84
Posts: 37
Joined: Friday 30 August 2013 20:24
Target OS: NAS (Synology & others)
Domoticz version: DS213+
Contact:

Re: Help needed -- lua script on Synology

Post by steef84 »

Very nice find, didn't spot that one! Thanks. Fixed it and now the script partly works. When for example my IemandThuis switch changes the lua script comes partly in actions and trigger some actions. However it throws an error at the log.

Code: Select all

2016-06-27 22:48:00.289 Error: EventSystem: in script_device_verlichting: [string "vSchemer_licht_aan = tonumber(uservariables['..."]:9: attempt to index global 'devicechanged' (a nil value)
.

Using now this script_device_verlichting.lua file

Code: Select all

vSchemer_licht_aan = tonumber(uservariables['Schemer_licht_aan'])

function sleep(n)
  os.execute("sleep " .. tonumber(n))
end

commandArray = {}

if devicechanged['State - IsDonker'] then
    if (otherdevices['State - IsDonker'] == 'Off' and otherdevices['Zon op-onder'] == 'Off' and vSchemer_licht_aan >= 1) then
        commandArray['Group:Huiskamer']='Off'
        commandArray['Group:Huiskamer']='Off AFTER 15'
        commandArray['Vakantietimer']= 'Off'
        commandArray['Variable:Schemer_licht_aan'] = tostring(0)
        print('<font color="blue">LICHT - Het is licht geworden - Alle lampen uit!!</font>')
    
    elseif (otherdevices['IemandThuis'] == 'On' and otherdevices['Vakantie'] == 'Off' and otherdevices['State - IsDonker'] == 'On' and vSchemer_licht_aan == 0) then
         commandArray['Vakantietimer']= 'On'
        commandArray['Group:Huiskamer']='On'
        commandArray['Group:Huiskamer']='On AFTER 10'
        commandArray['Variable:Schemer_licht_aan'] = tostring(1)
        print('<font color="blue">THUIS - Het is donker en er is iemand Thuis - Lichten gaan aan!!</font>')
 
    elseif (otherdevices['IemandThuis'] == 'Off' and otherdevices['Vakantie'] == 'Off' and otherdevices['State - IsDonker'] == 'On' and vSchemer_licht_aan == 0) then
        commandArray['Vakantietimer']= 'On'
         commandArray['Scene:Sfeertje']= 'On'
        commandArray['Scene:Sfeertje']= 'On AFTER 10'
        commandArray['TV kijken']='On'
        commandArray['Variable:Schemer_licht_aan'] = tostring(2)
        print('<font color="blue">NIET-THUIS - Er is niemand Thuis - Het is donker - Sfeerlicht gaat aan!!</font>')

    elseif (otherdevices['Vakantie'] == 'On' and otherdevices['State - IsDonker'] == 'On' and vSchemer_licht_aan == 0) then
        commandArray['Vakantietimer']= 'On'
        commandArray['Scene:Sfeertje']= 'On'
        commandArray['Scene:Sfeertje']= 'On AFTER 10'
        commandArray['TV kijken']='On'
        commandArray['Slaapkamer bedlamp']='On'
        commandArray['Slaapkamer bedlamp']='On AFTER 10'
        commandArray['Variable:Schemer_licht_aan'] = tostring(2)
        print('<font color="blue">VAKANTIEMODE - Er is niemand Thuis - Het is donker - Licht beneden & boven gaan aan -- TV gaat aan!!</font>')
    end
end

if devicechanged['IemandThuis'] then  
    if (otherdevices['IemandThuis'] == 'Off' and otherdevices['Vakantie'] == 'Off' and otherdevices['State - IsDonker'] == 'On' and vSchemer_licht_aan == 1) then
       commandArray['Vakantietimer']= 'On'
        commandArray['Scene:Sfeertje']= 'On'
		commandArray['PowerOff']='On'
        commandArray['Variable:Schemer_licht_aan'] = tostring(2)
        print('<font color="blue">WEGGAAN - De laatste persoon heeft heeft het huis verlaten- Het is donker - Sfeerlicht gaat aan !!</font>')
    
    elseif (otherdevices['IemandThuis'] == 'On' and otherdevices['Vakantie'] == 'Off' and otherdevices['State - IsDonker'] == 'On' and vSchemer_licht_aan == 2) then
       commandArray['Vakantietimer']= 'On'
        commandArray['Group:Huiskamer']='On'
        commandArray['Group:Huiskamer']='On AFTER 10'
        commandArray['Variable:Schemer_licht_aan'] = tostring(1)
        print('<font color="blue">THUISKOMEN - Het is donker en er komt iemand thuis - Lichten gaan aan!!</font>')
    end
end

if devicechanged['Vakantietimer'] then
    if (otherdevices['Vakantietimer'] == 'Off' and otherdevices['Vakantie'] == 'On' and otherdevices['State - IsDonker'] == 'On' and vSchemer_licht_aan == 2) then
        commandArray['Group:Huiskamer']='Off'
        commandArray['Group:Huiskamer']='Off AFTER 15'
        commandArray['PowerOff']='On'
        commandArray['Slaapkamer bedlamp']='Off'
        commandArray['Slaapkamer bedlamp']='Off AFTER 10'
        commandArray['Variable:Schemer_licht_aan'] = tostring(1)
        print('<font color="blue">VAKANTIEMODE - Er is niemand Thuis - Slaapstand actief - Alle lichten gaan uit!!</font>')
    end
end

return commandArray
- Stefan
steef84
Posts: 37
Joined: Friday 30 August 2013 20:24
Target OS: NAS (Synology & others)
Domoticz version: DS213+
Contact:

Re: Help needed -- lua script on Synology

Post by steef84 »

My error is fixed with this post: viewtopic.php?f=23&t=12568#p90073 Thanks again Jos!
- Stefan
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest