LUA script repeating like crazy

Moderator: leecollings

Post Reply
Reneke44
Posts: 2
Joined: Saturday 14 October 2017 12:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11780
Location: Netherlands
Contact:

LUA script repeating like crazy

Post 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
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA script repeating like crazy

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Reneke44
Posts: 2
Joined: Saturday 14 October 2017 12:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11780
Location: Netherlands
Contact:

Re: LUA script repeating like crazy

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest