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`: To enable the history statistics sensor, add the following lines to your `configuration.yaml`:
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
sensor: sensor:
@ -36,9 +37,10 @@ sensor:
entity_id: light.my_lamp entity_id: light.my_lamp
state: 'on' state: 'on'
type: time type: time
start: '{% raw %}{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}{% endraw %}' start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{% raw %}{{ now() }}{% endraw %}' end: '{{ now() }}'
``` ```
{% endraw %}
{% configuration %} {% configuration %}
entity_id: 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. **Today**: starts at 00:00 of the current day and ends right now.
{% raw %}
```yaml ```yaml
start: '{% raw %}{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}{% endraw %}' start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{% raw %}{{ now() }}{% endraw %}' end: '{{ now() }}'
``` ```
{% endraw %}
**Yesterday**: ends today at 00:00, lasts 24 hours. **Yesterday**: ends today at 00:00, lasts 24 hours.
{% raw %}
```yaml ```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: duration:
hours: 24 hours: 24
``` ```
{% endraw %}
**This morning (6AM - 11AM)**: starts today at 6, lasts 5 hours. **This morning (6AM - 11AM)**: starts today at 6, lasts 5 hours.
{% raw %}
```yaml ```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: duration:
hours: 5 hours: 5
``` ```
{% endraw %}
**Current week**: starts last Monday at 00:00, ends right now. **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). 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 ```yaml
start: '{% raw %}{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}{% endraw %}' start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
end: '{% raw %}{{ now() }}{% endraw %}' end: '{{ now() }}'
``` ```
{% endraw %}
**Last 30 days**: ends today at 00:00, lasts 30 days. Easy one. **Last 30 days**: ends today at 00:00, lasts 30 days. Easy one.
{% raw %}
```yaml ```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: duration:
days: 30 days: 30
``` ```
{% endraw %}
**All your history** starts at timestamp = 0, and ends right now. **All your history** starts at timestamp = 0, and ends right now.
{% raw %}
```yaml ```yaml
start: '{% raw %}{{ 0 }}{% endraw %}' start: '{{ 0 }}'
end: '{% raw %}{{ now() }}{% endraw %}' end: '{{ now() }}'
``` ```
{% endraw %}
<p class='note'> <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. 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.