Add instructions for custom formatted time sensor (#15086)

This commit is contained in:
zmarties 2020-10-09 14:07:49 +01:00 committed by GitHub
parent 9d8cb248d9
commit 6ed8d110c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,33 @@ sensor:
- **display_options** array (*Required*): The option to display. The types *date_time*, *date_time_utc*, *time_date*, and *date_time_iso* shows the date and the time. The other types just the time or the date. *beat* shows the [Swatch Internet Time](https://www.swatch.com/en_us/internet-time). - **display_options** array (*Required*): The option to display. The types *date_time*, *date_time_utc*, *time_date*, and *date_time_iso* shows the date and the time. The other types just the time or the date. *beat* shows the [Swatch Internet Time](https://www.swatch.com/en_us/internet-time).
Sensors including the time update every minute, the date sensor updates each day at midnight, and the beat sensor updates with each beat (86.4 seconds).
<p class='img'> <p class='img'>
<img src='/images/screenshots/time_date.png' /> <img src='/images/screenshots/time_date.png' />
</p> </p>
# Producing your own custom time and date sensor
Whilst there are a number of `display_options` exposed by this sensor, they cannot hope to satisfy everyone, and large parts of the world will find that their local display conventions are not included.
The following can be used to create a time and date sensor whose output can be properly customised to use your own preferred formatting, specified in the call to timestamp_custom() using standard [Python datetime formatting](https://docs.python.org/3.8/library/datetime.html#strftime-and-strptime-behavior).
{% raw %}
```yaml
sensor:
# Minimal configuration of the standard time and date sensor
- platform: time_date
display_options:
- 'date_time_iso'
# Build on the standard sensor to produce one that can be customized
- platform: template
sensors:
time_formatted:
friendly_name: "Date and time"
value_template: "{{ as_timestamp(states('sensor.date_time_iso')) | timestamp_custom('%A %B %-m, %I:%M %p') }}"
icon_template: mdi:calendar-clock
```
{% endraw %}