Update templates

This commit is contained in:
Fabian Affolter 2018-10-29 22:46:30 +01:00
parent fd95a34870
commit c7f8c12303
No known key found for this signature in database
GPG Key ID: E23CD2DD36A4397F

View File

@ -28,6 +28,7 @@ Examples of what you can track:
To enable the history statistics sensor, add the following lines to your `configuration.yaml`:
{% raw %}
```yaml
# Example configuration.yaml entry
sensor:
@ -36,9 +37,10 @@ sensor:
entity_id: light.my_lamp
state: 'on'
type: time
start: '{% raw %}{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}{% endraw %}'
end: '{% raw %}{{ now() }}{% endraw %}'
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
```
{% endraw %}
{% configuration %}
entity_id:
@ -124,50 +126,62 @@ Here are some examples of periods you could work with, and what to write in your
**Today**: starts at 00:00 of the current day and ends right now.
{% raw %}
```yaml
start: '{% raw %}{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}{% endraw %}'
end: '{% raw %}{{ now() }}{% endraw %}'
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
```
{% endraw %}
**Yesterday**: ends today at 00:00, lasts 24 hours.
{% raw %}
```yaml
end: '{% raw %}{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}{% endraw %}'
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
hours: 24
```
{% endraw %}
**This morning (6AM - 11AM)**: starts today at 6, lasts 5 hours.
{% raw %}
```yaml
start: '{% raw %}{{ now().replace(hour=6).replace(minute=0).replace(second=0) }}{% endraw %}'
start: '{{ now().replace(hour=6).replace(minute=0).replace(second=0) }}'
duration:
hours: 5
```
{% endraw %}
**Current week**: starts last Monday at 00:00, ends right now.
Here, last Monday is _today_ as a timestamp, minus 86400 times the current weekday (86400 is the number of seconds in one day, the weekday is 0 on Monday, 6 on Sunday).
{% raw %}
```yaml
start: '{% raw %}{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}{% endraw %}'
end: '{% raw %}{{ now() }}{% endraw %}'
start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
end: '{{ now() }}'
```
{% endraw %}
**Last 30 days**: ends today at 00:00, lasts 30 days. Easy one.
{% raw %}
```yaml
end: '{% raw %}{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}{% endraw %}'
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
days: 30
```
{% endraw %}
**All your history** starts at timestamp = 0, and ends right now.
{% raw %}
```yaml
start: '{% raw %}{{ 0 }}{% endraw %}'
end: '{% raw %}{{ now() }}{% endraw %}'
start: '{{ 0 }}'
end: '{{ now() }}'
```
{% endraw %}
<p class='note'>
The `/dev-template` page of your home-assistant UI can help you check if the values for `start`, `end` or `duration` are correct. If you want to check if your period is right, just click on your component, the `from` and `to` attributes will show the start and end of the period, nicely formatted.