[quote=“rigpapa, post:4, topic:200032”]This solution also won’t work across a Vera reload or reboot, if that happens while you’re watching a movie. To address that, you need to save the movieLights table to state somewhere:
-- Save the movieLights table in my private service on device 99 (projector?)
luup.variable_set( "urn:mydomainname-com:serviceId:MyServiceName", "MovieLights", table.concat( movieLights, "," ), 99 )
...
-- Get the movieLights table from my private service
str = luup.variable_get( "urn:mydomainname-com:serviceId:MyServiceName", "MovieLights", 99 ) or ""
movieLights = {}
str:gsub( "([^,]*),", function( m ) table.insert( movieLights, tonumber(m) ) return "" end )
if str ~= "" then table.insert( movieLights, tonumber( str ) ) end
This saves the table as a comma-separated list (string), but it’s kind of a pain to undo that, as you can see. It simplifies the code to use JSON, at a small expense of more memory use to do the module loading:
[code]json = require(“dkjson”)
– Save the movieLights table in my private service on device 99 (projector?)
luup.variable_set( “urn:mydomainname-com:serviceId:MyServiceName”, “MovieLights”, json.encode(movieLights), 99 )
…
– Retrieve the movieLights table
str = luup.variable_get( “urn:mydomainname-com:serviceId:MyServiceName”, “MovieLights”, 99 ) or “{}”
movieLights = json.decode( str ) or {}
[/code]
Note that this basically ignores any errors that might pop up in JSON decoding, but if the stored value is only touched by this code, there should never be any such errors. If an error does occur, this code just produces an empty table (no crash).[/quote]
Good idea! You could also read the list of lights you want to be affeced the same way, that way you can edit the variable list for that device instead of editing the script