Author Topic: House shutdown Procedure using VC  (Read 3545 times)

0 Members and 1 Guest are viewing this topic.

aussie mate

  • Jr. Member
  • **
  • Posts: 27
  • Karma: 2
    • View Profile
House shutdown Procedure using VC
« on: March 09, 2014, 04:27:33 AM »
Here is my first attempt at this so i hope it is all ok.

This script is one that you can run if you have HA and you want to shut everything down as you leave the house.
It currently is using x10 command but could be adapted for any HA system.
I did want to have a "cancel shutdown" command in case I want to halt the count down timer but I could not get it to work correctly.
BTW - the count down timer only goes for 20 sec but you should be able to see how to adjust that.
The alarm is controlled by my HA system so there are no commands for it in the script.


Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="House Shutdown" enabled="True" prefix="" priority="3" requiredProcess="" description="">
  <command id="688" name="House shut down mode" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.SpeakSync</cmdType>
      <cmdString>Do you want me to shut the house down?</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.On</cmdType>
      <cmdString />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>I am leaving, I am leaving the house, </phrase>
  </command>
  <command id="520" name="Shut house down" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{LastSpoken}&amp;&amp;be good</ifParams>
      <then>
        <action>
          <cmdType>TTS.SpeakSync</cmdType>
          <cmdString>Ok I will initiate the House shut down procedure</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.SpeakSync</cmdType>
          <cmdString>I will turn off all the lights and activate the alarm system</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.SpeakSync</cmdType>
          <cmdString>the shut down process will occurr in 60 seconds</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.TellVox</cmdType>
          <cmdString>Count Down Timer</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{LastSpoken}&amp;&amp;not today</ifParams>
      <then>
        <action>
          <cmdType>TTS.SpeakSync</cmdType>
          <cmdString>Understood, the house will remain in the current mode</cmdString>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <phrase>that would be good, not today</phrase>
    <phrase optional="true">yes, ok, no</phrase>
  </command>
  <command id="549" name="Count Down Timer" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.SpeakSync</cmdType>
      <cmdString>initiating the house shutdown procedure</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.SpeakSync</cmdType>
      <cmdString>You have 60 seconds to leave the house.</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.SpeakSync</cmdType>
      <cmdString>59, 58, 57, 56, 55, 54, 53, 52, 51, 50,</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.SpeakSync</cmdType>
      <cmdString>10, 9, 8, 7,  6,  5,  4,  3,  2,  1,,,</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.SpeakSync</cmdType>
      <cmdString>The House Shutdown has been Initiated.</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>X10.SendPlc</cmdType>
      <cmdString>K1 ON</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Count Down Timer</phrase>
  </command>
</commandGroup>
Go Manly, NSW & the All Blacks

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: House shutdown Procedure using VC
« Reply #1 on: March 09, 2014, 06:22:17 PM »
When you use TTS.SpeakSync it basically freezes and waits for the speaking to finish before moving on to the next action.  So you are not going to have much luck cancelling your command if you use speaksync.

In order to do it properly I think you would need to use a timer that goes off every second, and counts down from 60 (probably using python for subtraction).  You would need to use TTS.Speak.

A separate command could be used to cancel the sequence you have initiated by setting a variable that gets checked each time the count down loops.

So break it down something like this (pseudo code):

Command A:  
 - does the initial announcement (you can enable confirmation requirement on this command if you want)
 - sets a variable: 'shuttingDown' = True
 - sets a variable: 'counter' = 60
 - Starts command B

Command B:
 - Checks if 'shuttingDown" is still True, and if not then uses VC.StopMacro to quit the current macro and break the loop
 - Checks if counter is 0.  If it is then call the final shutdown command D and then VC.StopMacro to quit the current macro and break the loop
 - at this point we know we are still counting down so...
 - Speaks the counter using TTS.Speak (not SpeakSync)
 - Subtracts 1 from the variable 'counter'
 - set an eventTimer to run Command B again in one second.

Command C: (cancel)
 - Sets 'shuttingDown' = false

Command D:
 - do whatever is supposed to be done when the countdown finished (i.e. shut down stuff)

It may look pretty complicated, but it is not so bad, and it will almost certainly work.  Of course you will have problems if VC can hear itself counting down too loudly, and is trying to interpret the countdown as voice commands.
« Last Edit: March 09, 2014, 06:47:11 PM by nime5ter »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: House shutdown Procedure using VC
« Reply #2 on: March 09, 2014, 10:56:51 PM »
In order to do it properly I think you would need to use a timer that goes off every second, and counts down from 60 (probably using python for subtraction).  You would need to use TTS.Speak.

Yes, this solution works very well, but TTS.Speak doesn't give room for the chitchat/back and forth that some users want. I would recommend using TTS.SpeakSync for Command A's "initial announcement", so that the countdown begins after that point. The rest needs to be TTS.Speak, though.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: House shutdown Procedure using VC
« Reply #3 on: March 14, 2014, 08:49:41 AM »
In case it's of interest to anyone, in the attached I've combined Aussie mate's approach with jitterjames's suggestion for handling cancellation of the shutdown process.

I've added a few bells and whistles to make it more conversational as well, in keeping with the spirit of Aussie mate's initial post.

As always with a command group xml file (as opposed to xml in a code block), to import it into your own tree you just need to download the file to your desktop, and then drag the file itself into your tree (i.e., don't open the file).

As per Aussie mate's original posted commands, the actual home automation component of the shutdown will depend on your own setup so there is just a placeholder command there.

[Edit: I have added a bit more chitchat to one command; the computer now tells you that it understood the order to cancel the shutdown. Also, I forgot to mention that this xml requires the Python plugin be enabled.]
« Last Edit: March 15, 2014, 10:05:00 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

keithj69

  • $upporter
  • Sr. Member
  • *****
  • Posts: 113
  • Karma: 7
    • View Profile
Re: House shutdown Procedure using VC
« Reply #4 on: May 23, 2014, 12:01:12 AM »
Wow, this is cool. Thanks everyone.

jmpal32

  • $upporter
  • Jr. Member
  • *****
  • Posts: 4
  • Karma: 0
    • View Profile
Re: House shutdown Procedure using VC
« Reply #5 on: June 27, 2014, 09:04:00 AM »
That really is cool works like a charm!!!