@moci and @tom_l You could actually use this method…
Set up a ESP like this (code below) and it will subscribe to the message on the MQTT server, se it when it wakes up and take that value and set it to be the deep sleep duration value. Make sure the value you are sending as the topic however is in milliseconds.
I believe this call:
on_value:
then:
- lambda: |-
id(deep_sleep_1).set_sleep_duration(id(custom_sleep_time).state);
is not is not documented but it works fine for me :).
substitutions:
devicename: wemos_weather_station
friendly_devicename: weather station
esphome:
name: $devicename
platform: ESP8266
board: d1_mini_pro
wifi:
fast_connect: true
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.201
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Wemos WS Fallback Hotspot"
password: !secret ota_password
# NO API when using battery device
# api:
# password: !secret api_password
mqtt:
broker: '192.168.1.7'
username: !secret mqtt_username
password: !secret mqtt_password
discovery: false
discovery_retain: false
birth_message:
will_message:
on_message:
- topic: esp/ota_mode
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_1
# Enable logging
logger:
level: INFO
ota:
password: !secret ota_password
sensor:
- platform: wifi_signal
name: $friendly_devicename signal strength
- platform: mqtt_subscribe
name: "Sleep time topic"
id: custom_sleep_time
unit_of_measurement: ms
accuracy_decimals: 0
topic: esp/sleep_mode_time
on_value:
then:
- lambda: |-
id(deep_sleep_1).set_sleep_duration(id(custom_sleep_time).state);
switch:
- platform: restart
id: reboot_esp
name: $friendly_devicename restart switch
deep_sleep:
id: deep_sleep_1
sleep_duration: 300s
run_duration: 1s