Migration of Template based Sensors due to deprecation of "platform: template" from 2026.6

This commit is contained in:
2025-12-12 02:07:01 +01:00
parent d003fd5f0f
commit 7fee79c364
5 changed files with 118 additions and 73 deletions

View File

@@ -1,14 +1,17 @@
---
# ---
# IMPORTANT NOTE: all sensors here having templates have been migrated/fixed to template.yaml as per Deprecation of platform: Template
#
#### Return true if current time is within from and to time
- platform: template
sensors:
dont_disturb_nighttime:
# all variables below (excluding hour & minute) hold UTC times converted to timestamps (int)
# as internally HA times are in UTC
# nothe that you have to have sensor.time_utc configured
unique_id: dont_disturb_nighttime
value_template: >
{% set from = state_attr('input_datetime.dont_disturb_nighttime_from','timestamp') %}
{% set to = state_attr('input_datetime.dont_disturb_nighttime_to','timestamp') %}
{% set cur = ( now().hour * 3600 + now().minute * 60 ) %}
{{ (cur < to or from <= cur) if from > to else from <= cur < to }}
# - platform: template
# sensors:
# dont_disturb_nighttime:
# # all variables below (excluding hour & minute) hold UTC times converted to timestamps (int)
# # as internally HA times are in UTC
# # nothe that you have to have sensor.time_utc configured
# unique_id: dont_disturb_nighttime
# value_template: >
# {% set from = state_attr('input_datetime.dont_disturb_nighttime_from','timestamp') %}
# {% set to = state_attr('input_datetime.dont_disturb_nighttime_to','timestamp') %}
# {% set cur = ( now().hour * 3600 + now().minute * 60 ) %}
# {{ (cur < to or from <= cur) if from > to else from <= cur < to }}