Announcement

Collapse
No announcement yet.

Virtual Device: Control & Status?

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

    Virtual Device: Control & Status?

    I don't think what I am trying to accomplish can be done with just simple Event Triggers, so I started to code it in VB.NET but I am stuck.

    So I created a virtual device for my TV. It has two control buttons On and Off.

    When I press On, an event trigger uses MeiHarmonyHub to launch an activity.
    When I press Off, an event trigger uses MeiHarmonyHub plugin to Power Off.

    That's easy. I also have a Z-Wave switch that tells me if the TV is On based on how many Watts are being used.
    How can I change the status of the device based on Watt usage? If I make an event that simply changes the Virtual Device TV to On/Off it ends up triggering MeiHarmonyHub to launch an activity or powers the TV off.

    I tried using hs.SetDeviceValueByRef and setting False the last parameter so that it won't trigger the MeiHarmonyHub events but then other events that check if the virtual device is On won't trigger.

    Can someone point me in the right direction on how to solve this? Do I have to use something with CAPI controls?

    #2
    How about adding a condition to the event that triggers MeiHarmonyHub such that it doesn't trigger if watts are already showing that the TV is on?

    Comment


      #3
      I'm not completely sure what you are trying to do, but it sounds like you want to display 'On' or 'Off' based on the wattage reading, but still use the device as a trigger for events based on it's value/status. One way would be to create a tracking device in addition to the one you have.

      Another option, probably closer to what you have in mind, would be to try writing "On" and "Off" to the device string. That should override the status message, but not trigger your events. You can do that without a script, but it will require an immediate script statement, like this: &hs.SetDeviceString(nnnn, "On", True), where 'nnnn' is the RefID of the virtual device. (PS. I haven't tested this explicit application, but I it should work. )
      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


        #4
        Originally posted by Uncle Michael View Post
        it sounds like you want to display 'On' or 'Off' based on the wattage reading, but still use the device as a trigger for events based on it's value/status.
        That's exactly what I want to do. I don't mind writing a script but I would rather have the device's value handle everything.

        Comment


          #5
          Originally posted by zwolfpack View Post
          How about adding a condition to the event that triggers MeiHarmonyHub such that it doesn't trigger if watts are already showing that the TV is on?
          This was a solution I was using but I ended up having way too many events for similar virtual devices and it just became too difficult to manage. I would prefer to have everything written in a script.

          Comment


            #6
            I had a similar situation at one time with a HT receiver although no longer have the events. If I recall correctly I did something like this.

            IF TVControlDevice changes and becomes ON
            AND IF CurrentSensorDevice = OFF
            THEN trigger meiharmonyhub activity

            IF CurrentSensorDevice changes and becomes ON
            AND IF TVControlDevice = OFF
            THEN Set TVControlDevice = ON

            edit: on re-reading this I'm not 100% sure that's how I had it working but may be worth a try
            -Wade

            Comment


              #7
              Originally posted by HS14 View Post
              That's exactly what I want to do. I don't mind writing a script but I would rather have the device's value handle everything.
              What are you using for the event triggers? Can you post screen shots of the events that this device initiates?

              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


                #8
                Essentially the best analogy I can think of is that I want it to act a bit like a Z-Wave Switch.

                If you press ON on the HS device, it sends a signal to the physical Z-Wave device to turn on BUT if the device for whatever reason doesn't respond, the HS device will switch back to OFF.

                How to make a virtual device be both a control device AND a status device at the same time?

                Comment


                  #9
                  What you want to do may be possible, but others do not have the exact hardware you are using, so we need more information. If you post a screen shot of the events that you have, that may provide a basis for suggestions that will lead to a solution.
                  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


                    #10
                    Originally posted by Uncle Michael View Post
                    What you want to do may be possible, but others do not have the exact hardware you are using, so we need more information. If you post a screen shot of the events that you have, that may provide a basis for suggestions that will lead to a solution.
                    Fair enough, I attached events of what I am somewhat trying to accomplish but won't work since it will trigger events needlessly.



                    Comment


                      #11
                      Thank you. That helps, but I'm still not sure I understand. If the TV is turned on by changing the control state with the control button, then it would appear that the 'Speaker poll on' event will not run, since the device state will already be 'On'. Similarly for the case when the TV is turned off by changing the control state with the device control button. What sequence leads to the circumstance where the 'Speaker watts' value changes across the threshold value and then triggers the 'Speaker poll' events?
                      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


                        #12
                        OK, So if I've got this correct you want the virtual device on/off to power everything on and everything off and show either on or off. Now you want the zwave wattage device to change the icon to reflect on if the tv has been turned on manually.
                        Try this I took a virtual device and added 2 values and 2 icons on the status graphics page. 0 and 100 already there, just added 1 and 99. Made 1 the same as 0(off) and the 99 the same as 100(on). Also checked the status only box under status-control for these two buttons. You'll only see one set of on off buttons on the device. If you press the on button the device value goes to 100 and press the off button it goes to 0. Now if the wattage detects usage then set the devicevaluebyref to 99 but you'll still see an on icon. This was you can still trigger an event by value 100 or 0 but not 1 or 99.

                        Stuart

                        Comment


                          #13
                          Originally posted by Stuart View Post
                          Now if the wattage detects usage then set the devicevaluebyref to 99 but you'll still see an on icon. This was you can still trigger an event by value 100 or 0 but not 1 or 99.
                          I agree. This sounds like a good suggestion. You could also modify the status text, and/or the icon for the new device values to be something other than the default if you want to make it clear which state the device is in. Does this do what you want?

                          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


                            #14
                            So my solution was to write a script for this. I essentially just check which device has the most up-to-date data, either the Poll device ("tvWatts") or the Switch device ("tvControl").

                            I attached a screenshot of the events and a snippet of the code which I changed out the ref ID value to a string value so the code is easier to read.

                            Code:
                            Else If virtualDevice = "television" Then
                              ' Variables for this device
                              Dim tvWatts As Integer = hs.DeviceValueEx("tvWatts")
                              Dim tvControl As Integer = hs.DeviceValueEx("tvControl")
                            
                              ' Poll device has NEWER data, therefore control device will update status
                              If hs.DeviceLastChangeRef("tvWatts") > hs.DeviceLastChangeRef("tvControl") Then
                                If tvControl = 255 AND tvWatts = 0 Then
                                  hs.SetDeviceValueByRef(deviceRef("tvControl"), 0, True)
                                  hs.WriteLogEx(scriptName, "Television: Status OFF", "#000080")
                                Else If tvControl = 0 AND tvWatts > 15 Then
                                  hs.SetDeviceValueByRef(deviceRef("tvControl"), 255, True)
                                  hs.WriteLogEx(scriptName, "Television: Status ON", "#000080")
                                Else
                                  hs.WriteLogEx(scriptName, "Television: Everything is already set properly (Status)", "#000080")
                                End If
                            
                              ' Control device has NEWER data, therefore control device will execute
                              Else
                                If tvControl = 255 AND tvWatts = 0 Then
                                  CAPIControl("harmonyActivity", "Home Theater PC")
                                  hs.WriteLogEx(scriptName, "Television: Control ON", "#000080")
                                Else If tvControl = 0 AND tvWatts > 0 Then
                                  CAPIControl("harmonyActivity", "PowerOff")
                                  hs.WriteLogEx(scriptName, "Television: Control OFF", "#000080")
                                Else
                                  hs.WriteLogEx(scriptName, "Television: Everything is already set properly (Control)", "#000080")
                                End If
                              End If

                            Comment

                            Working...
                            X