save RF states and restore after reboot
Hi,
I've built a script, which is saving the RF states on change events into a .ini file and restoring these values after a livebox reboot, so the states as seen on the livebox and the real states are equal.
Hope somebody can use this code!
Markus from Linz, Austria
Attachment | Size |
---|---|
WM_logRFStatesApplet.lua | 2.12 KB |
?
I currently have 12 rf controlled sockets and so had to make a small mod to this script.
The script as it stands only takes the first digit in the xap message which is fine if you have 9 or less rf sockets. My problem was when setting rf.10, rf.11 and rf.12.
These got stored in the rf-settings.ini file as rf1 rf1 and rf1
the mod is below
function logstate()
-- Ignore the xAPBSC.info class messages.
if xap.getValue("xap-header","class") == "xAPBSC.event" then
-- Get the relays STATE either on or off
state = xap.getValue("output.state","state")
-- This LUA pattern will parse the source address ie. 'dbzoo.livebox.Controller:rf.1'
-- From this string extract the digit 1.
rf = string.match(xap.getValue("xap-header","source"),"rf.(%d+)")
-- Print out this relays current state
writeINIfile(filename, rf, state)
...and noticed that my 10th device was being stored as rf1 even with Mark's modification.
I've tried several things related to the pattern matching in the Applet but nothing fixed the issue.
e.g. :
Line 122: rf = string.match(frame:getValue("xap-header", "source"), "rf%.(%d+)")
added the % in front of the dot
Line 89: if string.find(lines[j], "rf%d*=") then
added the * to %d
Neither of these seemed to fix the issue, so I then removed the 'if' statement in the logstate function and expanded the filter in init with
f:add("xap-header", "class", "xAPBSC.event")
and bingo. My 10th RF device now logs as rf10. Not sure which of the above was the definitive fix so I've uploaded my logRFstatesApplet
Attachment | Size |
---|---|
logRFStatesApplet.lua | 2.88 KB |
Nice script Markus, thanks for sharing. I have no idea how this works however, I'm still using the "lua for dummies" manual. That said, scripts like these help us novices get new ideas.cheers. Garry