Page 1 of 1

LUA script repeating like crazy

Posted: Thursday 12 March 2020 18:47
by Reneke44
I don't really know how to describe this. I'm trying to make a script that turns on or off the living room lights, based on the sValue of a text device.
The text device is being updated by a Plex webhook. That works fine. So does my script. It just keeps repeating like crazy, where it actually should only run when the text device changes. It's really basic for the moment, but when I can get this behavior fixed I can build on from this. Please help?
This is my script:

Code: Select all

-- Plex verlichting woonkamer

commandArray = {}
 if (string.find(otherdevices['Plex-Woonkamer'],'play') or
     string.find(otherdevices['Plex-Woonkamer'],'resume'))
 then
     commandArray['LED-strip-TV']='Off'
 else
     commandArray['LED-strip-TV']='On'
 end
return commandArray

Re: LUA script repeating like crazy

Posted: Thursday 12 March 2020 18:58
by jvdz
That's because you do not test for changed device, so with each event you will send a new event creating an endless loop.
Something like this probably will fix that:

Code: Select all

-- Plex verlichting woonkamer

commandArray = {}
if devicechanged['Plex-Woonkamer'] then 
    if string.find(otherdevices['Plex-Woonkamer'],'play') 
    or string.find(otherdevices['Plex-Woonkamer'],'resume') then
        commandArray['LED-strip-TV']='Off'
    else
        commandArray['LED-strip-TV']='On'
    end
end
return commandArray
Jos

Re: LUA script repeating like crazy

Posted: Friday 13 March 2020 0:08
by Reneke44
Thank you Jos. That looks like the solution. I’m trying to learn LUA and did see the devicechanged function, but didn’t know where to insert it.

Thank you :)