I just built a DC generator to charge my emergency backup battery during our many power outages. For short-term outages we can survive on battery alone, but if it lasts longer than 12 hours, we need to burn some fossil fuels.
I have built the generator, it has an electric starter and using a micro-controller to start it when the battery is getting low, run it until it’s full and then shut it down is fairly trivial. It does require a bit of coding, timers, counters etc., since you want to only crank for a few seconds, check if the motor is running, make sure the alternator is generating DC, etc. As a hint about complexity, the setup has 10 relays.
I would really like to have this reporting to HA (some variables like voltage, amps, power, run-time, rpm) and be able to start it or shut it down from HA. Basically override the automatic start/stop.
I started testing the automation with Arduino. I figured ESPHome would be the way to go to implement this with HA. But I may be wrong.
The big question is how to handle this: It looks like all of the needed functionality could technically be handled in a YAML in ESPhome. I mean there’s a lot of counters, timers and if/thens, but I guess that can all be YAMLed.
However, I have much more personal experience coding in C++. I would prefer doing that and then exposing my code to ESPHome.
Which way should I go? And how would I go about the recommended approach?
I previously made lots of projects using Arduino/C++ but I’m now all-in with ESPHome, enough so that I’ve actually started switching all of my old projects to ESPHome (mainly just because, but also for some greater/easier control and data in HA).
There’s definitely some things that can be done more elegantly in C++ (which you can still use inside of ESPHome), but I’ve found the benefits far outweigh any tradeoffs. I end up with projects that feel more professional, usually are easier to code and ‘just work’ with HA in a way that still feels like magic to me.
I have some complex (very busy) code that I prefer to run separately from esphome. I have one esp32 running esphome web server and these non-esphome setups communicating with web server through rest api. Works perfectly.
Do you have an example on how this is accomplished? (Link)? That would be quite helpful. There seem to be several ways to go about it and I’m a newb to ESPhome and HA and would like to figure out the moist elegant and efficient route.
Depends how you want set all up.
Example to post data to esphome.
First of all make web server
web_server:
local: true
Make a component to receive values from non-esphome device (http request)
number:
- platform: template
name: Water heater Power
id: heater_power
min_value: 0
max_value: 1600
step: 1
optimistic: true
unit_of_measurement: "W"
and sending data from non-esphome device
HTTPClient http;
String postdata = "http://192.168.0.133/number/heater_power/set?value=" + String(actualpower);
http.begin(postdata);
http.addHeader("Content-Type", "text/plain");
int httpResponseCode = http.POST("POSTING from ESP32"); //Send the actual POST request, nothing in this case
http.end();
Just some more info: two truck alternators, modified with permanent magnet field generators. They are now running at up to 100V and 3.5kW each. They feed my 48V LiFePO4 battery through two PWM solar chargers. Even on the hottest day with my AC running full-tilt, my house needs less than 5kW on average, so I should be OK.