I am trying to stop to reflash an ESPHome device if a certain condition is not met.
The device in object is a smart plug.
I would like to avoid that any device is connected to the plug get switched suddenly OFF.
This OFF condition happens when the ESP is reflashed and reboots, even if I have set the switch (relay) restore_mode to ALWAYS_ON, I am guessing probably because it is a NO contact relay.
I believe that I might do something using the OTA Cnfiguration variables but I am unsure what to do to stop the OTA process.
Maybe it is not possible, thatâs the reason I am posting.
The concept is if there is any power draw from the plug, the OTA is not possible.
So on begin of the OTA Iâm testing if the sensor measuring the power is lower than a certain value, in case it is true it should proceed otherwise the OTA is interrupted.
Why not solve on HA side? I start my updates from there and it could easily skip one instead of abort from ESP side. If you mess this code up youâll be forced to serial flash.
Just asking if there is a way to stop the loading of the new code or update if a condition is not met.
Like sensor value > x then OTA stops else it runs.
Hello,
It is not a matter of skipping or not.
I will try to make it clearer:
The smart plug is powered and gives power to something.
If I start an update form esphome dashboard it will compile and load the code
When loading is done the device reboots and for a short while the relay controlling the power goes from ON to OFF and then back to ON.
I was trying to make sure I donât forget, now I am manually making sure that the device connected to the smart plug is off and then run the reflashing.
I understood that. But I do not start the update from ESPHome but from HA, so I can script it to my liking (skip updates, etc.). What I meant was, if you automate it so updates wonât start you do not need to break it off on ESP side.
If the ESP can refuse updates you might get caught in a situation where it wonât OTA at all nd you need to open it up for serial flash all over again.
So I wanted to say: if itâs a personal device, then you have control over it and can prevent an issue from removing it from itâs location or first turning off the controlled or monitored device, but I see now why youâre asking.
To confirm: you are OK with rebooting the ESP if the switch is off, but not on. What device is this controlling?
I agree with Edwinâs suggestion. Itâs probably sufficient and the easiest.
I am asking if there is a way to prevent the over the air update/flashing of a ESPHome device if a certain sensor value of the same device is not within an established limit.
e.g.
sensor value > 10 W
if and update is launched from the ESPHome dashboard
as condition is not met the update will not run
the device is a projector, quite old with lamp.
After a while is not doing anything it goes to standby, lamp off so the power consumption go down, as lamp is off it is not a problem to cut power abruptly.
I am ok with rebooting the ESP if the lamp is off.
I am ok with rebooting the ESP if the switch is OFF or ON but power consumption is lower than a certain value.
Iâm not sure how to do that reliably.
You could for example turn off wifi when critical situation exist.
But if itâs your personal device why would you do ota in the first place ?
Yes, I know you are right, but I know myself. In three months Iâll see an update and I forget that I should double check that, so I want to try to put in place some measure to avoid issue.
for the moment the solution is in the esphome dashboard:
device name + do not update if power on
I see your point, but I personally disagree since I think one should update device only when itâs really needed.
Anyway, if turning off wifi on esp is not possible/desirable, I donât have anything to suggest here.
Yes, you should have control of the consequences of what you do. You have a choice whether to update or not. Checking if the power is on before hitting the update all button should be something borne of experience and cost of replacement globes.
Option 1: Can you reconfigure your projector to come up as âglobe offâ or âstandby modeâ when power is applied? Check the user guide, and the service manual if available, as sometimes there are âservice technician optionsâ not available to the general public for different situations. Ask the manufacturer what they do in large concert halls and churches where the projectors are often in hard to reach places where changing globes can be very difficult.
Option 2: Maybe hook it up to a cheap UPS that will provide power long enough for the associated smart device to reboot, but short enough so it times out soon after the switch is deliberately turned off? A UPS for your switch, not the projector, but it could benefit that also.
Option 3: Are you handy with a soldering iron and can the switch case be opened easily and put back together safely? Do you actually use the switch functionality, or just the power monitoring side? A bit of surgery on your mains switch can disable it so it is on all the time. Safety warning: Please only do this if you are confident with mains wiring, and use a small soldering iron rated for electrical work on circuit boards, not guttering and pipe plumbing. No blowtorches please (you will melt off the other parts on your circuit board). No corrosive solder flux. Use very fine multicored resin solder is best. Disconnect your switch from anything, pull it apart and get to the back of the circuit board. Just solder a small bit of mains rated wire across the ânormally closedâ contacts at the back of the relay on the board and it wonât open to disconnect your projector from the mains. Use plenty of solder and make sure it is shiny, not a dry joint. Scrape back the coating on the circuit board near the relay contacts if you cannot get a good solid bridge across the contacts. Be aware that too much heat for too long can also lift the circuit traces, something you should avoid. Tin your iron, apply solder to the joint and heat it till it all fuses and melts together. If not self evident which parts to bridge, check the data sheet for the relay for the appropriate pins as common and normally closed (NC) - the circuit traces to them should be far fatter than the rest of the circuit to handle the mains rated switching current, and the two heavy wires for your Active/Line (brown or red by convention) should be soldered to the circuit board connected to the heavy traces and relay contacts. Yes the relay will click as expected, but the driven contacts will not open the circuit as they have been bridged. Donât worry, by design, dry relay contact -OUTPUTS- are not electrically connected to the rest of the control circuitry that drives the relay, just your switched mains wires, so wonât burn anything out if they are shorted. Your relay will still continue to work as designed but the output will be ignored as it is bypassed. In the future if you want to restore functionality, just unsolder the shunt you installed. The power monitoring function will still work after this modification is applied. Be sure to mark the modified switch clearly as bypassed and any âonâ indicator is covered in case somebody tries to repurpose it elsewhere later and wonders why it doesnât switch, or somebody assumes it comes up switched off if the indicator is off but it is still letting power through.
DeJaVu?
Option 4: In ESPHome for your switch, commenting out the OTA section but enabling the access point functionality (with suitable password) may be the other option, forcing you to connect to the access point to perform an update, with all the shenanigans to get it to trigger the access point functionality such as disabling your WiFi it connects to may be an option. In this case, you should also set a reminder in your calendar to check regularly in case there is a reason to update the smart switch firmware. Once it is working well, there often isnât a reason to update.