Home Assistant
With rest_command, Home Assistant starts and stops your timer, for example when you enter the office, scan an NFC tag on your desk or press a wall switch. A REST sensor reads the status as a sentence.
- Under Settings, API and devices, add a device of the kind "Other device" and copy the token.
- Put the token into
secrets.yaml, with the word Bearer in front. - Add the commands and the sensor below to
configuration.yamland restart Home Assistant. - Call the commands from automations, scripts or dashboards, for example as the action "RESTful Command: horaka_start".
secrets.yaml:
horaka_auth: "Bearer YOUR_TOKEN"
configuration.yaml:
rest_command:
horaka_start:
url: "https://api.horaka.com/v1/track/start"
method: post
headers:
Authorization: !secret horaka_auth
content_type: "application/json"
payload: '{"project": "PROJECT"}'
horaka_stop:
url: "https://api.horaka.com/v1/track/stop"
method: post
headers:
Authorization: !secret horaka_auth
content_type: "application/json"
payload: "{}"
sensor:
- platform: rest
name: HORAKA today
resource: "https://api.horaka.com/v1/track/status"
headers:
Authorization: !secret horaka_auth
value_template: "{{ value_json.data.running }}"
json_attributes_path: "$.data"
json_attributes: [project, today_seconds, text]
scan_interval: 300
Automation with an NFC tag from the Home Assistant app:
automation:
- alias: Toggle the timer at the desk
trigger:
- platform: tag
tag_id: desk
action:
- service: rest_command.horaka_start
The sensor polls every five minutes; the attribute text is the sentence the shortcut reads aloud as well.