Hi, I done my personal LinkTap Integration without AppDaemon and is more “direct”. Works (I tested) with only 1 LinkTap Device and restore the previous program when finished (See “autoBack” in the API https://www.link-tap.com/#!/api-for-developers)
NOTE: With the LinkTap API there is a limit for polling. Can toggle the switch only every 1 minute and can update the sensor only every 5 minutes. The sensor automatically update every 6 minutes AND 5 seconds after the switch toggle, so if you enable the toggle and 2 minutes later the automatic scan will be triggered, API return an error, so i forced the “on” status if error. Anyway after 6 or 12 minutes the correct status will be restored. I already wrote to the LinkTap support for request less time of device status polling time. LinkTap support tell me that soon will be a local LAN API support.
In “configuration.yaml” add the package and customizations support:
homeassistant:
[....... Your Things .......]
# Customizations
customize: !include customize.yaml
# Packages
packages: !include_dir_named packages
Add folder “packages” and create into it “linktap.yaml” with this lines:
!!! Change values between “…” with your User, API Key ecc… !!!
# LinkTap Package
# Inputs
input_number:
linktap_duration:
name: 'Duration'
icon: mdi:clock
min: 5
max: 150
step: 5
# Switches
switch:
- platform: template
switches:
linktap_sprinkler:
friendly_name: 'Sprinkler'
value_template: '{{ is_state("binary_sensor.linktap_status","on") }}'
turn_on:
service: script.linktap_on
turn_off:
service: script.linktap_off
# Binary Sensors
binary_sensor:
- platform: rest
name: 'LinkTap Status'
verify_ssl: true
scan_interval: 360
resource: https://www.link-tap.com/api/getAllDevices
method: POST
payload: '{"username": "USER", "apiKey": "APIKEY"}'
value_template: >-
{% if value_json.result == 'ok' %}
{% if value_json.devices[0].taplinker[0].plan.action %}
true
{% else %}
false
{% endif %}
{% elif value_json.result == 'error' %}
true
{% else %}
false
{% endif %}
headers:
User-Agent: Home Assistant
Content-Type: application/json
# REST Commands
rest_command:
linktap_on:
verify_ssl: true
timeout: 10
url: https://www.link-tap.com/api/activateInstantMode
method: POST
payload: '{"username": "USER", "apiKey": "APIKEY", "gatewayId": "GATEWAYID", "taplinkerId": "TAPLINKERID", "action": "true", "duration": {{ states.input_number.linktap_duration.state }}, "autoBack": "true"}'
content_type: 'application/json; charset=utf-8'
headers:
User-Agent: Home Assistant
Content-Type: application/json
linktap_off:
verify_ssl: true
timeout: 10
url: https://www.link-tap.com/api/activateInstantMode
method: POST
payload: '{"username": "USER", "apiKey": "APIKEY", "gatewayId": "GATEWAYID", "taplinkerId": "TAPLINKERID", "action": "false", "duration": 0, "autoBack": "true"}'
content_type: 'application/json; charset=utf-8'
headers:
User-Agent: Home Assistant
Content-Type: application/json
# Scripts
script:
linktap_on:
alias: 'Activate LinkTap'
sequence:
- service: rest_command.linktap_on
- delay: '00:00:05'
- service: homeassistant.update_entity
entity_id: binary_sensor.linktap_status
linktap_off:
alias: 'Deactivate LinkTap'
sequence:
- service: rest_command.linktap_off
- delay: '00:00:05'
- service: homeassistant.update_entity
entity_id: binary_sensor.linktap_status
linktap_update:
alias: 'Update LinkTap'
sequence:
- service: homeassistant.update_entity
entity_id: binary_sensor.linktap_status
And in “customize.yaml” add:
# LinkTap
script.linktap_update:
hidden: false
friendly_name: 'Update'
icon: mdi:sync
The result (In my language, Italian) is:
I hope can be useful for someone !