Skip to content

Commit

Permalink
Improvements to the EventGhost configuration
Browse files Browse the repository at this point in the history
Use a bearer token for communications between EventGhost and Home Assistant.
Listen for more consistent events when deciding computer activity.

Closes #54 and #55
  • Loading branch information
anton-johansson committed Dec 10, 2018
1 parent bcd71e9 commit efd4382
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ The configuration for my home tools, such as Home Assistant.
Some files needs to be created in order for everything to run properly.

```shell
echo "<redacted>" | tee /home/$USER/home/home-assistant/bearer-tokens/prometheus
echo "<redacted>" | tee /home/$USER/home/home-assistant/bearer-token
```

## Running home tools
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Expand Up @@ -215,7 +215,7 @@ services:
- prometheus-net
volumes:
- /home/$USER/home/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml:ro
- /home/$USER/home/home-assistant/bearer-tokens/prometheus:/etc/prometheus/home-assistant-bearer-token:ro
- /home/$USER/home/home-assistant/bearer-token:/etc/prometheus/home-assistant-bearer-token:ro
- prometheus-data:/prometheus
labels:
traefik.enable: "true"
Expand Down
1 change: 1 addition & 0 deletions home-assistant/.gitignore
Expand Up @@ -14,3 +14,4 @@
/downloads/
/.google.token
/.storage/
/bearer-token
1 change: 0 additions & 1 deletion home-assistant/bearer-tokens/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions home-assistant/bearer-tokens/README.md

This file was deleted.

Expand Up @@ -6,3 +6,8 @@ EventGhost is used to send activity statuses to Home Assistant.
## Download and installation

You'll find the download page [here](http://www.eventghost.net/downloads/).


## Configuration

After the configuration has been imported, you must go to `Autostart`, then `Set globals`. Configure this item, and update the Home Assistant URL and Bearer Token values.
@@ -1,35 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1722" Guid="{13730AC3-1E50-4877-BE08-567B3E8B9E2F}" Time="1541185107.43">
<EventGhost Version="1722" Guid="{3FE0B20B-05B2-43B0-A7A1-DEF50B73B252}" Time="1544467184.08">
<Autostart Name="Autostart">
<Plugin Identifier="Task" Guid="{D1748551-C605-4423-B392-FB77E6842437}" File="Task">
gAIpLg==
</Plugin>
<Action>
EventGhost.PythonScript(u'homeAssistantURL = "{homeAssistantURL}"\nhomeAssistantPassword = "{homeAssistantPassword}"\n\nsetattr(eg.globals, "homeAssistantURL", homeAssistantURL)\nsetattr(eg.globals, "homeAssistantPassword", homeAssistantPassword)')
<Action Name="Set globals">
EventGhost.PythonScript(u'homeAssistantURL = "{homeAssistantURL}"\nhomeAssistantBearerToken = "{homeAssistantBearerToken}"\n\nsetattr(eg.globals, "homeAssistantURL", homeAssistantURL)\nsetattr(eg.globals, "homeAssistantBearerToken", homeAssistantBearerToken)')
</Action>
</Autostart>
<Macro Name="Start Overwatch">
<Event Name="Task.Activated.Overwatch" />
<Action Name="Update HA">
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantPassword = getattr(eg.globals, "homeAssistantPassword")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc?api_password=" + homeAssistantPassword\nheaders = {\'content-type\': \'application/json\'}\ndata = \'{"state": true, "attributes": {"hidden": true, "focus": "overwatch"}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantBearerToken = getattr(eg.globals, "homeAssistantBearerToken")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc"\nheaders = {}\nheaders["Content-Type"] = "application/json"\nheaders["Authorization"] = "Bearer " + homeAssistantBearerToken\ndata = \'{"state": true, "attributes": {"hidden": true, "focus": "overwatch"}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
</Action>
</Macro>
<Macro Name="Stop Overwatch">
<Event Name="Task.Deactivated.Overwatch" />
<Action Name="Update HA">
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantPassword = getattr(eg.globals, "homeAssistantPassword")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc?api_password=" + homeAssistantPassword\nheaders = {\'content-type\': \'application/json\'}\ndata = \'{"state": true, "attributes": {"hidden": true, "focus": ""}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantBearerToken = getattr(eg.globals, "homeAssistantBearerToken")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc"\nheaders = {}\nheaders["Content-Type"] = "application/json"\nheaders["Authorization"] = "Bearer " + homeAssistantBearerToken\ndata = \'{"state": true, "attributes": {"hidden": true, "focus": ""}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
</Action>
</Macro>
<Macro Name="Lock/Idle Windows">
<Event Name="Task.Activated.LockApp" />
<Event Name="System.SessionLock" />
<Action Name="Update HA">
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantPassword = getattr(eg.globals, "homeAssistantPassword")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc?api_password=" + homeAssistantPassword\nheaders = {\'content-type\': \'application/json\'}\ndata = \'{"state": false, "attributes": {"hidden": true, "focus": ""}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantBearerToken = getattr(eg.globals, "homeAssistantBearerToken")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc"\nheaders = {}\nheaders["Content-Type"] = "application/json"\nheaders["Authorization"] = "Bearer " + homeAssistantBearerToken\n\ndata = \'{"state": false, "attributes": {"hidden": true, "focus": ""}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
</Action>
</Macro>
<Macro Name="Unlock/Unldle Windows">
<Event Name="Task.Deactivated.LockApp" />
<Event Name="System.SessionUnlock" />
<Action Name="Update HA">
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantPassword = getattr(eg.globals, "homeAssistantPassword")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc?api_password=" + homeAssistantPassword\nheaders = {\'content-type\': \'application/json\'}\ndata = \'{"state": true, "attributes": {"hidden": true, "focus": ""}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
EventGhost.PythonScript(u'import requests\n\nhomeAssistantURL = getattr(eg.globals, "homeAssistantURL")\nhomeAssistantBearerToken = getattr(eg.globals, "homeAssistantBearerToken")\n\nurl = homeAssistantURL + "/api/states/computer_activity.gaming_pc"\nheaders = {}\nheaders["Content-Type"] = "application/json"\nheaders["Authorization"] = "Bearer " + homeAssistantBearerToken\ndata = \'{"state": true, "attributes": {"hidden": true, "focus": ""}}\'\nresponse = requests.post(url, data, headers=headers, verify=False)\nprint(response.text)')
</Action>
</Macro>
</EventGhost>

0 comments on commit efd4382

Please sign in to comment.