From c7f8c123036cc028d91279f0cd9cb0cd9fd85ef7 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 29 Oct 2018 22:46:30 +0100 Subject: [PATCH] Update templates --- .../_components/sensor.history_stats.markdown | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/source/_components/sensor.history_stats.markdown b/source/_components/sensor.history_stats.markdown index c8f5bebb6e4..c2c99448962 100644 --- a/source/_components/sensor.history_stats.markdown +++ b/source/_components/sensor.history_stats.markdown @@ -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 %}

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.