Automatically Set States via Tasker for Android (WORKING!)

Forum for questions and support relating to the 1.24.x releases only.
Post Reply
camroidv27
Posts: 35
Joined: Tue Jun 15, 2010 6:18 am

Automatically Set States via Tasker for Android (WORKING!)

Post by camroidv27 » Tue Aug 02, 2011 8:03 pm

This is more of a request, and process post than anything. I am trying to make a setup that once my cell phone (Android) connects to my WiFi at my house, it will tell Zoneminder to switch off some of the cameras via changing the Runstate of Zoneminder.
I have two profiles, one called "Away" and the other called "Home"
Tasker has the ability to Post a form via Http.
It would work properly, except that I have a login enabled. Currently, its appears there is no way to auto login via the URL alone. Here is what I have found so far:

From someone posting about auto logging in from a cell phone, where inserting this form into an HTML page will give you a button that will automatically log you in:

Code: Select all

<form name="loginForm" id="loginForm" method="post" action="http://yourIP/index.php" target="_blank">
        <input name="action" value="login" type="hidden">
        <input name="view" value="postlogin" type="hidden">
        <table id="loginTable" class="minor" cellspacing="0">
          <tbody>
            <tr>
              <td class="colRight"><input name="username" value="YOURUSERNAME" size="12" type="hidden"></td>
            </tr>
            <tr>
              <td class="colRight"><input name="password" value="YOURPASSWORD" size="12" type="hidden"></td>
            </tr>
          </tbody>
        </table>
        <input value="ENTER" type="submit" >
      </form>
I also found that you can use the URL to change states:

Code: Select all

http://YOURIP/zm/index.php?view=state&action=&apply=1&runState=Away&newState=
I feel like I have two parts that can work together... but unable to see the connection. Any ideas? I'll keep researching and testing till I figure this one out.

And one more little bit that may help (from the Wiki:FAQ)
Now you can switch between these two states by selecting them from the same dialog you saved them, or from the command line from issue the command zmpkg.pl <run state>, for example zmpkg.pl Daytime.
The final step you need to take, is scheduling the time the changes take effect. For this you can use cron. A simple entry to change to the Daylight state at at 8am and to the nighttime state at 8pm would be as follows,
0 8 * * * /usr/local/bin/zmpkg.pl Daytime
0 20 * * * /usr/local/bin/zmpkg.pl Nighttime
Last edited by camroidv27 on Wed Aug 03, 2011 6:58 am, edited 1 time in total.

kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Re: Automatically Set States via Tasker for Android

Post by kevin_robson » Tue Aug 02, 2011 8:15 pm

If you can get the last bits (from the wiki) working you could 2 create shell scripts in cgi-bin, and call them through Apache?

camroidv27
Posts: 35
Joined: Tue Jun 15, 2010 6:18 am

Re: Automatically Set States via Tasker for Android

Post by camroidv27 » Tue Aug 02, 2011 8:45 pm

The last bits work properly, however, they need root permission to run the zmpkg.pl. Not sure how to lock that bit down, let alone having Apache call the script from an HTTP Post.

camroidv27
Posts: 35
Joined: Tue Jun 15, 2010 6:18 am

Re: Automatically Set States via Tasker for Android

Post by camroidv27 » Tue Aug 02, 2011 8:58 pm

I got login via URL! Great for those with cell phones!
But it appears I can't chain it with the state change.

camroidv27
Posts: 35
Joined: Tue Jun 15, 2010 6:18 am

Re: Automatically Set States via Tasker for Android

Post by camroidv27 » Wed Aug 03, 2011 1:40 am

It Works!

I created a script called control.php in /var/www/zm with chmod 755 on it.

Code: Select all

<?php
$output = shell_exec('/usr/local/bin/zmpkg.pl *YOUR RUN STATE NAME*');
?>
This successfully works with Tasker! Having it do an HTTP Post to the file with no data passed to it, makes it work. So, the next part is to make it work without having two files! I have one PHP file per needed state.

Here's how the Tasker App is setup:
Profile named "At Home"
Context: Wifi Connected to my home Wifi Router
  • Enter Task:
  • Action Catagory -> Net -> HTTP Post
  • "Server:Port" = YOURIP:PORT
  • "Path" = zm/YOURPHP.php
  • "Timeout" = 30s (this is because Zoneminder takes a little while to set the run state)

    Exit Task:
  • Action Catagory -> Tasker -> Wait
  • "Seconds" = 15 (to allow your phone to sync up with the wireless provider's network, 3G or 4G)
  • Action Catagory -> Net -> HTTP Post
  • "Server:Port" = YOURIP:PORT
  • "Path" = zm/YOURPHP.php
  • "Timeout" = 30s
That should do it!

stuffedmonkey
Posts: 19
Joined: Sat Jan 21, 2017 8:24 pm

Re: Automatically Set States via Tasker for Android (WORKING!)

Post by stuffedmonkey » Sun Jan 29, 2017 12:06 pm

Bumping a very old thread.
If you are still out there @camroidv27, what did acutally happend when you changed the Running state? I do get how im supposed to config ZM to actually change the function of my camera, depending on the running state. Because that must be the goal right? So when I leave home, the running state changes to Away, which in turn changes the function of my cameras to "modect".

Hoping to get this to work since i still use Tasker for pretty much everything that has with automation to do daily.

Cheers guys!

Edit: Nevermind, seems I was to fast in changing states back and fourth. Problably didnt let it save the state before i switched again. Now the function changes with each state. Just need to make the script and add the stuff to Tasker i guess. If anyone has any other good ideas on how to configure zoneminder together with Tasker im all ears! =)

camroidv27
Posts: 35
Joined: Tue Jun 15, 2010 6:18 am

Re: Automatically Set States via Tasker for Android (WORKING!)

Post by camroidv27 » Sat Oct 28, 2017 5:56 am

Glad you got it working-ish? I haven't been using this setup in quite a while... but if I remember correctly, I just told Tasker to "GET" a webpage at the address with the corresponding .php file.

Unfortunately this is a HUGE security risk, as anyone on the outside can then trigger this php file. Hence why I don't use this setup any more. However, there is a lot of documentation on the API from the zoneminder folks on the newer versions page. Maybe someone can write a tasker script with those in mind? Best of luck!

stuffedmonkey
Posts: 19
Joined: Sat Jan 21, 2017 8:24 pm

Re: Automatically Set States via Tasker for Android (WORKING!)

Post by stuffedmonkey » Sun Apr 29, 2018 9:53 am

Im trying to get this setup again somehow. But now the paths doesnt seem to work.
I guess the path /usr/local/bin/ isnt correct for zmpkg.pl any longer?

Anyone have another suggestion on how to solve this? I was hoping to be able to use the short script and then tell Domoticz to send a HTTP Post at certain times to active the MODECT when I activate my alarm.

rockedge
Posts: 1059
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Automatically Set States via Tasker for Android (WORKING!)

Post by rockedge » Tue May 01, 2018 2:03 am

/usr/bin/zmpkg.pl

stuffedmonkey
Posts: 19
Joined: Sat Jan 21, 2017 8:24 pm

Re: Automatically Set States via Tasker for Android (WORKING!)

Post by stuffedmonkey » Tue May 01, 2018 2:04 pm

rockedge wrote:
Tue May 01, 2018 2:03 am
/usr/bin/zmpkg.pl
Thanks. I found that after some digging. Problem is the script doesn't run .

User@zoneminder:/usr/share/zoneminder/www$ ./home.php
./home.php: line 1: ?php: No such file or directory
./home.php: line 2: syntax error near unexpected token `('
./home.php: line 2: `$output = shell_exec('/usr/bin/zmpkg.pl Home');'

Not sure what's wrong.

rockedge
Posts: 1059
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Automatically Set States via Tasker for Android (WORKING!)

Post by rockedge » Tue May 01, 2018 2:51 pm

I ran into this trying to have Darknet/YOLO do object detection on Alarm Frames jpg's. I had to make the PHP shell exec command call a BASH script which started the Darknet analysis of the jpg's sent to it. For some reason I could not use a PHP script to run from the exec command directly but it would work if it called a BASH script. Don't know if any of that will mean anything to you but I am running the scenario you have through the brain matter and troubleshoot this. It should work.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests