Announcement

Collapse
No announcement yet.

Script to continuous dim a light from an event

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script to continuous dim a light from an event

    Background:
    I'm using various scene controller capable devices to control a zigbee light. I can setup an event to very easily dim up the light as long as I hold the button down as follows:

    Click image for larger version

Name:	Capture1.PNG
Views:	414
Size:	26.0 KB
ID:	1431726

    The problem is that the 1 second interval is too slow. I'd like to trigger a script from an event so that I can set the dim interval in milliseconds. Any examples of a looping script that will dim a light until told to stop. Of course it will need to read the initial value of the light and then increment up (or down).

    Thanks!

    #2
    Just thinking out loud here, can't you set the dim speed of either the device or the remote. Or possibly is there a "released" function on the remote? In another discussion I mentioned the ZRC-90. That remote has pressed, held and released commands available.

    Comment


      #3
      Originally posted by racerfern View Post
      Just thinking out loud here, can't you set the dim speed of either the device or the remote. Or possibly is there a "released" function on the remote? In another discussion I mentioned the ZRC-90. That remote has pressed, held and released commands available.
      It's a non-zwave smart bulb. The dim levels can only be set through commands. I'm trying to simulate the bulb being continuously dimmed up and down by an event triggered by any device capable of triggering the event. I have no problem dimming it through regular event timing as illustrated in the post, but it's not as fast as I'd like it.

      Comment


        #4
        I wrote this a while back to control a dimmer using central scenes from another switch or dimmer. See if it can be adapted to what you're looking for.

        Code:
        Imports System.Threading, System.Convert
        Public Sub Main(ByVal Parms As Object)
        '' This script should be called when a central scene is set to "held down"
        '' it dims A dimmable device either up Or down until the central scene becomes "key released" or the load hits 99 or 0
        '' Parameters '<device ref #>|<device ref central scene #>|up|<dimrate>' or '<device ref #>|<device ref central scene #>|down|<dimrate>'
        '' ie: 79|78|up|10
        
        Dim ParmArray() As String
        ParmArray = Parms.ToString.Split(ToChar("|"))
        
        Dim DeviceRef As Integer = Integer.Parse(ParmArray(0))
        Dim DeviceValue As Integer = hs.DeviceValue(DeviceRef)
        Dim DeviceRefCS As Integer = Integer.Parse(ParmArray(1))
        Dim DeviceValueCS As Integer
        Dim Keyreleased As Integer = 1001
        
        Dim UpDown As String = ParmArray(2)
        
        '' DimStep is the increment value for each dim setting
        Dim DimStep As Integer = 3
        
        If UpDown = "down" Then DimStep = DimStep * -1
        If UpDown = "down" Then Keyreleased = 2001
        
        '' DimRate is how long to take between dim levels; ie the rate of dimming in milliseconds
        Dim DimRate As Integer = Integer.Parse(ParmArray(3))
        
        
        For value As Integer = 0 To 100
        
        '' increment the dim% value then set min and max values
        DeviceValue = DeviceValue + DimStep
        If DeviceValue > 99 Then DeviceValue = 99
        If DeviceValue < 0 Then DeviceValue = 0
        
        '' set the device to the current value
        Dim cc As HomeSeerAPI.CAPIControl = hs.CAPIGetSingleControl(DeviceRef, True, "Dim (value)%", False, False)
        cc.ControlValue = DeviceValue
        Dim cr As HomeSeerAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
        
        '' get current central scene value
        DeviceValueCS = hs.DeviceValue(DeviceRefCS)
        
        '' check to see if we should exit the loop
        If DeviceValue = 0 Or DeviceValue = 99 Or DeviceValueCS = Keyreleased Then Exit Sub
        
        Thread.Sleep(DimRate)
        Next
        
        End Sub
        HS4 Pro on Shuttle NC10U, Win10; Z-NET
        Number of Devices: 1005
        Number of Events: 293

        Plug-Ins: BLLock, DirecTv, EasyTrigger, Honeywell WiFi Thermostat, Marquis monoprice Amp, MeiHarmonyHub, PHLocation2, Pushover 3P, UltraM1G3, rnbWeather, Worx Landroid, Z-Wave

        External applications: Homebridge-homeseer, Geofency, EgiGeoZone.

        Comment


          #5
          Originally posted by jmaddox View Post
          I wrote this a while back to control a dimmer using central scenes from another switch or dimmer. See if it can be adapted to what you're looking for.
          Thanks! After getting my google fu working I found an older thread where you posted this originally, also found a script snippet from someone else. Based on your example and the other I'll try to put something together that will hopefully execute faster then doing the timing at the event level.

          Comment


            #6
            I have had varying success with dim rate control, especially with color bulbs. Some do not have the resolution for small changes in color that is implied by higher rates of control.

            Comment


              #7
              Originally posted by Michael McSharry View Post
              I have had varying success with dim rate control, especially with color bulbs. Some do not have the resolution for small changes in color that is implied by higher rates of control.
              You may be right, but that's the not the problem I'm trying to solve. Even if the steps I'm using are rather broad, let's say 12% for every step, that's still up to 8 seconds for a full dim range using the 1 second interval available in an event recurring trigger.

              I don't like smart bulbs, the automation should be built into the house infrastructure (ie, the dimmers and outlets) so that one can freely change out the bulbs to whatever technology comes along. But for the limited color bulbs I do have, I make it a point to use quality ones like Philips Hue which can definitely display a 12% step change.

              Comment

              Working...
              X