Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Controlling a light through DM in LUA

  1. #1
    Join Date
    Apr 2004
    Location
    Dearborn, MI
    Posts
    1,968

    Default Controlling a light through DM in LUA

    Code:
    -- Change to a light on your system, This happens to be a 'switch' type not a dimmer
    
    local path = 'Fordrat8\\ElkM1EZ8\\Light 14'
    	
    local device = DeviceManager:GetDeviceUsingPath (path)
    
    if device then
       device:Print ()
    else
       print ('No Device')
    end
    
    local controlid = 'Switch'
    local control = device:GetControl (controlid)
    if control then
      print ('Shutoff Workroom Light')
      control:SetValue ("Off")
    end
    Code:
    -- Now this is for a dimmer light
    
    local path = 'Fordrat8\\ElkM1EZ8\\Light 12'
    local device = DeviceManager:GetDeviceUsingPath (path)
    
    if device then
      device:Print ()
    else
      print ('No Device')
    end
    
    local controlid = 'Level'
    local control = device:GetControl (controlid)
    if control then
      print ('Turning on Family Room Lights')
      control:SetValue (100)
    end
    Last edited by jwilson56; November 7th, 2008 at 09:03 AM.
    John

    Now Playing skin creator

    Girder 5.0 / Elk-M1EZ8 / Ocelot / SECU-16IR /SECU-16I / SECU-16 / BobCat Humidity
    JRMC 11.1 / M-Audio Delta 410 / Xitel HIFI Pro / Xitel HIFI Link
    NetRemote 2.0 / 6 Zone whole house audio delivering 1580 watts RMS total
    ELO 15" Touchscreen, Nokia 770 and Advent 3500PC Mobile PC 7" TS
    Droid 2 Global

    Click here to visit my Nowplaying Showcase Blog

  2. #2
    Join Date
    Jun 2005
    Posts
    760

    Default

    The problem I have with this- How do you tell what Light 14 is?
    IMHO, it would be helpful to have some Lua code support the following methods that would make lighting control simpler and more intuitive:
    Code:
    Lights:Control('Workroom Light', 'Off')
    Lights:SetLevel('Family Room Lights', 100)

  3. #3
    Join Date
    Jun 2008
    Posts
    1,026

    Default

    that would be something like....

    Code:
    local device = DeviceManager:GetDeviceUsingLocationName ('Home\\Basement\\Workroom\Lights')
    
    device:SetControl ('Level',0)
    
    or 
    
    device:SetControl ('Switch','Off')

  4. #4
    Join Date
    Jun 2005
    Posts
    760

    Default

    Thanks Mike! I'll study this. Looks like it's easier than I thought.

  5. #5
    Join Date
    Apr 2004
    Location
    Dearborn, MI
    Posts
    1,968

    Default

    Quote Originally Posted by Mike C View Post
    that would be something like....

    Code:
    local device = DeviceManager:GetDeviceUsingLocationName ('Home\\Basement\\Workroom\Lights')
    
    device:SetControl ('Level',0)
    
    or 
    
    device:SetControl ('Switch','Off')
    Mike is there a way to use Location/Name (GetDeviceUsingLocationName) in the NR LUA code or something equivalent?
    Last edited by jwilson56; November 8th, 2008 at 11:07 PM.
    John

    Now Playing skin creator

    Girder 5.0 / Elk-M1EZ8 / Ocelot / SECU-16IR /SECU-16I / SECU-16 / BobCat Humidity
    JRMC 11.1 / M-Audio Delta 410 / Xitel HIFI Pro / Xitel HIFI Link
    NetRemote 2.0 / 6 Zone whole house audio delivering 1580 watts RMS total
    ELO 15" Touchscreen, Nokia 770 and Advent 3500PC Mobile PC 7" TS
    Droid 2 Global

    Click here to visit my Nowplaying Showcase Blog

  6. #6
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    Quote Originally Posted by Mike C View Post
    that would be something like....

    Code:
    local device = DeviceManager:GetDeviceUsingLocationName ('Home\\Basement\\Workroom\Lights')
    
    device:SetControl ('Level',0)
    
    or 
    
    device:SetControl ('Switch','Off')
    You should be aware however that GetDeviceUsingLocationName only retrieves the first device matching that location/name. If you have more than one then you should probably use GetDevicesUsingLocation which returns a table of the devices at that location. Normally there is only one device but this is not enforced so it's quite possible that the device you get back may not be the one you intended.
    Last edited by Rob H; November 9th, 2008 at 04:49 AM.
    --Rob

  7. #7
    Join Date
    Apr 2004
    Location
    Dearborn, MI
    Posts
    1,968

    Default

    Yes... Harleydude explained that to me last night on MSN. Personally I do not have a problem using path but wanted to see if there was a way for some other people.
    John

    Now Playing skin creator

    Girder 5.0 / Elk-M1EZ8 / Ocelot / SECU-16IR /SECU-16I / SECU-16 / BobCat Humidity
    JRMC 11.1 / M-Audio Delta 410 / Xitel HIFI Pro / Xitel HIFI Link
    NetRemote 2.0 / 6 Zone whole house audio delivering 1580 watts RMS total
    ELO 15" Touchscreen, Nokia 770 and Advent 3500PC Mobile PC 7" TS
    Droid 2 Global

    Click here to visit my Nowplaying Showcase Blog

  8. #8
    Join Date
    Apr 2004
    Location
    Dearborn, MI
    Posts
    1,968

    Default

    Is there any interest in seeing a NR CCF example for turning lights on and off and having dim up and down buttons instead of sliders? I ruffed one out for someone but will polish it up and upload it if others want to see it.
    John

    Now Playing skin creator

    Girder 5.0 / Elk-M1EZ8 / Ocelot / SECU-16IR /SECU-16I / SECU-16 / BobCat Humidity
    JRMC 11.1 / M-Audio Delta 410 / Xitel HIFI Pro / Xitel HIFI Link
    NetRemote 2.0 / 6 Zone whole house audio delivering 1580 watts RMS total
    ELO 15" Touchscreen, Nokia 770 and Advent 3500PC Mobile PC 7" TS
    Droid 2 Global

    Click here to visit my Nowplaying Showcase Blog

  9. #9
    Join Date
    Mar 2008
    Location
    Nottingham, England
    Posts
    406

    Default

    Hi John,

    Yeah there's always interest in how things are done from me....

    As I'm learning I'm constantly asking myself...is that right...can it be done different....what if....

    so to see some examples from my point of view is the best way to learn

    all this LUA stuff & State stuff is overwhelming for me to take in just reading

    I would also like to see internet radio, photo album with slideshow?


    Cheers

    Mark
    some people learn by writing, some by reading, some by listening and some by doing?...me I'm not learning at all

  10. #10
    Join Date
    Apr 2004
    Location
    Dearborn, MI
    Posts
    1,968

    Default

    Ok here is the small example that shows how to turn lights on and off and dim with buttons. It also has an example for non dimming switches or appliance modules.

    You will have to go through each button and change the 'path' to a light or switch you want to control. Also change the 'state' variable to that same light so that the little light bulb will show the correct status. Last change the % Dim value display Element Name to the correct 'path' also.

    Good Luck...and remember there are many ways to get what you want. This is just one.....
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	example-screenshot.jpg 
Views:	297 
Size:	7.0 KB 
ID:	5221  
    Attached Files Attached Files
    Last edited by jwilson56; March 30th, 2010 at 11:49 AM.
    John

    Now Playing skin creator

    Girder 5.0 / Elk-M1EZ8 / Ocelot / SECU-16IR /SECU-16I / SECU-16 / BobCat Humidity
    JRMC 11.1 / M-Audio Delta 410 / Xitel HIFI Pro / Xitel HIFI Link
    NetRemote 2.0 / 6 Zone whole house audio delivering 1580 watts RMS total
    ELO 15" Touchscreen, Nokia 770 and Advent 3500PC Mobile PC 7" TS
    Droid 2 Global

    Click here to visit my Nowplaying Showcase Blog

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •