I’ve written Luup support code for a couple simple UI7 scenes, and aside from the way trigger Luup and action Luup are treated differently, things seemed to work as expected. I have a couple “library” files written for UI5 that work great there…hope to use them with my scant UI7 devices. I would expect such things largely to be portable. Am I too optimistic?
It’s a very reasonable hope, and one that is generally borne out in practice.
Unless you are doing something bizarre like rewriting device files, meddling with icons, or trying to code an alternate event server, then you should be safe enough.
Mostly only the GUI handling has changed, but not the Luup Lua library. Some new functions have been added. They are flagged as UI7 or version 7.x only in the wiki http://wiki.micasaverde.com/index.php/Luup_Lua_extensions
Cheers Rene
Cool, I’ll give it a spin. I have one UI7-controlled dimmer I’ll want working with Siri Shortcut scenes using Homewave as the conduit. The code is simple…“dimmers.lua” looks like this:
module ("dimmers", package.seeall)
D_SID = "urn:upnp-org:serviceId:Dimming1"
function decrease_light(device,levels)
local current = luup.variable_get(D_SID,"LoadLevelStatus",device)
current = tonumber(current)
-- sort in descending order
table.sort(levels, function(a,b) return a>b end)
-- walk down the list until we hit the value below current
for index,target in ipairs(levels) do
if (target < current) then
luup.call_action(D_SID,"SetLoadLevelTarget", {newLoadlevelTarget = target}, device)
return
end
end
end
function increase_light(device,levels)
local current = luup.variable_get(D_SID,"LoadLevelStatus",device)
current = tonumber(current)
-- sort in ascending order
table.sort(levels, function(a,b) return a<b end)
-- walk up the list until we hit the value above current
for index,target in ipairs(levels) do
if (target > current) then
luup.call_action(D_SID,"SetLoadLevelTarget", {newLoadlevelTarget = target}, device)
return
end
end
end
An example Luup scene that uses it:
require 'dimmers'
dimmers.decrease_light(51,{0,10,30,50,100})
“51” is the device ID, the array after it contains the levels I’m interested in getting to. So running this scene will decrease the level for this device to the next level in the array below current. A companion scene makes the same call to “dimmers.increase_light” for going the other direction.
I have something similar for toggling binary devices…locks, garage doors, etc. Rather than having a shortcut scene to turn on and another to turn off, invoking that changes the state to whatever it isn’t currently.
Anyway, I have some free time today and tomorrow, and will try dropping the library code into UI7 and having a scene invoke it.
–Richard
Many binary devices implement the ToggleState
Action in the urn:micasaverde-com:serviceId:HaDevice1
service. See:
http://wiki.mios.com/index.php/Luup_UPnP_Variables_and_Actions#HaDevice1
Was not aware of that. I also use the toggle shortcuts for turning on/off dimmers quickly, so probably would have hacked my code together anyway. But thanks for the pointer!
–Richard