[tasker] Event driven Webhook and "owntracks" device tracker

The main objective was to get an reliable Device Tracker without any extra software besides Tasker.
Based on @Tinkerer’s tasker_hook who also helped to get this working! Thanks again, as so often :sweat_smile:

Either download it via Taskernet Share or save this as Webhook.tsk.xml and import it
06.23
added NFC card support

<TaskerData sr="" dvi="1" tv="5.7.2">
	<Task sr="task25">
		<cdate>1540727507908</cdate>
		<edate>1561301930529</edate>
		<id>25</id>
		<nme>HA Public Webhook</nme>
		<pri>100</pri>
		<Share sr="Share">
			<d>a packed Home Assistant webhook to start automating stuff based on your Android phone!</d>
			<t></t>
		</Share>
		<Action sr="act0" ve="7">
			<code>118</code>
			<label>%HTTPD</label>
			<se>false</se>
			<Str sr="arg0" ve="3">http://wtfismyip.com/text</Str>
			<Str sr="arg1" ve="3"/>
			<Str sr="arg2" ve="3"/>
			<Str sr="arg3" ve="3"/>
			<Str sr="arg4" ve="3"/>
			<Int sr="arg5" val="10"/>
			<Str sr="arg6" ve="3"/>
			<Str sr="arg7" ve="3"/>
			<Int sr="arg8" val="0"/>
		</Action>
		<Action sr="act1" ve="7">
			<code>330</code>
			<Bundle sr="arg0">
				<Vals sr="val">
					<net.dinglisch.android.tasker.RELEVANT_VARIABLES>&lt;StringArray sr=""&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%nfc_id
ID
Unique ID for the tag&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;%nfc_payload
Payload
Contents of the tag in text format&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;%nfc_present
Present
Contents of the tag in text format&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3&gt;%nfc_types()
Types
Type of technologies the card supports&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3&gt;&lt;/StringArray&gt;</net.dinglisch.android.tasker.RELEVANT_VARIABLES>
					<net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>[Ljava.lang.String;</net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>
				</Vals>
			</Bundle>
			<Str sr="arg1" ve="3"/>
			<Str sr="arg2" ve="3"/>
		</Action>
		<Action sr="act2" ve="7">
			<code>37</code>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%HTTPR</lhs>
					<op>3</op>
					<rhs>200</rhs>
				</Condition>
			</ConditionList>
		</Action>
		<Action sr="act3" ve="7">
			<code>30</code>
			<Int sr="arg0" val="650"/>
			<Int sr="arg1" val="0"/>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
		</Action>
		<Action sr="act4" ve="7">
			<code>137</code>
			<Int sr="arg0" val="0"/>
			<Str sr="arg1" ve="3"/>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%AIR</lhs>
					<op>2</op>
					<rhs>on</rhs>
				</Condition>
			</ConditionList>
		</Action>
		<Action sr="act5" ve="7">
			<code>135</code>
			<Int sr="arg0" val="0"/>
			<Int sr="arg1" val="1"/>
			<Str sr="arg2" ve="3"/>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%AIR</lhs>
					<op>2</op>
					<rhs>off</rhs>
				</Condition>
			</ConditionList>
		</Action>
		<Action sr="act6" ve="7">
			<code>38</code>
		</Action>
		<Action sr="act7" ve="7">
			<code>341</code>
			<label>Wifissid</label>
			<se>false</se>
			<Int sr="arg0" val="5"/>
			<Str sr="arg1" ve="3"/>
			<Str sr="arg2" ve="3">%WIFISSID</Str>
		</Action>
		<Action sr="act8" ve="7">
			<code>116</code>
			<se>false</se>
			<Str sr="arg0" ve="3">https://[URL]/api/webhook/UID-WEBHOOK</Str>
			<Str sr="arg1" ve="3"/>
			<Str sr="arg2" ve="3">{
  "trigger": "",
  "trigger2": " ",
  "trigger3": "",
  "nfc_present": "%nfc_present",
  "nfc_id": "%nfc_id",
  "nfc_payload": "%nfc_payload",
  "update_ot": "t",
  "who": "UserUlike",
  "dev_id": "ab_cd_owntracks",
  "device": "ef_whatever",
  "what": "%WIFISSID",
  "when": "%TIME",
  "where_n": "%LOCN",
  "acc_n": "%LOCNACC",
  "g_status": "%GPS",
  "where_g": "%LOC",
  "acc_g": "%LOCACC",
  "alt_g": "%LOCALT",
  "vel_g": "%LOCSPD",
  "battery": "%BATT",
  "ip": "%HTTPD",
  "service": "",
  "entity": "",
  "data": "",
  "ca_in_name": "%CNAME",
  "ca_in_num": "%CNUM",
  "ca_in_date": "%CDATE",
  "ca_in_time": "%CTIME",
  "ca_out_name": "%CONAME",
  "ca_out_num": "%CONUM",
  "ca_out_date": "%CODATE",
  "ca_out_time": "%COTIME",
  "cell_id": "%CELLID",
  "cell_sig": "%CELLSIG",
  "cell_serv": "%CELLSRV",
  "l_app": "%LAPP",
  "n_title": "%NTITLE",
  "screen": "%SCREEN",
  "task_run": "%TRUN",
  "uptime": "%UPS",
  "wifi": "%WIFI",
  "wifissid": "%WIFISSID",
  "win": "%WIN",
  "tasker_caller": "%caller",
  "err": "%err",
  "errmsg": "%errmsg"
}</Str>
			<Str sr="arg3" ve="3"/>
			<Str sr="arg4" ve="3"/>
			<Int sr="arg5" val="120"/>
			<Str sr="arg6" ve="3">application/json</Str>
			<Str sr="arg7" ve="3"/>
			<Int sr="arg8" val="0"/>
		</Action>
		<Img sr="icn" ve="2">
			<cls>org.chromium.webapk.shell_apk.MainActivity</cls>
			<pkg>org.chromium.webapk.a6addecdc2e9a93b8</pkg>
		</Img>
	</Task>
</TaskerData>

I tried to add as many variables as possible to it that you can run whatever you want to do fast and easy. Of cause it’s based on my needs like “device”: “ef_whatever” populates an input_text with the actual IP address of the phone. Keep it or leave it :wink: my complete file is here - the notify.file helps a lot debugging or thinkering

- initial_state: 'on'
  alias: 'Tasker hook'
  trigger:
#     https://www.guidgenerator.com - best to get two strings after each other.
    - platform: webhook
      webhook_id: !secret webhook_id
  action:
    - event: tasker_webhook
      event_data_template:
        id: "{{ trigger.webhook_id }}"
        trigger: "{{ trigger.json.trigger }}"
        trigger2: "{{ trigger.json.trigger2 }}"
        trigger2: "{{ trigger.json.trigger2 }}"
        nfc_present:   "{{ trigger.json.nfc_present }}"
        nfc_id: "{{ trigger.json.nfc_id }}"
        nfc_payload:    "{{ trigger.json.nfc_payload }}"
        update_ot: "{{ trigger.json.update_ot }}"
        who: "{{ trigger.json.who }}"
        dev_id: "{{ trigger.json.dev_id }}"
        device: "{{ trigger.json.device }}"
        what: "{{ trigger.json.what }}"
        when: "{{ trigger.json.when }}"
        where_n: "{{ trigger.json.where_n }}"
        lat_n: "{{ trigger.json.where_n.split(',')[0]  }}"
        long_n: "{{ trigger.json.where_n.split(',')[1]  }}"
        acc_n: "{{ trigger.json.acc_n }}"
        g_status: "{{ trigger.json.g_status }}"
        where_g: "{{ trigger.json.where_g }}"
        lat_g: "{{ trigger.json.where_g.split(',')[0] }}"
        long_g: "{{ trigger.json.where_g.split(',')[1] }}"
        acc_g: "{{ trigger.json.acc_g }}"
        alt_g: "{{ trigger.json.alt_g }}"
        vel_g: "{{ trigger.json.vel_g }} "  
        battery: "{{ trigger.json.battery }}"
        ip: "{{ trigger.json.ip }}"
        service: "{{ trigger.json.service }}"
        entity: "{{ trigger.json.entity }}"
        data: "{{ trigger.json.data }}"
        service2: "{{ trigger.json.service2 }}"
        entity2: "{{ trigger.json.entity2 }}"
        data2: "{{ trigger.json.data2 }}"
        ca_in_name: "{{ trigger.json.ca_in_name }}"
        ca_in_num: "{{ trigger.json.ca_in_num }}"
        ca_in_date: "{{ trigger.json.ca_in_date }}"
        ca_in_time: "{{ trigger.json.ca_in_time }}"
        ca_out_name: "{{ trigger.json.ca_out_name }}"
        ca_out_num: "{{ trigger.json.ca_out_num }}"
        ca_out_date: "{{ trigger.json.ca_out_date }}"
        ca_out_time: "{{ trigger.json.ca_out_time }}"
        l_app: "{{ trigger.json.l_app }}"
        n_title: "{{ trigger.json.n_title }}"
        screen: "{{ trigger.json.screen }}"
        task_run: "{{ trigger.json.task_run }}"
        uptime: "{{ trigger.json.uptime }}"
        wifi: "{{ trigger.json.wifi }}"
        wifissid: "{{ trigger.json.wifissid }}"
        win: "{{ trigger.json.win }}"
        tasker_caller: "{{ trigger.json.tasker_caller }}"
        err: "{{ trigger.json.err }}"
        errmsg: "{{ trigger.json.errmsg }}"


- initial_state: 'on'
  alias: 'Tasker Owntracks.see'
  trigger:
    - platform: event
      event_type: tasker_webhook
      event_data:
        update_ot: t
  action:
    - service: device_tracker.see
      data_template:
        dev_id: "{{ trigger.event.data.dev_id }}"
        gps: 
          - "{{ trigger.event.data.lat_g |float }}"
          - "{{ trigger.event.data.long_g |float }}"
        gps_accuracy: "{{ trigger.event.data.acc_n |int }}"
        battery: "{{ trigger.event.data.battery }}"

I thinking about ditching the device_tracker.see and creating an mqtt payload to get a more “realistic” owntracks component. but atm i`m happy that it works reliable. (ll get an update soon)

Example automation:
My Phone never! makes a sound. Lets outsurce this to Alexa


- initial_state: 'on'
  alias: 'Tasker call in'
  trigger:
    - platform: event
      event_type: tasker_webhook
  condition:
    - condition: time
      after: '07:30:00'
      before: '21:59:00'
    - condition: template
      value_template: "{{ trigger.event.data.when == trigger.event.data.ca_in_time }}"
    - condition: template
      value_template: "{{ trigger.event.data.wifissid == 'myssidname' }}"
    - condition: template
      value_template: "{{ trigger.event.data.device == 'MyPhone' }}"
  action:
    - service: notify.logfile
      data_template:
        message: |-
           Ich bekomme '{{ trigger.event.data.ca_in_name }}'
    - service: script.tts_evet
      data:
        volume: 0.9
#        message: '{{ event.data.ca_in_name }}'
#        this sadly dont work - out of reason I cant follow 
        message: "There is a call"
        type: tts
        delay: '00:00:02'
2 Likes

Good work, like always.