How can I make sure that the sensor is not reset after a reboot and the servo does not return to the 0 position? I noticed that if I specify restore_state: false at the switch, then after restarting the esp or de-energizing.
If I enable restore after reboot restore_state: true
If you remove the switches and sensors and leave only this option, then after restarting the esp or de-energizing, nothing is reset and remains in place. As soon as I add a switch and a sensor, then after a reboot everything goes wrong. I was thinking of using a number instead of a sensor to store the position in memory and restore the position from the number after a reboot, I can’t do it
Trying to find solution for the same problem. Not an expert in HA/ESPHome, but as far as I understand how modules work retaining often changing value is not feasible solution because flash will be killed in no time. Only rarely changing config values should be stored. Since servo kind of retains position till pwm signal is energized/sent - bigger load/force will move servo anyway - I would try to send update of last known state from HA when module becomes available after reset. Of course there might be some issues with sync if servo position is changed while HA is offline for some reason.
Since you are using esp32 maybe easier solution would be servo with analog position feedback hooked to adc input (for eg FS90-FB Micro Servo)?
that the servo keeps the position until a pwm signal is applied/sent - a large load/force will move the servo anyway - I would try to send an update of the last known state from HA when the module becomes available after reset.
I just want to provide emergency recovery of the last position of the servo after de-energizing the board, since the board will not de-energize, but only the servo itself. Why do I need this? You can watch my video where I build a smart bath. There I built a servo into the siphon and the servo rotates the siphon twister and opens or closes the drain valve. The servo is switched off so that you can manually turn the twister and close or open the drain valve. I am a little satisfied with the fact that if the power is reset and then the servo returns to the 0 position, but still I would like to be able to make it so that after losing power the servo does not return to 0. You can use Home Assistant, but there is no feedback, which I implemented in ESPHome, and this is important very
Hi Divan
I used your code for servo control thanks for share.i have problem i used actually final code on page but it’s still resetting servo motor position after energize deenergize .And its give error message on restore_state to change restore_mode .Do you have solution for resetting or could you share final code with me ?
Thanks a lot
It should be understood that the state is not recorded in memory immediately, but after a specified time. If you specified 1 minute, and you set the position of the servo and immediately de-energized, then this will not be stored in memory and the state will be reset. Set the position of the servo and wait for the time when it will be recorded in memory, and then you can de-energize