After I understood, what @HasQT did, I implemented the thing myself. Here my vesion, which is marginally different. All credits to @HasQT !
- My script to disable deep sleep does not switch off the automation. I handle this within the automation. (If DeepSleepTime is 00:00, then wait 10min and if still true, send a notification to my mobile phone. I then can use one of the other scripts to set DeepSleepTime or keep on working on the device .)
- My automation to manage DeepSleepTime follows the same logik, but uses different times.
- My MQTT-sensor does not have a unit_of_measurement, but uses a device_class.
MQTT Sensor to hold the currently set DeepSleepTime
### D1mini Wohnzimmer: DeepSleepTime ###
- platform: mqtt
name: "Wohnzimmer DeepSleepTime"
unique_id: "mqtt.Wohnzimmer.DeepSleepTime"
state_topic: "stat/D1mini_Wohnzimmer/RESULT"
value_template: '{{value_json.DeepSleepTime | timestamp_custom("%H:%M", False) }}'
device_class: "duration"
Automation to manage DeepSleepTime
alias: 'Wohnzimmer D1mini: DeepSleepTime Steuerung'
description: |-
Steuerung der DeepSleepTime, um deb Akkuverbrauch reduzieren
Zu Zeiten, in denen wir eher lüften: 5min
tagsüber: 15min
nachts: 60min
trigger:
- platform: mqtt
topic: tele/D1mini_Wohnzimmer/LWT
payload: Online
condition: []
action:
- service: mqtt.publish
data:
topic: cmnd/D1mini_Wohnzimmer/DeepSleepTime
- wait_for_trigger:
- platform: mqtt
topic: stat/D1mini_Wohnzimmer/RESULT
continue_on_timeout: false
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- choose:
- conditions:
- condition: or
conditions:
- condition: time
after: '06:00:00'
before: '09:00:00'
- condition: time
after: '11:00:00'
before: '14:00:00'
- condition: time
after: '17:00:00'
before: '21:00:00'
- condition: not
conditions:
- condition: state
entity_id: sensor.wohnzimmer_deepsleeptime
state: '00:05'
sequence:
- service: script.wohnzimmer_d1mini_deepsleep_5min
data: {}
- conditions:
- condition: or
conditions:
- condition: time
after: '09:00:00'
before: '11:00:00'
- condition: time
after: '14:00:00'
before: '17:00:00'
- condition: not
conditions:
- condition: state
entity_id: sensor.wohnzimmer_deepsleeptime
state: '00:15'
sequence:
- service: script.1653076935556
data: {}
- conditions:
- condition: or
conditions:
- condition: time
after: '21:00:00'
before: '06:00:00'
- condition: not
conditions:
- condition: state
entity_id: sensor.wohnzimmer_deepsleeptime
state: '01:00'
sequence:
- service: script.1653076986433
data: {}
- conditions:
- condition: state
entity_id: sensor.wohnzimmer_deepsleeptime
state: '00:00'
sequence:
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- condition: state
entity_id: sensor.wohnzimmer_deepsleeptime
state: '00:00'
- service: notify.mobile_app_nokia_7_plus
data:
message: D1mini Wohnzimmer DeepSleepTime aktivieren.
title: DeepSleepTime aktivieren
default:
- stop: D1mini Wohnzimmer DeepSleepTime nicht geändert.
mode: single
Scripts to set different DeepSleepTime on the D1mini.
Set DeepSleepTime to 300s (-> 5min)
alias: 'Wohnzimmer D1mini: DeepSleepTime 05min'
sequence:
- service: mqtt.publish
data:
topic: cmnd/D1mini_Wohnzimmer/DeepSleepTime
payload: '300'
mode: single
icon: mdi:sleep
Set DeepSleepTime to 900s (-> 15min)
alias: 'Wohnzimmer D1mini: DeepSleepTime 15min'
sequence:
- service: mqtt.publish
data:
topic: cmnd/D1mini_Wohnzimmer/DeepSleepTime
payload: '900'
mode: single
icon: mdi:sleep
Set DeepSleepTime to 3600s (-> 60min)
alias: 'Wohnzimmer D1mini: DeepSleepTime 60min'
sequence:
- service: mqtt.publish
data:
topic: cmnd/D1mini_Wohnzimmer/DeepSleepTime
payload: '3600'
mode: single
icon: mdi:sleep
Switch DeepSleep off to enable access to device
alias: 'Wohnzimmer D1mini: DeepSleepTime aus'
sequence:
- wait_for_trigger:
- platform: mqtt
topic: tele/D1mini_Wohnzimmer/LWT
payload: Online
- service: mqtt.publish
data:
topic: cmnd/D1mini_Wohnzimmer/DeepSleepTime
payload: '0'
- wait_for_trigger:
- platform: mqtt
topic: stat/D1mini_Wohnzimmer/RESULT
payload: '{"DeepSleepTime":0}'
- service: notify.mobile_app_nokia_7_plus
data:
title: D1mini Wohnzimmer DeepSleep aus
message: Der DeepSleep Modus des D1mini Wohnzimmer ist abgeschaltet.
mode: single
icon: mdi:toggle-switch-off-outline
One thing I did not yet understand: two of my three scripts are referenced with an ID. Where does the ID come from? I did not define the ID within the script… anyway, it works!