Is it possible to create a ?switch? that turns on or off all of the lights within the room it is assigned to within Vera ?
So rather than have to create a virtual switch linked to an associated scene for each room, or have an itemised list of device IDs within a some lua code by room.
Could a single piece of code be created that when run, looks for the room that this switch is assigned , look up all the lights within it, and then based on the command (on or off) carry out the required action?
As always I might be missing something completely obvious with this - if I am sorry - just let me know.
I?m just thinking about lights at the moment, as that is my pain point - if I look at my Hue integration, I have 6 lights within one room (4 are in one light fitting, but are shown individually)
Having a dimmer for all, as well as an off/on grouping option would be nice touch too (@cokeman)
If we can group them, then maybe we could also use veras ability to make a device invisible option, that way once grouped they do not appear individually within the UI, we just have a grouped light option. When you ungroup they are made visible again.
I use a virtual switch for my 3 exterior lights, al 3 in different rooms. When the switch is manually turned on/off, this triggers a PLEG action to turn on/off the lights. I also trigger the virtual switch based on sunrise/sunset. It could easily be done in a scene as well.
Agreed, using PLEG or a scene to group devices ; and then having a single trigger to carry out the same action across all of them is straightforward - Home Automation 101 - stuff.
Ideally out of the box Vera should have come with built in grouping capability for lighting and rooms. If I look within the Phillips Hue app , they allow you to group individual lights and control them together under 1 identity in the UI (hiding them as individual lights when grouped)
In the absence of it being built in to Vera; Im curious what it would take to code something thats dynamic (no scene/PLEG association needed) - I can envisage a sort of virtual switch too, but one thats coded upfront to i) be aware of the room its assigned to ii) to be able to look up all the lights that are in that same room automatically and iii) can then control alll of them together (a sort of Dynamic Grouping Switch)
Just been working on a piece of code on the side, that lists all the lights, their assigned room, and then their status. (For those with LuaTest, copy and paste to confirm)
[code]
function get_key_for_value( t, key )
for k,v in ipairs(t) do
if k==key then return v
end
end
end
local SSID = “urn:upnp-org:serviceId:SwitchPower1”
local HSID = “urn:micasaverde-com:serviceId:HaDevice”
for deviceNo,d in pairs(luup.devices) do
if d.category_num == 2 then
local tripped = luup.variable_get(SSID, “Status”, deviceNo) or “Nil”
if (tripped == “1”) then
end
local onoff = myLookupTable[tripped], 1
local kick = get_key_for_value( luup.rooms, d.room_num )
print (“The " …kick… " light, called (” … d.description … ") is switched " … onoff)