What kind of component or entity do I need for this?

My two cents on this is that it is targeted at people with a non c++ background so they can easily build many common basic projects. I think it does a great job of that.

Since there is C++ under the hood then there is nothing stopping you from doing whatever hybrid of ESPHome and full C++ based solutions you want. Although the precise way to do that may not be well documented.

The people that come from a strong C++ side of things seem to more just know how many advanced things work and “figure it out”. Baffles me.

Probably you’re somewhere in the middle where you have a fair bit of the c++ but can’t always figure out if you should do it the c++ or yaml way, or how the hybrid looks. The yaml way can get you quite far once you know “the ways”.

BTW have you found the ESPHome Discord yet? That’s where the bulk of advanced users are and they might be able to answer more of your architecture questions.

I honestly find the ESPHome documentation better than the Home Assistant docs!

Yes - good find! I tend to have search issues, since I tend to pick terms that narrow a search as much as possible. Old habit I can’t stop and it often means I don’t get hits others find easily.

I missed the “Edit” link - I think I’ve been so focused on just finding answers that I tuned out what didn’t lead me to more info.

That’s an excellent point! I’ve been using open source since the '90s and have been contributing, in some small forms, one or two projects of my own that have been outdated, for almost as long. Often, as a newbie in a project, suggestions are ignored or glossed over. Often there’s a, “Wait until you know what’s going on and it’ll all make sense,” attitude (or a, “No, we’re doing it this way because it’s right and others are wrong!” attitude - less frequent, but I’ve run into it).

As a beginner on with a project, it can be hard to contribute to docs. There’s a feeling of, “But if I write this, what if I’m overlooking or missing something important?” But this discussion is proof people here are open to bringing up questions like, “This seems more complete. Is there anything inaccurate in it?” on this forum.

I think writing up something for the Template components would be helpful. At this point, I can do that for the Numbers one. I don’t know if the Text or Select would work the same. I also wish I could find the page discussing Number Components (or Template Number) that mis-stated what the state field does. It wasn’t on the main pages for those components, but I did read something about it that was confusing.

I take it if I started threads with something like, “Possible issue in the documentation, suggested change for ” would make sure I get feedback before posting misinformation.

I did make one post about an issue with what seemed buggy behavior - included something like “Possible Bugs” in the title, but never had responses on it. If it’s not bugs, that would also provide me information for adding something to the docs.

Very astute of you. I have used C++ in the past, but that was over 15 years ago. I loved it, since it was “closer to than metal” than most languages. (I used to do a lot in Assembler, back when Apples ran on 6502 chips!) There’s a part of me that would really love the excuse to dive back in, since I’ve forgotten so much! (The hardest part, for me, was learning how to use all the options for compiling and linking - the programming was fairly easy, the “meta-programming” was hard for me to keep straight.)

If I did it on a Pi, I’d use Python for development speed. I keep forgetting about MQTT, for some reason. I have devices that use it and, at one point, I had read up on it, but I just keep forgetting that’s an option!

One advantage to an ESP32 is no OS on board - so nothing running updates in the background or daemons you forgot about getting in the way of an embedded system. I’m hoping to get used to using ESPHome and Pis for some projects I’d like to do for home automation and just a few simple gadgets.

That would make sense. Still, it’s hard to do much without lambdas and that means that to do much on it, one needs a smattering of C++. I think lambdas are basically filling in the gap for functions and services YAML doesn’t supply.

I would freaking love to! I would really love to add something that makes it easy to reference and use variables and substitutions, and getting the values of Components, without having to use lambdas. But it’s been so long since I used C++, and right now I have to get a business up and running, so the time is an issue. (I’d certainly be willing to get into discussions and get back up to speed on C++ over time.)

I think that’s why some things don’t get fixed, and it goes back to @nickrout’s comments about the perspective of a newbie being useful. This is common in open source projects: Those heavily involved know it all and find it easy to navigate, but those who are new are confused - and the highly experienced devs are so used to what they can use easily, it’s easy to forget how hard it is to come in to it fresh.

Somewhere along the line, I told myself, “Okay, YAML is more like a config language, but it’s really a limited form of OOP.” That helped me a lot. Here, it’s confusing since some fields are YAML and don’t even need quotes around them to use them, and others are C++ and need quotes or even the “double quotes inside single quotes” thing for string values. It’s tough to know which is which without experience.

I haven’t been there yet. I’ll have to keep that in mind. I often do better using non-realtime forums because it takes me time to think through a post.

I have a love/hate relationship with HA, but I like it better than OpenHAB, where I found the forum frustrating because of negative responses to me when I needed help with clarifications of how things were said and just what they meant.

1 Like

While the component issue is solved, I just realized there’s another issue with this situation: Detecting the state on startup. I’m using toggle switches, not push-button, so if there’s a power interruption or something like that and power comes back on, and the switch is on, it won’t detect that.

For the fan, that’s important, since, if the laser turned on in a situation like this, it’d be important to have the vent fan turn on to keep the workshop from filling with smoke. Also, with that kind of situation, I’d want to get an urgent warning that the control box came back on and the laser is on. I’m thinking of several solutions for this:

  1. Setup something in on_boot to check the state of each switch and, if it’s on, to set the delay as true.
  2. When power the system comes on, on_boot could check the main switch and, if it’s on, disable the entire box until that main switch gets turned off then on again.

#2 is more likely, but it also raises an issue because I do not want a control box for devices like this to be able to be turned on or off remotely. I’m thinking I’d have to make the deactivation part to be something internal, that can’t be controlled externally. (That would make sure it can’t be turned on remotely, through HA, by mistake or by eager and curious grandkids.)

While this situation is unlikely, since I’m not going to be using the CNC or laser remotely, and if there were a power loss (we have a standby generator and devices like this are on a UPS), the first thing I’d do is to hit the main switch on the panel to shut it down. BUT - this is the kind of situation where something bad could happen.

I can’t recall your specific implementation, but take a look at publish_initial_state:.

I’m not worried about what’s published - I’m worried about making sure devices can’t come on if there’s a power outage and the switches were left on and are still on when power comes back on.

I’ve posted about using on_boot and how long ESPHome takes to boot. It seems to me to be over 60 seconds, but I’m not sure. So counting on ESPHome to us an on_boot function for an emergency shutdown on reboot would be a problem. Also, since ESPHome is only reading the switches, which are DPST, so the devices they control are on a different circuit, I think I’m going to have to handle this with hardware.

It looks like your suggestion is working. I did several tests on it today (took me a few days! I like how it’s behaving. When I test and debug something, I’m aggressive with it. I WANT to break it NOW so it won’t break later. (When I was running a software-as-a-service business, this is one thing that helped me sleep better - knowing that I was rougher on my software than my clients would ever be!)

I used a timer component to print the value of the switch and delay regularly so I could track them. I also used another button so I could press it and get a status on them, and had log statements showing me what was going on, so I could easily track the delay and switch. Then I tried to break it. I did things like hold down the button and change the delay value while the button was down. I tried changing the delay while the delay was in progress. I tried pressing the switch, letting up, then pressing again while the delay was ongoing.

I found changing the value of the delay once the delay had started didn’t affect the delay length. (Changing it while the button was down did change the delay.) If I pressed the button again, while the delay was ongoing, it would reset to when I released the button a 2nd time.

So, overall, it’s working fine. I’m going to run more tests on it to see if I can break it, but I think it’s solid and it uses fewer components and less code than my method did.

Also, I mentioned the issue with what to do when I lose power and forget to turn things off. Looks like I can deal with that with a reset button and a simple circuit with an SCR. Basically, once the control box receives power, it will have to be “activated” by pressing a button. That way the ESP32 will work when power comes back, but none of the devices can be turned on until I press the activation button. It’d be nice of that safety feature were transparent, but, for now, this works.

(And as I type that, I can imagine a way I might be able to make it transparent - have to think about that, but it’s another topci.)