post home assistant update
This commit is contained in:
88
hass_trackers/templates/automation.yaml
Normal file
88
hass_trackers/templates/automation.yaml
Normal file
@@ -0,0 +1,88 @@
|
||||
- alias: 'Counter: Increment {{ item.id }}'
|
||||
description: ''
|
||||
trigger:
|
||||
- platform: time
|
||||
at: 00:00:00
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
metadata: {}
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.days_since_{{ item.id }}
|
||||
mode: single
|
||||
- alias: 'Counter: Reset {{ item.id }}'
|
||||
description: ''
|
||||
trigger:
|
||||
- platform: state
|
||||
entity_id:
|
||||
- input_button.reset_days_since_{{ item.id }}
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.reset
|
||||
metadata: {}
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.days_since_{{ item.id }}
|
||||
mode: single
|
||||
- alias: 'Counter: Update last_non_zero_days_since_{{ item.id }}'
|
||||
description: ''
|
||||
trigger:
|
||||
- platform: state
|
||||
entity_id:
|
||||
- counter.days_since_{{ item.id }}
|
||||
condition:
|
||||
- condition: numeric_state
|
||||
entity_id: counter.days_since_{{ item.id }}
|
||||
above: 0
|
||||
action:
|
||||
- service: counter.increment
|
||||
metadata: {}
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.last_non_zero_days_since_{{ item.id }}
|
||||
mode: single
|
||||
- alias: 'Counter: Reset last_non_zero_days_since_{{ item.id }}'
|
||||
description: ''
|
||||
trigger:
|
||||
- platform: numeric_state
|
||||
entity_id:
|
||||
- counter.days_since_{{ item.id }}
|
||||
above: 0
|
||||
below: 2
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.reset
|
||||
metadata: {}
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.last_non_zero_days_since_{{ item.id }}
|
||||
- service: counter.increment
|
||||
metadata: {}
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.last_non_zero_days_since_{{ item.id }}
|
||||
mode: single
|
||||
- alias: 'Counter: Undo Reset {{ item.id }}'
|
||||
description: ''
|
||||
trigger:
|
||||
- platform: state
|
||||
entity_id:
|
||||
- input_button.undo_reset_days_since_{{ item.id }}
|
||||
condition:
|
||||
- condition: numeric_state
|
||||
entity_id: counter.days_since_{{ item.id }}
|
||||
below: 1
|
||||
action:
|
||||
- service: counter.set_value
|
||||
metadata: {}
|
||||
data:
|
||||
value: "{{ '{{' }} int(states('counter.last_non_zero_days_since_{{ item.id }}')) {{ '}}' }}"
|
||||
target:
|
||||
entity_id: counter.days_since_{{ item.id }}
|
||||
- service: counter.decrement
|
||||
metadata: {}
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.last_non_zero_days_since_{{ item.id }}
|
||||
mode: single
|
||||
12
hass_trackers/templates/counter.yaml
Normal file
12
hass_trackers/templates/counter.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
days_since_{{ item.id }}:
|
||||
name: Days Since {{ item.name }}
|
||||
restore: true
|
||||
initial: 0
|
||||
step: 1
|
||||
icon: {{ item.icon }}
|
||||
last_non_zero_days_since_{{ item.id }}:
|
||||
name: Last Non-Zero Days Since {{ item.name }}
|
||||
restore: true
|
||||
initial: 0
|
||||
step: 1
|
||||
icon: mdi:undo
|
||||
54
hass_trackers/templates/dashboard.yaml
Normal file
54
hass_trackers/templates/dashboard.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
type: grid
|
||||
square: false
|
||||
columns: 1
|
||||
cards:
|
||||
- type: markdown
|
||||
content: >
|
||||
{{ '{%' }} set trackers = [
|
||||
{% for item in trackers -%}
|
||||
{
|
||||
"counter": states("counter.days_since_{{ item.id }}") | int,
|
||||
"threshold": state_attr("binary_sensor.threshold_for_days_since_{{ item.id }}", "upper"),
|
||||
"percent": (int(states("counter.days_since_{{ item.id }}")) / state_attr("binary_sensor.threshold_for_days_since_{{ item.id }}", "upper")),
|
||||
"name": "{{ item.name }}"
|
||||
},
|
||||
{% endfor -%}
|
||||
]{{ '%} ' }}
|
||||
|
||||
{% raw %}
|
||||
{% for tracker in (trackers | sort(reverse=true, attribute='percent')) %}
|
||||
{% set days_left = ((tracker.threshold - tracker.counter) | int | string) %}
|
||||
{% set message = tracker.name + " completed " + tracker.counter | string + " days ago. Due again in " + days_left + " days." %}
|
||||
{% if tracker.percent > 1 %}
|
||||
<ha-alert alert-type="error">{{ message }}</ha-alert>
|
||||
{% elif tracker.percent > 0.8 %}
|
||||
<ha-alert alert-type="warning">{{ message }}</ha-alert>
|
||||
{% else %}
|
||||
<ha-alert alert-type="success">{{ message }}</ha-alert>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{%- endraw %}
|
||||
{% for item in trackers %}
|
||||
|
||||
- type: grid
|
||||
square: false
|
||||
columns: 2
|
||||
title: Days Since {{ item.name }}
|
||||
cards:
|
||||
- type: button
|
||||
name: Reset
|
||||
entity: input_button.reset_days_since_{{ item.id }}
|
||||
tap_action:
|
||||
action: toggle
|
||||
- type: button
|
||||
entity: input_button.undo_reset_days_since_{{ item.id }}
|
||||
name: Undo
|
||||
tap_action:
|
||||
action: toggle
|
||||
- type: entity
|
||||
entity: counter.days_since_{{ item.id }}
|
||||
name: Days Since
|
||||
- type: entity
|
||||
entity: counter.last_non_zero_days_since_{{ item.id }}
|
||||
name: Last Non-Zero
|
||||
{% endfor %}
|
||||
6
hass_trackers/templates/input_button.yaml
Normal file
6
hass_trackers/templates/input_button.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
reset_days_since_{{ item.id }}:
|
||||
name: Reset {{ item.name }}
|
||||
icon: {{ item.icon }}
|
||||
undo_reset_days_since_{{ item.id }}:
|
||||
name: Undo Reset {{ item.name }}
|
||||
icon: mdi:undo
|
||||
4
hass_trackers/templates/threshold.yaml
Normal file
4
hass_trackers/templates/threshold.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
- platform: threshold
|
||||
entity_id: counter.days_since_{{ item.id }}
|
||||
upper: {{ item.check_every }}
|
||||
name: threshold_for_days_since_{{ item.id }}
|
||||
Reference in New Issue
Block a user