need advice on creating macro that triger exe on windows pc

mmoalem

New member
Hi all - just came across macrodroid in my quest to automate my cctv software.

What I want to achive is that when I am at home (while my phone is connected to my home wifi) the phone "sends" a message to a windows pc that runs agentDVR software to keep the inside cameras off - and when I leave the house (not connected to the home wifi) to send messege to turn cameras on.
I assume i can achive this through http request for action (trigger be time intervale of few minutes and contrain be wifi connection), I also have batch files to turn on and off the camera on the windows pc and thats about it...
any advice on bridging the two will be great
 

RSF

Well-known member
Looks like agentDVR has an API that MacroDroid could access via http calls, assuming your phone is on that same network as the PC.

You'll need the IP address of the PC on your home network, and the port the agentDVR software was configured to use. Per that API documentation, you can issue commands by sending them to
http://IPADDRESS:pORT/command.cgi?cmd=COMMAND&ot=OBJECT_TYPE&oid=OBJECT_ID
You can also use a group ID to group all your cameras in agentDVR-- that might be easier than issuing a series of commands to multiple cameras.

For example, if your PC's IP is 1.2.3.4, with port = 8090 (the default), and you created an agentDVR group called "inside" for all the cameras you want to control ... to turn off all inside cameras something like this should work in MacroDroid:
Screenshot 2023-03-29 4.14.07 PM.png

The full scheme in MacroDroid would be:
Triggers:
  • Connectivity / Wifi State Change / Connected to network / (your network SSID)
  • Connectivity / Wifi State Change / Disconnected from network / (your network SSID)
Actions:
If the 1st trigger is fired, issue the HTTP call above
else if the 2nd trigger is fired, issue a different HTTP call to turn agentDVR recording back on.

I don't think there's a need for timers.

Regarding your mention of batch files ... I don't think there's a way to invoke a PC-based batch file from MacroDroid.
 

Qarboz

Well-known member
  • Connectivity / Wifi State Change / Connected to network / (your network SSID)
  • Connectivity / Wifi State Change / Disconnected from network / (your network SSID)

When the phone connects to the WiFi everything is ok; but when it disconnects, the phone is no longer in the same network and it becomes more complicated to issue the command to the DVR. I'm not familiar with networking, but I think that at home you need to have internet connectivity with a fixed IP (or use a dyndns service) and when the phone is disconnected from WiFi, create a VPN between the phone and the home network and launch the command.
I think it's easier to use an old smartphone with MacroDroid installed, to keep at home that receives commands from the other smartphone (via webhook, SMS, email, etc.) to control the DVR, IMHO
 

mmoalem

New member
Thank you both for the replies. Indeed the main problem with this is when I am away and not on the same network. I could open a port but that to the ouside but that is a big security risk unless there is a way for the port to filter all traffich but the two possible urls used for the commands which I am not aware of. I will look at a vpn solution as I am not sure how to make this work (only used vpn as a bridge rather an end in itself)

I am aware the home assistant can execute a batch file and can listen to calls from IFTTT and Tasker but it seems overkill as I will need to run it in a virtualbox which will take too many resources from my PC.

AutoHotKey can also listen to HTTP request but again the is the security risk of leaving a port open.

At the moments I think I have some kind of solution which I am exploring... The most secure system would ideally be something like - When triggered Macrodroid marks something online - lets say post a tweet phrased in a certain way and than the windows PC has s a tweater reader than can identify when that certain tweet is sent and execute command localy (or Telegram, whatsapp etc) - that way the PC has no open ports. I believe that AutoHotKey can achive that but I need to delve deeper into how to do it exactly.

BTW whats the most frustrating thing is that the simplest solution (which I currently use) is problematic because of my phone brand... I basically ping my phone's local ip every few minutes - get response - I'm in - keep the camera off - no response - I'm out - keep camera on BUT Samsung phones seem to have an issue with responding to ping when asleep...
 

Jacob L

Moderator (Lawsonator)
Maybe you have an old Android device, you can set variables from multiple devices to the spare one and then use the old device to communicate with the cameras
 

mmoalem

New member
ok, got a little further with slight change of direction - found an autohotkey script that can read messages on tlk.io so if post a message in my tlk.io chat room it will read it and execute accordingly on the controled PC.

So now I am back at Macrodroid trying to figure out how to post a message on tlk.io as an action... if anyone can help me figure this out it will be truly appreciated
 

Endercraft

Moderator (& bug finder :D)
ok, got a little further with slight change of direction - found an autohotkey script that can read messages on tlk.io so if post a message in my tlk.io chat room it will read it and execute accordingly on the controled PC.

So now I am back at Macrodroid trying to figure out how to post a message on tlk.io as an action... if anyone can help me figure this out it will be truly appreciated
Does AutoHotKey have a notification listener ? Then you could use ntfy.sh
 

paps93fr

New member
with this is when I am away and not on the same network. I could open a port but that to the ouside but that is a big security risk unless there is a way for the port to filter all traffich but the two possible urls used for the commands which I am not aware of.
...
When triggered Macrodroid marks something online - lets say post a tweet phrased in a certain way and than the windows PC has s a tweater reader than can identify when that certain tweet is sent and execute command localy (or Telegram, whatsapp etc)
...
ok, got a little further with slight change of direction - found an autohotkey script that can read messages on tlk.io so if post a message in my tlk.io chat room it will read it and execute accordingly on the controled PC.

Do you really think publishing your status telling you're in or outside your home on any social network is more secure than opening a port on your box/router and on your PC ?

You must try to find a solution like VPN to link your devices and exchange information privately.
 

mmoalem

New member
thanks all for the advice - I have now found a working solution.

In case anyone reach this thread with the same issue this is my solution:

1. Set Macrodroid to send email to an outlook email you use. I use keywrods in the subject so I set it that when I enter home area (triggered by geofence) it send enail with keyword 1 in subject and when I exit the area it send email with keyword 2 in the subject.

2 On the windows PC I use Outlook and VBA - In outlook I created a rule that run a VBA script whenever a new email with keyword 1 in its subject arrives - this script send a command line that sets agentDVR camera on (or off) - and anotehr rule for keyword 2 that runs a 2nd script for the opposite effect.

The main issue in this setup is that there is letancy between entry/exit of the area until the email is sent, recieved in the other end and than executed so its not a good solution for low letancy control of the windows PC BUT for my needs of turning a camera on or off it is not a problem
 
Top