Announcement

Collapse
No announcement yet.

Automatic lights thru a loop reading notes.....

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

    Automatic lights thru a loop reading notes.....

    So this is my idea:

    Att a regular interval, read all (in my case) Z-Wave devices that represents a on/off switch or a dimmer. In my case the are all controlling my lamps. I would need to read parameters stored in a free text field, like the "Notes" field (or something better?) and act from that.

    Let's say this parameter says:
    5

    That would be interpreted to "when turned on, it will be turned off after 5 minutes by the loop defined above".

    Or if is says:
    6,20

    That would be interpreted to "when turned on manual (by user interaction on the wall switch or something not triggered by an event) wait 20 minutes before turning off, and if turned on by an event wait 6 minutes".

    And so on.

    So how do I read the "Notes" field in a device, or is it any better suggestion on a field I could use? And how do I loop all Z-Wave devices that are "controlling" in my case lamps?

    (of course, if this field used as a parameter, is empty, nothing should/will happen)

    #2
    If I'm interpreting your question properly, I do not think there is a way to do what you want exactly as you envision it. You could use a script, but keeping track of how each device was turned on is not something that HS does natively. On the other hand, you can include in any event that turns on a light a delayed action to turn it off, so instead of recording the information in the device you'd record it in the event. That gives you the added flexibility to allow the lamp on time to be variable by event.

    To turn off a lamp that has been turned on manually, given the parameters in your post, you could have an event for each lamp that checks how long it's has been on, and if the time is longer than a limit value (again, stored in the event, not in the device) assume that the lamp was not turned on by an event (the limit would need to be longer than any event limit) then turn the lamp off.

    A more common way to handle lights off is to monitor activity in the space to determine if it is occupied or not, then turn off lights based on that data. It's more involved, but avoids arbitrarily turning off a lamp even if someone is still using it.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Well yes and no...

      I will have to store a property like "Status" per device in for example a Global Variable (which needs to be created each time the system is started since Global Variables does not survive a restart...). I could, at the same time, also create a "Time" property in a Global Variable....

      The main thing is that I do not like to hardcode everything all the time. For example, for every time delayed lamp I have (and I do have a few - different design than motion activity) I a) has a script that turns on a lamp for what ever trigger I choose, b) a script that sets the turnoff time, and c) a script that runs all the time that checks all time variables from b if time has passed and turns off that device. So for every device I add, I end up with two scripts/events per device plus a number of rows of script code in the general script running every minute (I have a general purpose event for that - completely different story). However this way, the way I coded this, it works if someone manualy turns on any of the devices defined for this, will be handled correctly, and also cover for automatic triggering like a motion event.

      Comment


        #4
        Have you considered storing your parameters in an .ini file?
        Mike____________________________________________________________ __________________
        HS3 Pro Edition 3.0.0.548, NUC i3

        HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

        Comment


          #5
          No. And the reason is that I like to have the parameters inside the device. If I could store my extra properties inside the device then I would. Hmmm maybe I could add two virtual devices to the root node of each device with the parameter string is stored in the Notrs field?!

          Comment


            #6
            Your code is going to be incredibly complex, but do-able. For what you're describing though, I would think that delayed actions and even timers would be a better fit.
            HS4Pro on a Raspberry Pi4
            54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
            Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

            HSTouch Clients: 1 Android

            Comment


              #7
              If you are open to other ways to accomplish some of this, I have a plugin in beta for allowing one device to control another as well as things like 'turn off after 10 minutes of being turned on' which is your primary use case. LMK if you want to try it out to see if it would do what you'd like.

              Comment


                #8
                Originally posted by rmasonjr View Post
                Your code is going to be incredibly complex, but do-able. For what you're describing though, I would think that delayed actions and even timers would be a better fit.
                I have tested timers, and I am a bit disappointed to them, since they can only count up and not down to zero. This is due to the fact that I use different values for my timers for different time of day (say 20 minutes in the bathroom morning time, 7 minutes daytime/evening, and only 3 minutes during night time) - it is possible to handle by using three different triggers yes, but the way it is implemented is well not my style maybe? I use delayed actions, however I find them a bit frustrating since I need to cancel them sometimes... So no, in current shape I need something more flexible....

                That being said, my solution above is not flexible from a few points, although the code needed per room/event is constant... I might end up with my current solution anyway, since it works (when I remember to change everywhere when I make a change.....) and well it does what I need.

                Comment


                  #9
                  Okay, so it's been some time since I started this, and well a lot of stuff got in the way. However I now have a simple script that does what I need:

                  Code:
                  Sub Main(ByVal Parm As Object)
                  
                  hs.writelog("AutoOff", "Start")
                  
                  Dim CurrTime = now()
                  Dim NewTime = now()
                  Dim Device_DT = now()
                  Dim New_Device_DT = now()
                  
                  Dim Devnr as integer
                  
                      Try
                  
                          Dim dv As Scheduler.Classes.DeviceClass
                          Dim EN As Scheduler.Classes.clsDeviceEnumeration
                  
                          EN = hs.GetDeviceEnumerator
                  
                          Do
                              dv = EN.GetNext
                  
                              If dv Is Nothing Then Continue Do
                  
                              If dv.UserNote(Nothing).ToLower <> "" and dv.Interface(Nothing).ToLower = "z-wave" Then
                                  hs.writelog("AutoOff", "UserNote: " & dv.UserNote(Nothing))
                                  hs.writelog("AutoOff", "Function: " & dv.Location2(Nothing))
                                  hs.writelog("AutoOff", "Room: " & dv.Location(Nothing))
                                  hs.writelog("AutoOff", "Device ID: " & dv.Ref(Nothing))
                                  hs.writelog("AutoOff", "Name: " & dv.Name(Nothing))
                                  hs.writelog("AutoOff", "Device Value: " & dv.devValue(Nothing))
                                  hs.writelog("AutoOff", "DeviceLastChanged: " & dv.Last_Change(Nothing))
                  
                                  Device_DT = DateAdd("n", cint(dv.UserNote(Nothing)), dv.Last_Change(Nothing))
                                  hs.writelog("AutoOff", "NewDeviceTime: " & Device_DT )
                                  hs.writelog("AutoOff", "CurrTime: " & CurrTime )
                                  If DateTime.Compare(CurrTime, Device_DT) > 0 and dv.devValue(Nothing) <> "0" Then
                                     hs.writelog("AutoOff", "Automagic turnoff: " & dv.Location(Nothing) & " - " & dv.Location2(Nothing))
                                     Devnr = cint(dv.Ref(Nothing))
                                     hs.CAPIControlHandler(hs.CAPIGetSingleControl(Devnr, true ,"off", false, true))
                                  End If
                  
                              End If
                  
                          Loop Until EN.Finished
                  
                      Catch ex As Exception : hs.writelog("AutoOff", "Exception: " & ex.message)
                      End Try
                  
                  hs.writelog("AutoOff", "Stop")
                  End Sub
                  For this to work just enter a integer in the "notes" field of the device you like to control, and let the script run every minute or so, and it will fix the rest. Kind of...

                  Comment

                  Working...
                  X