From bcbae6bb0cf6ba6924ca3fe354bf2280fed26d99 Mon Sep 17 00:00:00 2001 From: ttrabatt Date: Mon, 2 Dec 2024 00:27:28 +0100 Subject: [PATCH] Created binary_sensor dont_disturb_nightime --- binary_sensors.yaml | 14 ++++++++++++++ sensors.yaml | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/binary_sensors.yaml b/binary_sensors.yaml index e69de29..cad36e2 100644 --- a/binary_sensors.yaml +++ b/binary_sensors.yaml @@ -0,0 +1,14 @@ +--- +#### 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 }} diff --git a/sensors.yaml b/sensors.yaml index 5848bf3..0efe138 100644 --- a/sensors.yaml +++ b/sensors.yaml @@ -12,4 +12,3 @@ off {% endif %} icon_template: mdi:motion-sensor -