Turning off and disabling a GPIO switch

What would be the prefred way to block a switch from being turned on? I’m working load shedding for my solar setup and I need to be able to disable specific outlets (controlled by an esphome gpio switch) while blocking automations and users from turning them. Failing this could lead to an overload and the inverter cutting power to the house.

My guess would be to make a proxy template switch and then actuate the gpio switch from it, blocking if necessary, but synching the state of two switches sounds like it would be hard to get right, considering that I’d also need to restore the state on boot. Is there a better way of doing this?

Expose a template switch from esphome (to HA) which checks an binary sensor (“load shedding”) from HA and only switches the relay/gpio when load shedding is not active. This all happens directly on the esphome nodes. The moment you receive the information from HA that load shedding is active you set your relays/gpio’s to the states you want (probably off).

Great scenario for esphome and something that probably no zigbee/zwave/matter etc. will ever be able to achieve!

I’d also need to stop the template switch from turning on the gpio thing, but yeah that’s the direction I’ll probably end going

It’s really cool that you can put your own logic into the microcontroller and have it follow certain rules.

Although I think the underlying issue here is that home assistant is structured so that a lot of unrelated automations can manage a lot of shared resources. It would be cool to have sort of an “entity mediator” that would receive input from different automations and then block, allow or sequence the output in a way that it sees fit. This would essentially allow you to move this logic outside esphome and have it work with other ZigBee, Z-wave MQTT or whatever other devices.

I have a similar issue where I want to use my front lights together with Alarmo to do a light show whenever the alarm is tripped. The esphome device should ignore physical switch input while on “light show” mode and sequence the output to turn on and off. Right now I’m doing the logic inside the microcontroller, but it feels weird to do what’s essentially an automation there.

Really? Esphome has inbuilt automations. Not weird at all.

If I need to use the same device for connecting a different appliance and I don’t need load shedding anymore (or the other way around), I’d have to change the firmware, that is what feels weird. I know changing the firmware is something you do regularly with esphome but it still feels like that logic should be in home assistant imho. Any logic that you implement there in the device doesn’t translate to other kind of devices like Z-wave ZigBee, etc.

I just made an implementation of this “load shedding” switch, flashed it and now the unit isn’t connecting back to home assistant :confused:. I’m guessing that it’ll reboot at some point it’ll revert back and give me ota access. This is what I mean by it feeling “weird”, the home logic is running on the MCU and any issues will take down the entire device, as compared to having somethig running on the home assistant server in a supervised manner.

There are two approaches. Automation on the esp or automation on ha. Some people want it on the esp, just in case ha is down.

Different approaches for different uses.

Totally, there are some automations that make sense on the mcu. Turning on a switch based on some GPIO input is something that should be done in the ESP.

In this case this is not an “automation”, it’s more of a rule set that should be followed. Don’t turn on the relay no matter what if the device is being disabled due to the power budget, sort of like an interlock, load shedding should be off before the relay can be turned on. Right now I’m doing it on the ESP because it’s more difficult to implement in HA.