Author Topic: Gmail notifier - Using IP camera email notifications to trigger events in VC  (Read 27774 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
I thought the following might be helpful for some VC users.

I have written some python code* that can read a gmail feed (the same atom feed that you can check using VC's built-in gmail actions).

Depending on the message content, the code will trigger a "newMail" event in VC. The script re-checks gmail every 30 seconds (this interval can be adjusted), and the whole script is threaded so that it will not freeze VoxCommando. It just runs in the background, basically.

Currently the script only triggers an event when a new email with the subject line "motion detected" is received. This can be changed.

This could be adapted to serve any number of purposes -- use your imagination. It is not just for IP cameras etc.

I wrote it to address a specific problem: Casmo recently posted, looking for a way to trigger VC events when his camera detects motion.

Some cameras can send UDP or http messages directly, which makes life easy. But for less full-featured cameras, we have to rely on workarounds.

Casmo's IP camera can be configured to send an email message when motion is detected. This is a pretty common feature, I think. As long as you don't mind using gmail, the attached gmail_notifier.py can then make use of those email notifications.

Obviously, to use the attached file, you'll need to enable the Python plugin in VC.

I store my python scripts in my VoxCommando\PY folder, but do what you wish. You'll need to open the file (which you can do in VC's python editor) and enter the appropriate gmail username and password as directed, then save the file.

Other aspects of the code can be customized as well, of course.

I hope some of you will find it a useful starting point. Enjoy!

*[Extreme overstatement alert. This is just other people's code cobbled together, with some customized RegEx and conditions added.]

UPDATED SCRIPT 18-FEB-2015 -- resolved authorization error by updating the "realm" parameter to "mail.google.com" (see http://stackoverflow.com/questions/28547395/gmail-atom-feed-stopped-working-lately). Also restored default interval of 30 seconds.

UPDATED SCRIPT 28-DEC-2015 -- mistake in try/catch might cause problems if VC loses access to the Internet. Fixed.
« Last Edit: December 28, 2015, 12:00:09 PM 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)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Just for fun, here is what I did with the gmail notifier in VC:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.0-->
<commandGroup open="True" name="Alarm" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="272" name="motion detected" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{var.away}&amp;&amp;True</ifParams>
      <then>
        <action>
          <cmdType>SMTP.Send</cmdType>
          <params>
            <param>your neighbour's email@email.com</param>
            <param>motion detected!</param>
            <param>Camera message: {1} {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.SpeakSync</cmdType>
          <params>
            <param>Intruder alert! Your presence has been detected.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>Sound.PlayWav</cmdType>
          <params>
            <param>siren.wav</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.TellVox</cmdType>
          <params>
            <param>red alert</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Hue.Group</cmdType>
          <params>
            <param>0</param>
            <param>"effect":"colorloop"</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>Sound.PlayWav</cmdType>
          <params>
            <param>bugle.wav</param>
            <param>True</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>There is someone at the front door.|Are you expecting visitors?</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>There is someone at the front door.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>newMsg</event>
  </command>
  <command id="273" name="Set to away mode" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Setting VC to away mode.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>away</param>
        <param>True</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set to away mode, I'm leaving the house now</phrase>
  </command>
  <command id="285" name="Cancel away mode" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Cancelling away mode.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>away</param>
        <param>False</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Hi honey I'm home, Cancel away mode</phrase>
  </command>
  <command id="289" name="launch gmail notifier python script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\gmail_notifier.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

One command runs the python code on VC.Loaded. It will continue to run in the background until VC is closed.

I have two commands to let VC know when I'm "away" and when I'm back home. They work very simply by setting an away variable in VC to True or False. (This variable could then be used for any number of commands.)

Depending on whether I'm away or home, VC will respond differently to the "motion detected" newMail alert that it receives.

------------
A more simple example that is probably a better command to test with:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.3.3-->
<commandGroup open="True" name="Gmail notifier alert" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="272" name="Alert received" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Alert received.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>Subject: {1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="True">
      <ifType>(A)==(B)</ifType>
      <ifParams>{2}&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>OSD.AddText</cmdType>
          <params>
            <param>Message: {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>newMsg</event>
  </command>
  <command id="299" name="launch gmail notifier python script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\gmail_notifier.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>
« Last Edit: January 08, 2015, 05:01:29 PM 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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
This is great, but it is not just for IP cameras!

You could use this to do a lot of stuff using gmail to trigger events or even initiate actions directly.

The new version of VC (2.003) will also have a 'Watcher' plugin which might be useful for IP cameras that can save images to a folder which VC can monitor.
« Last Edit: July 25, 2014, 01:08:13 PM by jitterjames »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
This is great, but it is not just for IP cameras!

Absolutely. Hence my line "This could be adapted to serve any number of purposes -- use your imagination."

I waffled on whether to be so specific in my subject line, but I wanted to make sure that our home automation crowd could find this thread when searching.  :D
« Last Edit: July 25, 2014, 01:02:33 PM 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)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
 :clap :clap :clap
this opens full control of vc and what ever it controls through sending emails ... house automation, security ....etc.
I think it will even make integrating IFTTT much easier
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
I think it will even make integrating IFTTT much easier

I hope it will be useful for some.

If you're lookng for more IFTTT integration, you may want to upgrade to 2.0.0.3, which is on the Downloads page now.  http://voxcommando.com/downloads.asp

The new Watcher plugin + Dropbox is a more efficient IFTTT solution than my python because it doesn't involve active polling. http://voxcommando.com/mediawiki/index.php?title=ChangeLog#NEW_Watcher_plugin.

You can instead save a text file to Dropbox in your IFTTT recipe. Set the new Watcher plugin to watch that Dropbox folder for new arrivals, et voilĂ .

This is also a better option for our non-Haddood crowd (aka, folks who don't want to deal with programming languages). ;)

« Last Edit: July 25, 2014, 06:06:59 PM 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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Search IFTTT recipes  for: voxcommando watcher

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
I hope it will be useful for some.

If you're lookng for more IFTTT integration, you may want to upgrade to 2.0.0.3, which is on the Downloads page now.  http://voxcommando.com/downloads.asp


 :o :o didn't know version 2.0.0.3 was released  ... will test immediately



This is also a better option for our non-Haddood crowd (aka, folks who don't want to deal with programming languages). ;)


 ::club

Search IFTTT recipes  for: voxcommando watcher

 :yay :clap ::bow ::wiggle
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
This is great, but it is not just for IP cameras!

You could use this to do a lot of stuff using gmail to trigger events or even initiate actions directly.

The new version of VC (2.003) will also have a 'Watcher' plugin which might be useful for IP cameras that can save images to a folder which VC can monitor.

NOTE: There was an error in the python file attached above, so I have updated the file.
If you're using the original file, change the variable "guser" to "gusr":
Code: [Select]
myMailChecker = mailChecker(gusr,gpwd)
And not to beat a dead horse here, but I just wanted to mention:

1) I didn't realize James would be releasing the Watcher plugin so soon when I posted the Python option, and in the case of IP cameras the Watcher plugin is a much easier solution if your camera can save motion-detected images to an accessible folder.

2) If you want to use the Python but aren't sure you understand how to adapt it even after giving it a thorough go, please feel free to post your questions. Within reason, I'm more than happy to provide further explanation or to help adapt the regular expression in the code if needed (for example, if you need to access the message itself, which currently isn't captured in the regular expression).
« Last Edit: July 28, 2014, 12:29:48 PM 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)

JoshK

  • Jr. Member
  • **
  • Posts: 32
  • Karma: 3
    • View Profile
I've been trying to get IFTTT integration with VC working through use of this -
https://github.com/captn3m0/ifttt-webhook.

has anyone else tried this?

btw I haven't succeeded yet. but it should be possible

Edit: since upgraded to 2.0.0.5 and used watcher plugin with dropbox for ifttt integration - Beautiful!
« Last Edit: August 09, 2014, 12:33:31 PM by JoshK »

Soda97

  • Contributor
  • ***
  • Posts: 69
  • Karma: 1
    • View Profile
Hi,

Noob here and not a programmer.

I have an security alarm that hooked up with the envisalink that will send me an email when I arm or disarm.  I want voxcommando to be able to speak a welcome or goodbye message.

How do I use the the receipt from IFTTT? And how do I use the watcher plug in to trigger that?

Thanks in advance!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Hi Soda97.

You basically have two choices.  You can do either of the following, you don't need to use both:

1 - Use the gmail notifyer script posted by nime5ter at the beginning of this thread to monitor your gmail account.  It will detect the subject line or your email and trigger an event.  This event can be used to run a command which will provide you with your TTS message.  For this to work you need to have your alarm system send an email to your gmail account that VoxCommando is monitoring.  It checks your mail every 30 seconds in a loop (but you could change the delay).

http://voxcommando.com/forum/index.php?topic=1679.msg14606#msg14606
(read the first two posts carefully)


2 - Use IFTTT, DropBox and the VoxCommando Watcher plugin.  How this works is that your alarm system would need to send an email to a specific IFTTT email address with a specific subject line.  When IFTTT receives this email it will run a recipe that saves a file to your dropbox.  The Watcher plugin will detect this file and read it and generate an event.  This event can be used to run a command which will provide you with your TTS message.

http://voxcommando.com/mediawiki/index.php?title=Plugin_Watcher
https://ifttt.com/recipes/191411-voxcommando-watcher-test

Decide which method suits you best and let us know if you need specific help with something.

Soda97

  • Contributor
  • ***
  • Posts: 69
  • Karma: 1
    • View Profile
Thanks for the reply.

I would like to use my iCloud email and would also want to trigger within a sec or so... I guess the 2nd option would be better for me?

I only know the very basic of using the voxcommando.  I have an Insteon home automation and I setup using scrape and phrase to trigger my lights from online instruction.  And that's all I know. I know nothing about create and using an event.

You think you can still walk me through it?

Thank you.

CarsonY101

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 2
    • View Profile
Hey Soda97! I've only been using VoxCommando about a year and found the link before helpful along with James YouTube channel. Just search VoxCommando to find him.

Hope this helps.

http://voxcommando.com/mediawiki/index.php?title=Main_Page

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
This might be a case of trying to run before you can walk.  We prefer that people learn a bit about how to use the program so that we don't have to spend all of our time walking every user through every step.  If you want to learn about events then you should read the wiki about events and also watch the events tutorial. http://voxcommando.com/mediawiki/index.php?title=Events

If you don't want to use a gmail account then the first option is not the one for you.

However, you will probably find that the second option will sometimes take more than "a second or so".  It might take 2 to 10 seconds (or maybe more) depending on the speed of sending an email, the speed of IFTTT and DropBox.

Is your alarm system only able to send emails, or can it do other things as well?