Unfortunately, I still have the problem that the deep sleep duration is only a few seconds regardless of the values and the device shuts down again immediately. The on_value
blocks are cycled on new values, like here:
sensor:
- platform: mqtt_subscribe
name: "Sleep time topic"
id: custom_sleep_time
unit_of_measurement: min
accuracy_decimals: 0
topic: homeassistant/input_number/dth11_deepsleep_dauer/state
on_value:
then:
- logger.log: "neuer Wert!"
- lambda: |-
id(this_deep_sleep).set_sleep_duration(id(custom_sleep_time).state * 1000 * 60);
- delay: 1s
- deep_sleep.enter: this_deep_sleep
The sleep values are also received and logged correctly via MQTT:
- platform: template
name: sleep-zeit
lambda: |-
return id(custom_sleep_time).state;
accuracy_decimals: 0
update_interval: 10s
- platform: template
name: run-zeit
lambda: |-
return id(custom_run_time).state;
accuracy_decimals: 0
update_interval: 10s
Deleting the OTA topic also works.
After 1-2 sec always deep sleep starts, although it is logged: Run Duration: 300000 ms
.
INFO Reading configuration /config/esphome/esensor-01.yaml...
INFO Starting log output from esp-dht11-01/debug
INFO Connected to MQTT broker!
[16:58:59][I][deep_sleep:116]: Beginning Deep Sleep
[16:59:11][I][mqtt:216]: MQTT Connected!
[16:59:11][V][mqtt:314]: subscribe(topic='homeassistant/switch/ota_dht11_modus/state')
[16:59:11][V][mqtt.component:062]: 'Sleep time topic': Sending discovery...
[16:59:11][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[16:59:11][V][json:051]: Size after shrink 352 bytes
[16:59:11][V][mqtt:414]: Publish(topic='homeassistant/sensor/esp-dht11-01/sleep_time_topic/config' payload='{"unit_of_meas":"min","name":"Sleep time topic","stat_t":"esp-dht11-01/sensor/sleep_time_topic/state","avty_t":"esp-dht11-01/status","uniq_id":"ESPsensorsleep_time_topic","dev":{"ids":"84cca8a32288","name":"esp-dht11-01","sw":"esphome v2022.5.0 May 18 2022, 15:20:08","mdl":"esp01_1m","mf":"espressif"}}' retain=1)
[16:59:11][V][mqtt:314]: subscribe(topic='homeassistant/input_number/dth11_deepsleep_dauer/state')
[16:59:11][V][mqtt.component:062]: 'Run time topic': Sending discovery...
[16:59:11][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[16:59:11][V][json:051]: Size after shrink 344 bytes
[16:59:11][V][mqtt:414]: Publish(topic='homeassistant/sensor/esp-dht11-01/run_time_topic/config' payload='{"unit_of_meas":"s","name":"Run time topic","stat_t":"esp-dht11-01/sensor/run_time_topic/state","avty_t":"esp-dht11-01/status","uniq_id":"ESPsensorrun_time_topic","dev":{"ids":"84cca8a32288","name":"esp-dht11-01","sw":"esphome v2022.5.0 May 18 2022, 15:20:08","mdl":"esp01_1m","mf":"espressif"}}' retain=1)
[16:59:11][V][mqtt:314]: subscribe(topic='homeassistant/input_number/dth11_laufdauer_sec/state')
[16:59:11][V][mqtt.component:062]: 'Temperatur': Sending discovery...
[16:59:11][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[16:59:11][V][mqtt.component:062]: 'run-zeit': Sending discovery...
[16:59:11][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[16:59:11][V][json:051]: Size after shrink 308 bytes
[16:59:11][V][mqtt:414]: Publish(topic='homeassistant/sensor/esp-dht11-01/run-zeit/config' payload='{"name":"run-zeit","stat_t":"esp-dht11-01/sensor/run-zeit/state","avty_t":"esp-dht11-01/status","uniq_id":"ESPsensorrun-zeit","dev":{"ids":"84cca8a32288","name":"esp-dht11-01","sw":"esphome v2022.5.0 May 18 2022, 15:20:08","mdl":"esp01_1m","mf":"espressif"}}' retain=1)
[16:59:11][V][mqtt:414]: Publish(topic='esp-dht11-01/sensor/run-zeit/state' payload='nan' retain=1)
[16:59:11][V][mqtt:314]: subscribe(topic='homeassistant/switch/ota_dht11_modus/state')
[16:59:11][C][deep_sleep:037]: Setting up Deep Sleep...
[16:59:11][I][deep_sleep:042]: Scheduling Deep Sleep to start in 60000 ms
[16:59:11][V][mqtt.component:062]: 'Luftfeuchtigkeit relativ': Sending discovery...
[16:59:11][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[16:59:11][V][json:051]: Size after shrink 428 bytes
...
[16:59:11][D][main:150]: payload off, enter DS
[16:59:11][V][mqtt:414]: Publish(topic='homeassistant/switch/ota_dht11_modus/state' payload='' retain=1)
[16:59:11][V][sensor:074]: 'Sleep time topic': Received new state 1.000000
[16:59:11][D][sensor:124]: 'Sleep time topic': Sending state 1.00000 min with 0 decimals of accuracy
[16:59:11][D][main:341]: neuer Wert!
[16:59:11][V][mqtt:414]: Publish(topic='esp-dht11-01/sensor/sleep_time_topic/state' payload='1' retain=1)
[16:59:12][V][sensor:074]: 'Run time topic': Received new state 300.000000
[16:59:12][D][sensor:124]: 'Run time topic': Sending state 300.00000 s with 0 decimals of accuracy
[16:59:12][D][main:147]: neuer Wert!
[16:59:12][V][mqtt:414]: Publish(topic='esp-dht11-01/sensor/run_time_topic/state' payload='300' retain=1)
[16:59:12][D][main:150]: payload off, enter DS
...
[16:59:12][V][mqtt.component:062]: 'sleep-zeit': Sending discovery...
[16:59:12][V][json:031]: Attempting to allocate 512 bytes for JSON serialization
[16:59:12][V][json:051]: Size after shrink 316 bytes
[16:59:12][V][mqtt:414]: Publish(topic='homeassistant/sensor/esp-dht11-01/sleep-zeit/config' payload='{"name":"sleep-zeit","stat_t":"esp-dht11-01/sensor/sleep-zeit/state","avty_t":"esp-dht11-01/status","uniq_id":"ESPsensorsleep-zeit","dev":{"ids":"84cca8a32288","name":"esp-dht11-01","sw":"esphome v2022.5.0 May 18 2022, 15:20:08","mdl":"esp01_1m","mf":"espressif"}}' retain=1)
[16:59:12][V][mqtt:414]: Publish(topic='esp-dht11-01/sensor/sleep-zeit/state' payload='nan' retain=1)
[16:59:12][V][component:199]: Component mqtt took a long time for an operation (0.06 s).
[16:59:12][V][component:200]: Components should block for at most 20-30ms.
...
[16:59:12][C][mqtt:601]: MQTT Message Trigger:
[16:59:12][C][mqtt:602]: Topic: 'homeassistant/switch/ota_dht11_modus/state'
[16:59:12][C][mqtt:603]: QoS: 0
[16:59:12][C][mqtt.sensor:027]: MQTT Sensor 'Sleep time topic':
[16:59:12][C][mqtt.sensor:031]: State Topic: 'esp-dht11-01/sensor/sleep_time_topic/state'
[16:59:12][C][mqtt_subscribe.sensor:031]: MQTT Subscribe 'Sleep time topic'
[16:59:12][C][mqtt_subscribe.sensor:031]: State Class: ''
[16:59:12][C][mqtt_subscribe.sensor:031]: Unit of Measurement: 'min'
[16:59:12][C][mqtt_subscribe.sensor:031]: Accuracy Decimals: 0
[16:59:12][C][mqtt_subscribe.sensor:032]: Topic: homeassistant/input_number/dth11_deepsleep_dauer/state
[16:59:12][C][mqtt.sensor:027]: MQTT Sensor 'Run time topic':
[16:59:12][C][mqtt.sensor:031]: State Topic: 'esp-dht11-01/sensor/run_time_topic/state'
[16:59:12][C][mqtt_subscribe.sensor:031]: MQTT Subscribe 'Run time topic'
[16:59:12][C][mqtt_subscribe.sensor:031]: State Class: ''
[16:59:12][C][mqtt_subscribe.sensor:031]: Unit of Measurement: 's'
[16:59:12][C][mqtt_subscribe.sensor:031]: Accuracy Decimals: 0
[16:59:12][C][mqtt_subscribe.sensor:032]: Topic: homeassistant/input_number/dth11_laufdauer_sec/state
...
[16:59:12][C][mqtt.sensor:027]: MQTT Sensor 'sleep-zeit':
[16:59:12][C][mqtt.sensor:031]: State Topic: 'esp-dht11-01/sensor/sleep-zeit/state'
[16:59:12][C][mqtt.sensor:027]: MQTT Sensor 'run-zeit':
[16:59:12][C][mqtt.sensor:031]: State Topic: 'esp-dht11-01/sensor/run-zeit/state'
[16:59:12][C][mqtt:601]: MQTT Message Trigger:
[16:59:12][C][mqtt:602]: Topic: 'homeassistant/switch/ota_dht11_modus/state'
[16:59:12][C][mqtt:603]: QoS: 0
[16:59:12][C][deep_sleep:049]: Setting up Deep Sleep...
[16:59:12][C][deep_sleep:052]: Sleep Duration: 60000 ms
[16:59:12][C][deep_sleep:055]: Run Duration: 300000 ms
[16:59:12][I][deep_sleep:116]: Beginning Deep Sleep
Note: the OTA topic is of course deleted, so empty.
The following is the current deep sleep block in ESPHome. The OTA state is detected correctly.
on_message:
- topic: homeassistant/switch/ota_dht11_modus/state
payload: 'on'
then:
- logger.log: "payload on, no DS"
- deep_sleep.prevent: this_deep_sleep
- topic: homeassistant/switch/ota_dht11_modus/state
payload: 'off'
then:
- logger.log: "payload off, enter DS"
- mqtt.publish:
topic: homeassistant/switch/ota_dht11_modus/state
retain: true
payload:
- delay: 2s
- deep_sleep.enter: this_deep_sleep
deep_sleep:
run_duration: 60s
sleep_duration: 1min
id: this_deep_sleep