Skip to content

Commit

Permalink
Add automations
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Oct 27, 2019
1 parent ba6f4fe commit 27ee5ee
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 26 deletions.
59 changes: 59 additions & 0 deletions documentation/basic/automation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
id: automation
title: Automation
---

Here is a few simple automation examples of what you can do with the data that HACS gives you.

## New repositories added

![auto_ex_2](/img/automation_example2.PNG)

_If you click the link here you will get to the page in HACS for that repository._

```yaml
automation hacs_new_repo:
- alias: Create a notification when somethig is added to HACS
trigger:
platform: event
event_type: hacs/repository
event_data:
action: registration
condition:
condition: template
value_template: "{{ trigger.event.data.repository is defined }}"
action:
service: persistent_notification.create
data_template:
title: New repository in HACS
message: >-
{% set repo = trigger.event.data.repository %}
{% set id = trigger.event.data.repository_id %}
[{{ repo }}](/hacs/repository/{{ id }})
was just added to HACS.
```

## Updates pending

![auto_ex_1](/img/automation_example1.PNG)

```yaml
automation hacs_updates:
- alias: Create a notification when there is updates pending in HACS
trigger:
platform: state
entity_id: sensor.hacs
condition:
- condition: template
value_template: "{{ states(trigger.entity_id) != 'unknown'}}"
- condition: template
value_template: "{{ (states(trigger.entity_id) | float) != 0}}"
action:
service: persistent_notification.create
data_template:
title: Updates pending in HACS
message: >-
{% for repo in state_attr(trigger.entity_id, 'repositories') %}
**{{ repo.display_name }}** _{{ repo["installed version"] }}_ -> _{{ repo["available version"] }}_
{% endfor %}
```
27 changes: 1 addition & 26 deletions documentation/basic/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,4 @@ These events can also be used in automations.
- `hacs/repository`


### Automation example

This will create a new `persistent_notification` every time a new repository is added to HACS.

```yaml
automation:
trigger:
platform: event
event_type: hacs/repository
event_data:
action: registration
action:
service: persistent_notification.create
data_template:
title: New repository in HACS
message: >-
{% set repo = trigger.event.data.repository %}
[{{ repo }}](https://github.com/{{ repo }})
was just added to HACS.
```

This example will give you this notification when something is added to HACS.

![notification](/img/notification.png)

Clicking the link will take you to the GitHub page for that repository.
[Have a look here for automation examples](basic/automation.md)
2 changes: 2 additions & 0 deletions documentation/basic/sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ This will have the number of pending updates as the state.

As attributes ther is a list of objects that you can use for display and/or automations.

[Have a look here for automation examples](basic/automation.md)

![sensor](https://user-images.githubusercontent.com/15093472/59136215-5ff29d00-8982-11e9-860f-75d382a4d3b7.png)
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
"basic/startup",
"basic/sensor",
"basic/events",
"basic/automation",
"basic/theming",
"basic/logs"
],
Expand Down
Binary file added static/img/automation_example1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/automation_example2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed static/img/notification.png
Binary file not shown.

0 comments on commit 27ee5ee

Please sign in to comment.