Announcement

Collapse
No announcement yet.

Lights not returning to their original settings after animation ends

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

  • Lights not returning to their original settings after animation ends

    I've got a script that does the following:

    1. Stops an animation that is already running (stops animation named "Alert - Red")
    2. Starts a second animation (starts animation named "Alert - Cyan")

    When the second animation ("Alert - Cyan" animation) finishes running in a minute, the lights do not revert to their original settings (i.e. the settings that were in effect prior to the 1st animation started running). Instead, the lights revert to the 1st animation's settings. For example, if the lights were Off before the 1st animation ("Alert - Red") started running, the lights don't turn back off when the second animation ("Alert - Cyan") finishes. Instead, the lights revert to the 1st animation's settings (so the lights turn Red instead of turning off).

    It seems that there is some sort of timing issue? If I only stop an animation (using StopAnimation plug-in call) and I don't start another one, then the lights revert back to their original settings. Or, if an animation ends by itself (after elapsed wait time), then the lights revert back to their original settings. But, if I StopAnimation and then immediately StartAnimation, when the new animation finishes, the lights revert back to the settings of the 1st animation and not the original settings prior to the 1st animation running.

    Here is the code in my script:

    oldAnimation = "Alert - Red"
    rc = CBool(hs.PluginFunction("JowiHue", "", "StopAnimation", {oldAnimation}))
    If (rc = False) Then
    hs.WriteLog("Error", FuncName & ": 5. StopAnimation failed for " & oldAnimation)
    Else
    hs.WriteLog("Info", FuncName & ": 5. StopAnimation successful for " & oldAnimation)
    End If

    targetAnimation = "Alert - Cyan"
    rc = CBool(hs.PluginFunction("JowiHue", "", "StartAnimation", {targetAnimation, Nothing}))
    If (rc = False) Then
    hs.WriteLog("Error", FuncName & ": 5. StartAnimation failed for " & targetAnimation)
    Else
    hs.WriteLog("Info", FuncName & ": 5. StartAnimation successful for " & targetAnimation)
    End If


    Below is from the HomeSeer Log (listed in reverse-chronological order):
    Mar-24 10:49:40 AM JowiHue Animation Alert - Cyan Finished
    Mar-24 10:48:40 AM JowiHue Animation Alert - Red Finished
    Mar-24 10:48:38 AM JowiHue Start of animation Alert - Cyan
    Mar-24 10:48:38 AM Info UpdateHueLights: 5. StartAnimation successful for Alert - Cyan
    Mar-24 10:48:38 AM Info UpdateHueLights: 5. StopAnimation successful for Alert - Red
    As the code and the logs show above, the script does StopAnimation on the "Alert - Red" first, and then does StartAnimation on "Alert - Cyan". But the JowiHue log entries seem to show that "Alert - Cyan" starts before "Alert - Red" finishes? Anyway, when "Alert - Cyan" finishes (after about a minute), instead of the lights reverting to their original settings (i.e. their settings before "Alert - Red" started running), the lights revert to the settings done by the "Alert - Red" animation. What I really want is for the lights to revert back to the settings that they had before "Alert - Red" (and not turn Red).

    Is the issue because the StopAnimation and StartAnimation plug-in calls are not synchronous so there's some sort of timing issue going on? Any suggestions on settings or code changes if I want to stop one animation and start another one in the same script but I want the lights to revert to their original settings prior to the 1st animation started running?

    Below are the animation definitions:

    Click image for larger version  Name:	Animations.png Views:	1 Size:	106.6 KB ID:	1294706

    Below are the scenes used by the animations:

    Click image for larger version  Name:	Scenes.png Views:	1 Size:	68.8 KB ID:	1294707


    Below are the presets used by the scenes ("Alert Preset - Cyan" and "Colorful - Red"):

    Click image for larger version  Name:	Presets.png Views:	1 Size:	61.7 KB ID:	1294708





    Last edited by randman; March 24th, 2019, 10:40 AM. Reason: Fixed typo

  • #2
    randman

    This is an challenge indeed. It is all about timing here....

    The point is that each start of an animation is getting the current state of the lights involved. So if the second animation starts, it will check the current state of the lights, which might not have been refreshed yet, although the last animation is finished (and has reset the lights).
    So it will find the last state of the animation that was running just before the current animation and use these values to return to its last known state.

    In the configuration page of the plugin you will find a setting for the refreshrate of the bridge (only in use for Philips Hue bridges). To be sure the second animation gets the state of the lights as they should be, the bridge has to be refresed at least once before the second animation starts. So if your first animation has ended and your refreshrate is set to 3 seconds, set a wait for say 4 seconds before the second animation is allowed to start. This should solve the issue.

    But ofcourse it could be a lot easier to combine both animations into one animation, but I don't know 100% what you want to achieve

    Wim

    -- Wim

    Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
    650 devices ---- 336 events ----- 40 scripts

    Comment


    • #3
      Originally posted by w.vuyk View Post
      randman

      This is an challenge indeed. It is all about timing here....

      The point is that each start of an animation is getting the current state of the lights involved. So if the second animation starts, it will check the current state of the lights, which might not have been refreshed yet, although the last animation is finished (and has reset the lights).
      So it will find the last state of the animation that was running just before the current animation and use these values to return to its last known state.

      In the configuration page of the plugin you will find a setting for the refreshrate of the bridge (only in use for Philips Hue bridges). To be sure the second animation gets the state of the lights as they should be, the bridge has to be refresed at least once before the second animation starts. So if your first animation has ended and your refreshrate is set to 3 seconds, set a wait for say 4 seconds before the second animation is allowed to start. This should solve the issue.

      But ofcourse it could be a lot easier to combine both animations into one animation, but I don't know 100% what you want to achieve

      Wim
      Thanks, Wim.

      Yes, based on the logs, it looks like HomeSeer/JowiHue haven''t refreshed yet by the time I start the second animation. Also, I was looking at the "Philips hue" device (type JowiHueBridge). AFTER I called StopAnimation to stop the first 1st animation, but BEFORE I called StartAnimation to start the 2nd animation, the "Philips hue" device still said "1 animation(s) running" in its device string.

      I can't combine both animations into one animation. I use the animations to alert/notify me of any issues. I have various animations, one for each color. Each color signifies a specific alert condition. For example, I use the "Alert - Yellow" animation to turn the Hue group's lights to yellow when a garage door is opened. I use the "Alert - Red" animation to turn the lights red when the Smoke detector detects smoke. I use "Alert - Blue" when there is a water leak, etc. In my use case, it is possible that one issue happens so I turn the lights yellow, and then another higher-priority issue also occurs, so I want to turn the lights red. I suppose a simpler, one color for all alerting conditions would be easier, but I've already gone down the path of using different colors based on alert priority when I did this alerting for my HSM200 sensor LEDs.

      So, it looks like I have a couple of workarounds for this issue:

      1. As you suggested, after calling StopAnimation, call hs.WaitSecs(4) before calling StartAnimation. I tested this, and it works! The advantage of this is that if 2 (or more) alert conditions occur, the Hue lights will reflect the color of the highest priority issue. The disadvantage is that my script will take 4 more seconds to run (normally, it takes less than a second). The events that call my script use the event option "Only allow a single instance to run at a time" in order to prevent multiple instances of the same script from clashing with each other. So if I add another 4 seconds to my script, I might miss a change in my home's condition (whether a new alert condition arises, or an existing alert condition ends), and this can cause some undesirable side effects.

      OR

      2. If there is already an animation running, and another alert condition arises, don't bother doing StopAnimation/StartAnimation. Just let the old animation continue to run, until the 1st alerting condition is cleared. So, if the lights are yellow due to an open door, and the house catches on fire, the lights will continue to be yellow instead of red. But I should be able to hear my Smoke detectors, and I should get my Pushover notifications tell me there is a fire. Or, I'll start to get really hot :-)

      For my use, I think disadvantages of #1 are worse than disadvantages for #2... So, for now I'm looking to use #2.

      The only caveat with #2 is that I need to know whether an animation is still running to decide whether or not to call StartAnimation. Fortunately, StartAnimation does not allow more than one instance of the same animation to run. But I need to know if ANOTHER alert animation (different than the one I want to start) is already running. I can pretty reliably figure this out using a virtual device that I have, and also by calling hs.DeviceStringByName("JowiHue JowiHue Philips hue") and parsing for X in "X animation(s) running" (useful if virtual device gets out of sync or an animation ends since it's not in an infinite loop). So, if another animation is still running, don't bother doing StartAnimation. Just wait for the current animation/alert condition to end. Of course, this assumes that I only use animations for alert conditions. For now, this is true, but in the future, I might start using animations for something else. Don't know if it would be helpful to others or easy to do, but something like IsAnimationRunning(<animation name>) that returns True or False would be useful in this case. Or maybe a #3 option would be to have a StopStartAnimation(<animation to stop>, <animation to start>) that would do the calls in one operation. For now, I'm testing option #2 and see how it goes.

      Question: if I were to run animations outside of JowieHue (if possible, like from the Philips Hue app), will the "JowiHue JowiHue Philips hue" device include those animations, or does it only reflect JowiHue-specific animations that are running??

      Thanks.




      Comment


      • #4
        I could add a scripting command for getting information on animations running at a certain moment. Or the plugin could return a complete list of all current animations running.

        I can imagine that in your situation you'd like to have a slow animation running in the living room, but would like to also have a short alert going on the front door bell, which should not break the living room animation, but should stop a kitchen animation (just fantasizing here)

        You can choose on this I guess, a scripting command to query of a certain animation is running, or a command for returning a list of all animations running? Which do you prefer?

        Animations running by other apps are not known to any other apps, including the JowiHue plugin, as the bridge itself is not aware ot the existence of animations at all. So the plugin has no way of knowing if other animations are running outside the plugin. In that area I can only advise to try to have one source of animation control as weird effects might occur if you use more then one app at the same time controlling scenes or animations

        -- Wim

        Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
        650 devices ---- 336 events ----- 40 scripts

        Comment


        • #5
          I'm not that familiar with JowieHue, but I'm assuming it represents each of the lights in your animation as a device in HomeSeer. If so, I think the Easy Trigger plugin provides a straightforward solution to saving the lights' states before your animation and restoring it after. This can be done by using the "Push" and "Pop" device functions in the current (0.61) beta version of Easy Trigger.

          1. Form an Easy Trigger group that includes all of the lights in the animation (Set up the group from the [Plug-Ins] -> [Easy Trigger] -> [Config] page. Let's call it "Animation_Lights".
          2. Create an event with Actions that are structured like this . . .
          • "Easy Trigger: Push to Stack" (Group) Animation_Lights
          • "Run A Script or Command" (Your Script)
          • "Easy Trigger: Pop from stack and Set Devices" (Group) Animation_Lights

          Comment


          • #6
            Originally posted by w.vuyk View Post
            I can imagine that in your situation you'd like to have a slow animation running in the living room, but would like to also have a short alert going on the front door bell, which should not break the living room animation, but should stop a kitchen animation (just fantasizing here)
            Yes, exactly! I have a group of Hue lights that are dedicated for just doing ambiance lighting or alert-related JowiHue animations for notification purposes. This group won't be running non-alert animations (just JowiHue-defined alert-related animations). In addition, I have other Hue lights/groups that are NOT used for alert notifications, but might run non-alert-related animations which I don't want to disturb when I need to run an alert notification on the first group. So, what I'd like to do is: if an alert condition occurs, then start an alert-related animation (e.g. turn "red" or "yellow", etc.) if there is no alert-related animation already running.

            Originally posted by w.vuyk View Post
            You can choose on this I guess, a scripting command to query of a certain animation is running, or a command for returning a list of all animations running? Which do you prefer?
            Either one would work for me. Some thoughts: Option 1 (a command to query if a certain animation is running) is simpler for my particular use case. However, Option 2 (a command that returns a list of all animations running), might be better for general-use for other user cases or other users of this plug-in. If I had a list of all running animations (Option 2), I can always search the list to see if a particular animation is running or not. But with Option 1, getting a list of running animations is a little more difficult (one would have to call GetAnimations to get the complete list of all running and not-running animations, and then parse each entry in the list using Option 1 to figure out which from the list are currently running). Also, with Option 2, it would be another way to get the number of currently running animations (currently, I call hs.DeviceStringByName("JowiHue JowiHue Philips hue") and then check/parse if it returns "animations(s) running" to get the count).

            So, to answer your question, maybe option 2 would be better for general use.

            Originally posted by w.vuyk View Post
            Animations running by other apps are not known to any other apps, including the JowiHue plugin, as the bridge itself is not aware ot the existence of animations at all.
            Yes, that's good. I also tested this last night and hs.DeviceStringByName("JowiHue JowiHue Philips hue") didn't see animations that I started from outside of JowiHue (not that I normally would start animations outside JowieHue, but I just wanted to confirm).

            Thanks, Wim!!

            Comment


            • #7
              Originally posted by jvm View Post
              I'm not that familiar with JowieHue, but I'm assuming it represents each of the lights in your animation as a device in HomeSeer. If so, I think the Easy Trigger plugin provides a straightforward solution to saving the lights' states before your animation and restoring it after. This can be done by using the "Push" and "Pop" device functions in the current (0.61) beta version of Easy Trigger.

              1. Form an Easy Trigger group that includes all of the lights in the animation (Set up the group from the [Plug-Ins] -> [Easy Trigger] -> [Config] page. Let's call it "Animation_Lights".
              2. Create an event with Actions that are structured like this . . .
              • "Easy Trigger: Push to Stack" (Group) Animation_Lights
              • "Run A Script or Command" (Your Script)
              • "Easy Trigger: Pop from stack and Set Devices" (Group) Animation_Lights

              Thanks for the info. This looks interesting for more general-use cases or if I need much more customized functionality. I like the JowiHue plug-in's "Return to original settings after animation ends" feature since it does the heavy lifting underneath the covers (and no need to keep my Hue group in sync with an Easy Trigger group). When I explicitly do StopAnimation or if an animation ends by itself (when it is not defined to run indefinitely), then each light in the group will automatically revert to its original settings. If an animation ends by itself (if it's not defined to run indefinitely), my script/logic won't be automatically aware that it ended, so I won't have the opportunity to do the popping. (Aside: I recently ran into an event condition that I may need help with from the Easy Trigger plug-in... I need a condition "AND IF a <device> has been On for at most Xs", but HomeSeer only supports "AND IF a <device> has been On for at least Xs". So either I create a timer and use the timer in the condition, or get the Easy Trigger plug-in... anyway, that's another story).

              Thanks.

              Comment


              • #8
                Originally posted by randman View Post


                Aside: I recently ran into an event condition that I may need help with from the Easy Trigger plug-in... I need a condition "AND IF a <device> has been On for at most Xs", but HomeSeer only supports "AND IF a <device> has been On for at least Xs".

                Thanks.
                For situations like that, Easy Trigger supports the condition "This device's value has changed within the last [select time period]" which can be use to give you the effect you're looking for ( i.e., you can implement "AND IF a <device> has been On for at most Xs" as two conditions (a) Device X is on, and (X) Device X's value has changed within the last [time period].) Thus, if device X is on and has not changed within the time period you set, you know it has been on for more than the period you want.


                And as a FYI, Easy Trigger also supports an analogous "This device's value has NOT changed within the last [select time period]'. There's a free trial period for the plugin if you want to give it a try. I find it to be one of the most useful tools I know of to help write events.

                Comment


                • #9
                  Originally posted by jvm View Post

                  For situations like that, Easy Trigger supports the condition "This device's value has changed within the last [select time period]" which can be use to give you the effect you're looking for ( i.e., you can implement "AND IF a <device> has been On for at most Xs" as two conditions (a) Device X is on, and (X) Device X's value has changed within the last [time period].) Thus, if device X is on and has not changed within the time period you set, you know it has been on for more than the period you want.


                  And as a FYI, Easy Trigger also supports an analogous "This device's value has NOT changed within the last [select time period]'. There's a free trial period for the plugin if you want to give it a try. I find it to be one of the most useful tools I know of to help write events.
                  Yes, this plugin would’ve saved me a lot of coding if I had started using it a long time ago.

                  Comment


                  • #10
                    After playing with the JowiHue Plug-in for a couple of weeks now, I gotta say, I love this plug-in! I just read some other threads about creating sunrise and sunset animations, so I'm looking into having those start automatically via HomeSeer events as well. I need additional logic so that if an alert-related animation is currently running, another less critical animation (like sunrise or sunset animation) won't start so as not to disturb an alert-related animation. But, if a sunrise or sunset animation is already running, it should be preempted (stopped) by an alert-related animation. Looks like things can get messy if more than one animation is running at the same time on the same light group :-) . I can probably track things via virtual devices to see what is supposed to be currently running, but rainy day scenarios may cause my virtual devices' views to be out-of-sync with reality/actual JowiHue view. So, yeah, as you suggested, an API that can return a list of running animations would be great!

                    Originally posted by w.vuyk View Post
                    You can choose on this I guess, a scripting command to query of a certain animation is running, or a command for returning a list of all animations running? Which do you prefer?

                    Comment


                    • #11
                      I will make it will be there in the next release. No estimate yet on when the new release will be available
                      -- Wim

                      Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
                      650 devices ---- 336 events ----- 40 scripts

                      Comment


                      • #12
                        Originally posted by w.vuyk View Post
                        I will make it will be there in the next release. No estimate yet on when the new release will be available
                        Awesome! Thanks so much!!

                        Comment


                        • #13
                          Originally posted by randman View Post
                          . But, if a sunrise or sunset animation is already running, it should be preempted (stopped) by an alert-related animation. Looks like things can get messy if more than one animation is running at the same time on the same light group :-)
                          After rereading your description, I wonder if you have seen the option "Continue after any other Hue command" when creating an animation? An alert (with restore to original values enabled) can run on top of a sunset animation, the sunset will take over again after the alert has finished?
                          -- Wim

                          Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
                          650 devices ---- 336 events ----- 40 scripts

                          Comment


                          • #14
                            Originally posted by w.vuyk View Post

                            After rereading your description, I wonder if you have seen the option "Continue after any other Hue command" when creating an animation? An alert (with restore to original values enabled) can run on top of a sunset animation, the sunset will take over again after the alert has finished?
                            I saw that option earlier but it wasn’t clear to me. Let me play with that option on the sunset/sunrise animation. Sounds like a useful option to continue an “ambience” animation when it is preempted by an “alert” animation and then ends.

                            However, if an alert animation is currently running (such as a code Red alert), and either (1) another alert (maybe a code Yellow alert issue) occurs, or (2) it is time to start the sunset/sunrise animation, I would like a way to know not to start the new animations so they don’t interrupt the first (e.g. Red) alert animation. To do that, a way of knowing what animations are currently running would be helpful.

                            Comment


                            • #15
                              The new function is not a discussion here . In fact in my edits at this very moment it is already available. I was just pointing to an possibility to ignore a running animation that could continue after starting another animation(alert). The new function will be available as ListRunningAnimations() as List(of String)

                              Wim
                              -- Wim

                              Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
                              650 devices ---- 336 events ----- 40 scripts

                              Comment

                              Working...
                              X