I have a small esphome project that uses an ESP8266 to move a servo. I’m running the project from battery, so also using deep_sleep
and controlling the required movement via MQTT commands. I’m using ESPHome version 2023.10.1
This is generally working well. The issue I’m finding is that occasionally (maybe 1 in 10 boots), the servo appears to return to a neutral/home position, before restoring back to the last retained message value. What could the reason for this be? If I disable the deep_sleep
, then the servo never moves unless commanded - so it definitely appears to be a boot related issue.
my config -
esphome:
name: $device_name
esp8266:
board: d1_mini
ota:
password: !secret ota_password
mqtt:
broker: $mqtt_broker
id: mqtt_client
birth_message:
topic: 'nope'
payload: online
will_message:
topic: 'disabled'
payload: offline
topic_prefix: homeassistant/$device_name
on_message:
- topic: homeassistant/ota_mode
payload: 'ON'
then:
- logger.log:
format: "OTA mode ON - battery usage elevated"
level: INFO
- deep_sleep.prevent: deep_sleep_1
- topic: homeassistant/ota_mode
payload: 'OFF'
then:
- logger.log:
format: "OTA mode OFF - deep sleep now available"
level: INFO
- deep_sleep.allow: deep_sleep_1
- topic: homeassistant/$device_name/number/catdoorposition/command
then:
- number.set:
id: catdoor_position
value: !lambda |-
return stof(x);
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# update this to override OTA update target
use_address: $static_ip_address
fast_connect: true
manual_ip:
static_ip: $static_ip_address
gateway: $static_ip_gateway
subnet: $static_ip_subnet
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: !secret fallback_wifi_ssid
password: !secret fallback_wifi_password
http_request:
useragent: esphome/$device_name
timeout: 2s
# Enable logging
logger:
level: $log_level
output:
- platform: esp8266_pwm
id: pwm_output
pin: $gpio_servo_pin
frequency: 50 Hz
servo:
- id: catdoor_servo
output: pwm_output
auto_detach_time: 2s
max_level: 12.8%
number:
- platform: template
id: catdoor_position
name: "catdoorposition"
min_value: -100
max_value: 100
step: 1
optimistic: true
set_action:
then:
- servo.write:
id: catdoor_servo
level: !lambda 'return x / 100.0;'
sensor:
- platform: adc
pin: VCC
name: "VCC Voltage"
deep_sleep:
id: deep_sleep_1
run_duration: $sleep_duration_awake
sleep_duration: $sleep_duration