ISY-99i Series INSTEON:Networking:Tasker

From Universal Devices, Inc. Wiki
Revision as of 18:16, 7 February 2018 by Mkohanim (Talk | contribs) (Network Awareness)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

To push device and scene state from ISY to Tasker - please see this [[1]]

This page is a work in progress!

Network Awareness

First, it is helpful if Tasker can use the HTTP interface when on the same network, and HTTPS when not. This should probably not be used for geofencing your home - as Android devices will sleep and disconnect sometimes. This set of tasks and profile is simply so that Tasker has a reliable way to call the ISY API...

Once you have installed Tasker, perform the following steps:

Click the three dots top-right - and select 'Preferences'
Uncheck 'Beginner Mode'
Set the 'Theme' to 'Dark' (saves battery!)
Hit 'Back' (gear icon in the top-left of screen)

Now, let's create the first task, step by step: (CaSe is important)

Click the 'Tasks' tab (top of screen)
Click + (bottom right of screen)
Set the task name to 'Home-On-Net' and touch the check-mark
Click the + bottom center of screen
In the 'Filter', type 'variable. Scroll and select 'Variable Set'
In the 'Name' box, type '%IsyUrl'
In to 'To' box, type '%IsyUrlInternal'
Hit 'Back' (gear icon in the top-left of screen)
Click the + bottom center of screen
In the 'Filter', type 'variable. Scroll and select 'Variable Set'
In the 'Name' box, type '%URLPrefix'
In to 'To' box, type '/'
Hit 'Back' (gear icon in the top-left of screen)
Hit 'Back' again (gear icon in the top-left of screen) to return to the list of tasks..

SetInternalURL.png Home-On-Net.png Home-on-net.png


Now, let's create the second task, step by step: (CaSe is important)

From the 'Tasks' tab...
Click + (bottom right of screen)
Set the task name to 'Home-Off-Net' and touch the check-mark
Click the + bottom center of screen
In the 'Filter', type 'variable. Scroll and select 'Variable Set'
In the 'Name' box, type '%IsyUrl'
In to 'To' box, type '%IsyUrlExternal'
Hit 'Back' (gear icon in the top-left of screen)
Click the + bottom center of screen
In the 'Filter', type 'variable. Scroll and select 'Variable Set'
In the 'Name' box, type '%URLPrefix'
If NOT using ISY Portal:
  In to 'To' box, type '/'
If you ARE using ISY Portal:
  In to 'To' box, type '/isy/<secure_isy_id>' (get the ID from 'Tools' / 'Information' / 'ISY Information' in my.isy.io. It's the 'Path to ISY' URL component)


Hit 'Back' (gear icon in the top-left of screen)
Hit 'Back' again (gear icon in the top-left of screen) to return to the list of tasks..

SetExternalURL.png Home-Off-Net.png Off-net-2.png

After creating the tasks above, the Tasks tab should look like this:

Tasks.png

Now, lets set a couple of variables...

Click the 'VARS' tab (top of screen)
Near the bottom of the screen - if you don't see buttons labeled 'Indexed' and 'Empty', click the ^ in the far bottom-right.
Ensure 'Empty' is lit up...  if not, click the 'Empty' button to display empty variables
You should see the '%IsyUrl' '%IsyUrlExternal' and '%IsyUrlInternal' variables
Touch '%IsyUrlInternal' and enter the internal URL (in the format 'http://user:password@192.168.1.3'). Touch the check to save
Touch '%IsyUrlExternal' and enter the external URL for your ISY (or Portal URL), and save it.
   Internal: http://user:password@192.168.1.3
   External direct to ISY: https://username:password@myisy.dyndns.org
   External Via Portal: https://username:password@my.isy.io

If you use the ISY Portal - you might have to URL encode the username (since it has a @ in it). @ encodes to %40. Test without encoding first.

Leave '%IsyUrl' blank..

At this point, your variables should look like this (Except of course the correct IP address, external URL, username and password entries are used!. The left image is if you are connecting directly - and the second one is if you are connecting via ISY Portal):

TaskerVars.png 8da82b0e-ddc1-4056-8374-4773944d221e.png

Exit Tasker and re-launch (This is to save the tasks - so we can create profiles that refer to them)

Now, let's create the first profile:

Click the 'Profile' tab
Click the + bottom-right
Click on 'State'
In the 'Filter' - type 'wifi'
Touch 'Wifi Connected'
Next to 'SSID' - touch the magnifier.
 Select the SSID of your home network - where the ISY is. If you have more than one SSID - select each in turn until they are all added
Next to 'MAC' - touch the magnifier.
 Select the Mac of your home network - where the ISY is. If you have more than one - select each in turn until they are all added
 (It's important to use the MAC as well as the SSID - so your device does not treat a spoofed SSID as your home network - and switch to no SSL..)
Hit 'Back' (gear icon in the top-left of screen) 
You are prompted to select the entry task...  touch 'Home-On-Net'
In the list - touch and hold 'Home-On-Net'. From the popup menu, touch 'Add Exit Task'
Touch 'Home-Off-Net'
Touch and hold the profile name. Click the 'A' icon at the top of the screen
Set the name to 'On Home Network', and hit the check.
Hit the Android back button - Tasker should exit.

The profile tab should look like this when done:

Profile.png

The profile name is green when it's active...

At this point - if you drop the Android notifier, you should see a Tasker notification proclaiming 'On Home Network'. Click it - Tasker will open. Click the 'Vars' tab, you should see that %IsyUrl has been set to the internal URL..

Base task dependencies

Before you complete this step - please complete the steps outlined in 'Network Awareness' section.

Let's create the first 'meta' task... These tasks are called by other processes to utilize the ISY API.

From the 'Tasks' tab...
Click + (bottom right of screen)
Set the task name to 'ISY-SetVarState' and touch the check-mark
4f350644-db6a-4e18-b677-1737ac50756c.png Click+.png SetName.png

Click the + bottom center of screen
In the 'Filter', type 'http'
Touch 'HTTP Get'
8b6c55e9-ca2b-44a1-8329-433dc375a1d7.png Da1511e9-ad72-4e81-a289-2a4691ed1aed.png SelectAction.png NewStepStart.png

In the 'Server:Port' box, touch the 'Tag' and select '%IsyUrl'
In to 'Path' box, type '%URLPrefix/rest/vars/set/2/%par1/%par2'
If you are using a self-signed certificate on your ISY (and not the portal) - scroll down and check 'Trust Any Certificate'
Hit 'Back' (gear icon in the top-left of screen)
Hit 'Back' again (gear icon in the top-left of screen) to return to the list of tasks..
NewStepFilled.png 80ac6ae9-0963-4c9d-aaad-af14e0267517.png BackAfterAdding.png Addmetafinal.png

Now - use the above process to create these additional 'meta-tasks':

ISY-SetVarInteger	'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/vars/set/1/%par1/%par2'
ISY-RunIf		'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/programs/%par1/run'
ISY-RunThen		'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/programs/%par1/runThen'
ISY-RunElse		'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/programs/%par1/runElse'
ISY-SceneOn		'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/nodes/%par1/cmd/DON'
ISY-SceneOff		'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/nodes/%par1/cmd/DOF'
ISY-ExecNet		'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/networking/resources/%par1'
ISY-WOL			'Net' 'HTTP Get' / Server:Port = '%IsyUrl' / Path = '%URLPrefix/rest/networking/wol/%par1'

In-Car Detection

First - the steps outlined in 'Network Awareness' and 'Base Task Dependencies' must be completed.

I've found the most reliable way to do in-car detection is bluetooth. Either to your cars built-in bluetooth - or using a device like a ZUS (http://www.amazon.com/gp/product/B015F34P1Q) or any other bluetooth device plugged into the accessory outlet.

First, create a 'State Variable' on the ISY called 'In Car'. Set it's 'init' value to 2. Make a note of it's ID number. For purposes of example, I'm going to say mine is 23.

Create two tasks (follow the steps in the second box of Network Awareness') using data in this table:

ISY-Set-Car-Enter		Perform Task / ISY-SetVarState	%par1=23 %par2=1
C64c9e1d-6e13-416b-bdf4-0d3cb4e0deb8.png 9d97def2-5699-4cee-a989-ba469b782f0c.png

ISY-Set-Car-Exit		Perform Task / ISY-SetVarState	%par1=23 %par2=0
A15deeb3-0d09-497f-bf05-822f0159a620.png B746056c-7921-42d0-84f4-65ddca102b47.png

Now, pair your phone with the bluetooth device. This is necessary to cause your phone to automatically connect when the device powers up (in your car).

In Tasker, add a 'State' profile.

Car1.png Car2.png Car3.png

In the filter, type 'BT' and then select 'BT Connected'

Car4.png Car5.png

For the 'Name', click the magnifying glass and select your bluetooth device.

A23b420b4-4086-4294-bb3f-e4048cb0b220.png Bf353a127-09ef-4b7f-a74e-9c51902a95ae.png

For the 'Address', click the magnifying glass and select the same bluetooth device as for the name.

Ca9390bf9-f69e-477b-a1a1-4d30a7a099c5.png Dbfbbbd8b-983b-462f-80de-9ac38287bac5.png

Hit 'Back' and select 'ISY-Set-Car-Enter' as the task to run.

Eee039e54-7903-44bd-b75a-8ef28a995ea2.png Fd663e2fb-0435-409c-8825-9c82cdbaecf0.png

In the profile list, long-press the 'ISY-Set-Car-Enter' task, and select 'Add Exit Task' select 'ISY-Set-Car-Exit' as the task to run when exiting the car.

Ifed91dde-fc28-4e8b-a4c6-1f2df868a735.png G33de5b11-2f8b-44b5-a4a9-8ae77f6c9ac4.png H9e56b8f7-2ed6-4b57-ae30-caa1440356b6.png

Manually run the 'ISY-Set-Car-Exit' task the first time (while not in the car!), and verify the 'In Car' variable changes from '2' to '0'.

Geofencing

For effective geo-fencing on Android - add the AutoLocation module to Tasker (https://play.google.com/store/apps/details?id=com.joaomgcd.autolocation). After 7 days, you'll have to buy the unlock key (https://play.google.com/store/apps/details?id=com.joaomgcd.autolocation.unlock). If your phone supports it - this hooks into the hardware based geofencing that newer Android devices have.

Again - the steps outlined in 'Network Awareness' and 'Base Task Dependencies' must be completed before this section. They not only setup prerequisites - but they also server as a tutorial on adding 'Tasks' and 'Profiles' to ISY.

First - ensure the Autolocation Geofence monitor is set to run on boot:

Create a 'task' called 'Start Geofence'
In the filter, type 'autolocation' and select 'AutoLocation Geofences'
Click the 'Configuration'
Click 'Geofence Monitor'
Select 'Start'
Click the 'Check' to accept..
click 'Back' to return to the list, and then back again.
Create a 'Profile' by clicking +
Select 'Event'
In the filter, type 'device' and select 'Device Boot'
There are no options to configure for this event, so hit 'Back'
Select the 'Start Geofence' task you just created.

This will cause the geofence monitor to start when the Android device starts.


Now, create a 'State Variable' on the ISY called 'At Work'. Set it's 'init' value to 2. Make a note of it's ID number. For purposes of example, I'm going to say mine is 28.

Create two tasks:

ISY-Set-Work-Arrive		Perform Task / ISY-SetVarState	%par1=28 %par2=1
ISY-Set-Work-Leave		Perform Task / ISY-SetVarState	%par1=28 %par2=0

Configure a geofence in AutoLocation

Open 'AutoLocation' and click 'Manage Geofences'
Click + to add a new Geofence
In the map, select the center of the location you wish to fence.. 
Adjust the size of the fenced area with the slider, and then click 'Accept Geofence'.
Give it a name - 'Work'.

Back on the list - Autolocation will tack on 'Inside' or 'Outside' as appropriate..
Click 'Start Monitor' under the 'GEOFENCES' section..

Finally, create the Tasker profile that ties it all together:

Create a new profile:
'State' 'Autolocation Geofences'
For 'Configuration', select the 'Geofence Name' 'Work'.
For 'Status' - select 'Inside'
Click the 'Check' then hit 'Back'
select 'ISY-Set-Work-Arrive' as the task to run on entering the geofence.
In the profile list, long-press the 'ISY-Set-Work-Arrive' task, and select 'Add Exit Task'
select 'ISY-Set-Work-Leave' as the task to run when exiting the geofence.

Device Toggles

Again - the steps outlined in 'Network Awareness' and 'Base Task Dependencies' must be completed before this section. They not only setup prerequisites - but they also server as a tutorial on adding 'Tasks' and 'Profiles' to ISY.

On my ISY - I have a device (a Switchlinc) called 'Dining Room Overhead' - and it's in a folder 'Main / Dining /' I also have a scene 'SC - Dining Room Overhead' in folder 'Main / '. The Switchlinc is a controller of the scene - and is also the switchlinc attached to the load. There are other Switchlincs in the scene.

The goal is to have a task on Tasker that simply toggles the state of the light - without having to know the current state. I do this with a DISABLED program on ISY (so it does not trigger on any element of the IF clause) and have the IF branch based on the current state..

On ISY, create a DISABLED program like the following:

If
        Status  'Main / Dining / Dining Room Overhead' is not Off
Then
        Set Scene 'Main / SC - Dining Room Overhead' Off
Else
        Set Scene 'Main / SC - Dining Room Overhead' On

Test the program by manually performing a 'RunIF' - and abserving the light toggle - with all scene controllers and responders staying in sync.

Over on the program summary tab, make a note of the Program ID (in my case - 01D0).

On Tasker, create the following task:

ISY-DiningRoom-Toggle	Perform Task / ISY-RunIf	%par1=01D0

...and test. Each run of the task toggles the light on and off.

Retrieving ISY Variables into a Tasker variable

See this page for details of how to do this.