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

0 Members and 1 Guest are viewing this topic.

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
The PY script is from here:
http://voxcommando.com/forum/index.php?topic=1679.msg14606#msg14606

the change i did to the PY script, was change any reference to "GmailStartu.py"

the XML:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<commandGroup open="True" name="Gmail notifier alert" enabled="False" 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>TTS.Speak</cmdType>
          <params>
            <param>Subject. {1} . Message. {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.AddText</cmdType>
          <params>
            <param>Message: {2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>newMsgVC</event>
  </command>
  <command id="358" name="Gmail Startup" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\GmailStartup.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Thanks Nime5ter for your help

My goal is, because i have an arduino attached to the PC:

Arduino with a water sensor in the water bowl of my dog, if the water is too low
smtp sends me a mail with a warning about the low water (that part is checked and working)

I send back a mail to myself with the subject "VC"
and the body of the mail, something like "Water Dog"
and the arduino triggers an action to open a valve to serve water to the dog
(half part completed)

depends on the body of the replay mail, it could be:
Water Dog
Food Dog
Turn On Heater
Turn Off Heater
etc

Thanks again


mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
I have another PY script that loads at startup, with the VC.Loaded event, and this is for
the initialization of COM port for arduino

attached is the code

Thank you

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
I am not having any crashing with the gmail notification script, so as James mentioned we'd need to see your log to be able to make any kind of educated guess: http://voxcommando.com/mediawiki/index.php?title=Log

That said, if you're sending messages to a gmail account that gets a ton of email, it's possible that the amount of logging in the original script is creating a lot of extra, unnecessary work (assuming you have logging enabled in VC, that is).

Since you seem to understand a bit about how scripting works, perhaps you've noticed that the Python script writes to your log every time a new gmail message is received. You could comment out that logging to see if it helps. It is really meant for debugging, with the expectation that users will know to comment out extra logging once they have tested it.

However: in the scenario you're describing, using a script that is polling every 30 seconds is, I think, not the most efficient way to handle things.

There are a few alternatives that would be less work for your machines.


« Last Edit: December 27, 2015, 05:30: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
e.g. you could use IFTTT to send messages/trigger events in VC, either using the TCP plugin in VoxCommando or the Watcher plugin + Dropbox.

https://ifttt.com/p/jitterjames/shared
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)

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Thanks for your response

the IFTTT takes even up to 15 minutes to send an email or SMS, is very slow for my needs

Can you pointing me in the direction for the other alternatives ?

Attached is the log

the log stops at 3:00, but the programs crashed at 3:04 aprox


jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
No, sending messages to VC using ifttt is quite fast. It's a matter of seconds, not minutes.

Ifttt is generally slow when monitoring things like RSS feeds etc. because that involves polling which it does infrequently, understandably.

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
I have the IFTTT with the littlebits "cloudbit" and the messages took up to 15 minutes
to reach the destination.

http://littlebits.cc/kits/cloudbit-starter-kit

on the other hand, the email with the py/VC solution took no more than 5 seconds to  be received

thanks

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
The speed of littlebits is irrelevant.  I am telling you because I have used the recipe before.  Sending a message to VC using email and IFTTT is fast.  If you don't want to try it that is up to you, but please don't tell me that I am wrong without even trying it.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Attached is the log

the log stops at 3:00, but the programs crashed at 3:04 aprox

Hm. That's very strange.

The error message is not too helpful. The main things you can try are:

1. Get rid of the logging in the script, as I mentioned earlier.

2. Reduce the rate of polling. The default is 30 seconds, which is a LOT, and we generally recommend polling no more than every few minutes.

You mentioned that you did not change this value, however later in the thread you said, "the email with the py/VC solution took no more than 5 seconds to  be received." That may sometimes be true if gmail happened to received a "vc" email seconds before the python script was already scheduled to poll. However, it should sometimes be taking close to 30 seconds to receive, because it should have only been checking your e-mail every 30 seconds.

If that value has been changes to <30 seconds, that could also cause problems.

3. Another thing you could try is to create a new gmail account just for this purpose, so that VC is not receiving and having to evaluate all your regular email to find the occasional "vc" emails.
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)

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Thanks James,
I will try IFTTT

Thanks Nime,

I will implement all your suggestions, but later in the next year (a week away :D)

I want to finish something I started with ESP8266, to integrate it into your solution
I also want to try the new post you just published:
 
http://voxcommando.com/forum/index.php?topic=2434.msg20972#msg20972

thanks for all the help

and happy holidays for both of you and all other VC members and users

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Great. Hopefully it will meet your needs.

As a rule, we recommend not using polling solutions unless they are truly necessary. In your case, since you want manual control over what happens based on feedback from the sensors, the gmail notifier solution is overkill (even if it worked for you -- which for some reason it does not ...).

I did upload a new version of the gmail notifier script to fix something in the code, but based on your log I don't think it was responsible for your particular problem.
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)

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Hi Nime,

Let me give you the whole picture of mi project: (this is just an example)

and arduino with 2 sensors, 1 relay, 1 servo, all connected over wifi to my network:

sensor 1 - water sensor for the water bowl of my dog - moist sensor
sensor 2 - food sensor to the food bowl of my dog - weight sensor
relay 1 - connected to a water pump to server water to the bowl
1 servo - connected to a door of a food dispenser


if the water level goes down, VC speaks a message, and send me an email to let me know the dog
needs water.
if I am at home, I can speak back to VC and let it trigger the relay to serve water
if I am away from home, i send an email to trigger an action to serve the water (all over my smartphone)


example VC to email: (smtp plugin)
Subject: VC
Message: Water level is low

example email to VC: (your PY script)
Subject: VC
Message: Serve water

the same applies to the food sensor/servo
the only difference is the message from VC, and the message back to VC

any help is highly appreciate

thanks


nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Yes, I think you described this scenario earlier.

If your preferred method of communication with VC when you're away from home is email, then the IFTTT solution should work as reliably as the gmail notifier python script, but without requiring you to constantly query the gmail servers (which is what the python script is doing).

You would still use the SMTP.Send/TTS announcement command. The difference is simply the method by which your reply email is received when you respond to tell VC what to do.

I think that once you have the time to test the IFTTT email option, you'll see what I mean.

Of course, whether you use the gmail notifier or IFTTT, you won't automatically receive any confirmation feedback (remotely) that your command was successfully executed. You would have to add another command that sends a confirmation email to you to verify that it received your previous instructions. (Very doable.)
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)

mexicanto

  • Contributor
  • ***
  • Posts: 55
  • Karma: 1
    • View Profile
Thank you very much Nime,
I will try IFTTT, meanwhile, there is still a lot to do over arduino-wifi