to access cpp src from haos, do this: - open terminal (don't have it? have it...) - go inside the esphome container: docker exec -it $(docker ps --filter "name=esphome" --format "{{.Names}}") bash - go in /data/build/your_device_name/src pin this if you want
A fantastic guide and a huge time saver. I might never have gone in this direction, but I probably will now. We definitely will need a way to get the data out to complete the job and enable so many other great projects. Thanks again!
MQTT is supported. Also, you can write your own components if the existing ones don't quite do what you want... Plenty of Open Source components to clone and modify for your needs.
00:00 Arduino IDE vs. ESPHome: Introduction 01:05 Understanding the Fundamentals: C++ vs. YAML 03:08 Basics of YAML for ESPHome: Key-Value Pairs & Objects 06:10 First ESPHome Project: Wi-Fi Connectivity and Basic Setup 07:50 Building a Sensor with ESPHome: BME280 Example 09:33 Adding Outputs and Switches: Controlling LEDs 10:48 Examining the Generated Arduino Code: PlatformIO Project 12:10 Integrating an OLED Display: Lambda Functions in YAML 14:08 Implementing Logic with Automations: Button and Switch Control 15:56 Using Scripts in ESPHome: Reusable Functionality 18:19 Verdict: ESPHome vs. Arduino IDE - Pros and Cons 21:03 Future Use Cases and Conclusion These chapters were created entirely locally on my Debian machine using open-source software (Whisper, Ollama, Qwen2.5:14b). @Andreas Spiess - Use the chapters in your video description if you want, no need for credits.
Great overview of ESPhome concepts - this would have saved me so much time when getting started. A few other tips that I learnt the hard way, and wish I took this path from the beginning: 1) Compiling ESPhome is so slow on something like a RPi for Home Assistant. It is far better to do the compiling and flashing from a high performance desktop (running ESPhome as a container). The devices can still be discovered by Home Assistant. 2) Keep all your secrets (passwords and IP addresses) in the secrets yaml file. This simplifiles your boilerplate code for each project. 3) Use name substitutions at the top of your file, which means the main yaml body is more generic and can easily be shared with others, or duplicated across similar projects and devices.
Thank you for your additions. I agree with all of them. Frequent users know that one of the reasons I moved to X86 and Proxmox was the slow speed of ESPhome compilation on the Raspberry 4. With my second-hand miniPC the speed is ok...
I kind of knew a lot of this, but had never really thought about it in a structured way. Thank you for making this video, it was really helpful and added to my knowledge! Merry Xmas to you and your family!
@@michaels3003 lol human readable, key value pairs? ... thats machine readable, if i have to memorize these high level abstractions of what they mean when they say "home:something" i might as well learn the code that manipulates the registers that set these functions instead, maybe not as "easy" to read but you have to understand what they mean just the same as any readable word anyway so i dont see the effeciencey gains here, infact you just have to memorize a layer of bloat and lose the undersatnding of what youre actually doing with these high level abstractions and now youre stuck when something goes wrong or want to add a feature. Im all for abstracting messy code awway, but it should be code you wrote, or at leaste copied. I have 250 lines of code that uses no libraries except a font.h file written in arduino IDE stm32c6 (the low ram version) that sets up the BME sensor and calibrates it too your liking, weather (pun intended) you want to oversample temp/ humidity or preasure, or not which is critical for any power savings for a usable weaher station on batttery. Outputting to an oled display with a handsome font ,fittingon 32 kb or ram. I wonder how much ram this esp32 bloatware version cost us eh Andreas? ;) I kid, the register manipulation code is ugly, but kind of simple, and now you know where the data is and can interface it with whatever database you want. By the way i not a pro programmer, i just used chatgtps help to setup this sensor with minimal libraries and resources.
One thing with YAML is to understand the difference between declarative (= describing the end result and the system figures everything out) and imperative (= do this then do something else, ...) coding. Most coding was always done imperative and declarative is a fairly new thing.
I love the way you can make almost any appliance or gadget smart with a quickly built esphome node. Just need a relay or a motor to actuate. So many integrated components. It is amazing !
There are various ways to write ESPHome sensors to a database such as InfluxDB, depending on what you want to do. - ESPHome + MQTT: ESPHome offers support for sending data to MQTT topics, so you can go the route completely without Home Assistant. The data could then be written to InfluxDB, for example, using your own program or Node-RED. - ESPHome + Home Assistant + Nodered: The Home Assistant add-on for Node-RED can capture specific sensor data and write it to the desired database using a database add-on such as InfluxDB. - Customize Home Assistant Recorder: There are ways to customize the recorder in Home Assistant so that certain values are written to the desired location, such as the Influx database. - Long-term sensor data in Home Assistant: If the data ends up in Home Assistant anyway, there is the option of writing long-term data to the Home Assistant database. It is not always necessary to use an Influx database for long-term data.
Thank you for your answer. Currently, I use Node-Red to post the data to influxDB (your 3rd proposal) and I once used influxDB for all HA data. After your comment, I looked again at this integration, and it seems you can now limit the sensor data written to influxDB. And maybe I could even have more than one bucket. That would solve my problem of having topic-specific buckets.
@AndreasSpiess Yes, it did so too. (Inspired by your videos) But unfortunately Influx1.8 is discontinued and migration to newer versions is complicated. So i switched to postgres as my main database, since there is a "postgres for everything" movement.
@@ei23de I am also not happy with the "behavior" of the organization behind influx. For the moment, I try to stick with it because I did not want the effort for migration. Mabe, one day it anyway has to be done...
I've been on the journey of learning ESPhome recently, and this video condenses much of what I've discovered. Thank you Andreas. A tip I learned recently concerning the use of LVGL and local displays, is to build a simulation environment using SDL2. It saves all of those flash writes whilst making small changes to layout and data formatting and can connect to live ESPhome. eg: I connect my sensors to ESPhome, and then fiddle with the display output on my PC simulation until I'm happy, and then flash the local display.
Perfect timing, after just setting up my Home Assistant to monitor and control my home, and now adding modules to support my filament storage, and humidity control.
Thank you again, even after experimenting and quite some frustrations on the YAML code I got things working. This video still learned me a lot! And happy to see you use chat gpt for help as well. This tool makes programming so much easier!
Thanks Andreas for the video and for the good and helpful information - I will try it also and I guess your info will save a lot of experimental time on my side.
Long over due clear explaination of YAML which I still loathe!!! Wish I had this 4 years ago. JSON is easier for me to read and understand due to the open/close separation of items. Seeing how list, ie, arrays, and automation, decision branches, are created helps a lot! As always, you're clear and concise, and great to see an fellow DECcie still "Kicking it"
Thanks Andreas, this was another very interesting video. I like the way you setup your videos. If I have a home project to do, I will definitely check back and let them guide me.
A great video, that explains everything really really well. As a novice with esp32's in general you have massively increased my understanding. Especially thst red squiggly line don't always mean a syntax error in the code i've just pasted.. 😂.
indeed, great thanks for this well explained guide. Even for using esphome for long time, you explained me the concept much better. That's what i really about your channel, the well explained concepts of various topcs.
Exactly what I need a great clarification from the Master :) with the help of chatGPT I managed to setup a Victron UART reader for my solar system, Bedroom Air Qualtiy sensor running BME680 and MH Z17 CO2 sensor, and HX711 for weight scale. Thank you!
Another super useful video! I had heard of ESPhome but didn't know its capabilities. I have a project idea for a stepper motor control that will raise and lower my window blinds and the Home Assistant instant integration made it an easy choice! As you say I'll still use Arduino/PlatformIO for things like my circuit board that drives the gas gauge in my converted electric Porsche based on the state of charge of the battery pack.
Yes, I run home-assistant with esp-home. It is good but I am not a trusting sort. YAML is me calling other peoples code. I started programming in assembly language where nothing executed beside what you wrote. If you have a problem, it is your code that is causing it. As I progressed to C, C++, Python, and now YAML, not much of what is executing is code I wrote. It is a paradigm shift and a lesson in trust. And now I ask Claude AI to help me code and more trust required. I am an old dog having some problems learning new tricks, but alas, I am adjusting🤔 For sure this speeds up my results orders of magnitude in time. I watch the esp-home compile and ponder all the code I did not have to write
I understand your point. Unfortunately, I do not trust myself because many of my programs contain errors;-) Also with Ardino IDE and ESP32 we run on other's code (libraries or Wi-Fi for example). Working in the industry with complex systems, my firm believe became that testing is the aproach, not understanding the code. Particularly not in programs with parallel execution. I always told people: "Assume that an untested system does not work". However, I wonder how this will be done with "AI automations" when the response on certain input can be different.
The whole "IoT" thing is layers upon layers of code written by God knows who/where/how. Testing can help with some assurance for functionality. Now think how much trust you can put in the security of these things. For me it felt similar to bungee jumping 😀
And I know you're going to say that you don't care who can see the temperature in your fridge Andreas :) The trouble is - you never know where people use the same devices/libraries/framework for something more important, and you find out when it's too late
@@dan-nutu You can always review the component code that underpins the higher abstract layer ESPHome works on. The world runs on common libraries these days. With ESPHome, all of those are open source and thus available for inspection. Writing your own functions is entirely possible too.
@@AndreasSpiessDo they really run in parallel though? Isn't it just you declare your components in parallel, but the compiler still calls an update function on each of the components you declare in YAML. I didn't quite get the use of lambda functions and scripts in ESP-Home. (And their difference)
I have waited for this video on this channel for about a year 🙂 - to me the Arduino IDE is already painful today if you do not need the millisecond response from the chip. Having different chips and screens around house and ESPhome makes it easy to implement new ideas. Mentioning the easy implementation and immediate feedback from “system” is also to me an important feature when comparing ESPhome with Arduino IDE
Indeed, the speed of implementation is a good thing. Yesterday, I needed a Wake on LAN button in a different subnet. An ESP8266 and a few lines of YAML...
Your video has expanded my understanding of ESPhome immensely as I am a noob in the HA world. If you feel comfortable with it, I would appreciate a video in which you expand on the methods for making sequential code in ESPhome. I see implementing this as bringing the best of both worlds together.
Great video, thank you for sharing. Definitely food for thought, I will try to use ESPHome more often. I've never seen a good example of running it standalone though, that is an interesting option
Nice to see this video from a perspective of somebody who never quite got to play with arduino ide and only knows esphome. I know this is surely not helping but I ditched my grafana + influxdb stack due to the added complexity it brought + extra maintenance time it required. To be very honest I have enough data I need from Home Assistant itself. That being said, very good video! Learned some stuff as well which I had no idea about :)
Thank you for sharing your thoughts. Interesting to see that needs can be different. I interact much more with Grafana than with HA (things in HA are often automated).
Like the others commenting here, I found this to be an excellent resource. The comments add value too. Andreas Spiess made my day and earned 10 Attaboys. 🤩
ESPhome is a fantastic project! I have to agree with you that the documentation, while detailed, misses explaining some key concepts. It often talks about "platforms" and it took me quite a long time to realize platforms are analogous to components.
I treat "platforms" as containing the code, and "components" as the object containing code and other definitions. This helps me to understand lists, for example.
So true, lots and lots of details, but not an overview of the basic concepts. (For a beginner to wrap his/her head around) This is the power of Andreas!!
Great video Andreas. I run InfluxDb and Grafana in Home Assistant OS, with sensor data being fed in etc. If this is of interest I'm more than happy to knowledge share etc. All the best from New Zealand.
Thank you! My question is very specific: How can I write the data of one sensor to one influxDB bucket and the data of another into a different bucket.
Thank you, Andreas! Perfect timing, and perfect "translation" from c++ concepts to yaml concepts ;-) One question though: What do I do, if my new sensor is not covered by the vast list of ESPhome sensors? It is connected by I2C and there exists working Arduino code for it. How do I turn this into a ESPhome device?
First, I would use a different sensor. And second, I probably would use C++. Third: Learn how to write an ESP32 component. Not impossible, but probably too much for just one sensor.
Thank you for this video. As a total noob and beginner to ESP and HA i can't get anything to work like i want 😅 especially since i don't even have HA yet
The declarative YAML stuff is also at the heart of what "DevOps" or "cloud engineers" do these days. It is in a way very powerful or expressive way to get a lot of done with "just a few lines". But on the contrast, it lacks a lot of convenient features developers have gotten used to with modern programming languages and IDE's such static analysis and autocomplete. In my experience there's typically 1:10 ratio of engineers that know their way around this in a typical project. These engineers often end up being the bottlenecks. In the worst case a "bus factor" of 1. MCU's are a very different topic as cloud engineering, but the principle here is the same. In essence, it's a GUI interface without the GUI. It might contain snippets of code/script but code it is not. I guess it is called "infrastructure as code" as it can be committed to version control with the rest of the code and also peer reviewed the same way. 😁
At least, autocomplete is built-in ESPhome. And the squiggles help to avoid obvious errors. But many more complex errors are only discovered during compilation. Maybe this will become better in the future, if the overall code is regularly checked, not only the few lines around where your write.
@@michaels3003 this is true, the ESPHome CLI is at the end a program written in Python that parse YAML files and decide to copy blob of c++ code in a directory to form a real project and than compile it for you.
I was skeptical Andreas, with my recent forray into bare metal programming with stm32 I have an unhealthy obsession with having to know exactly what the bits are doing and why and even fondle them as they move along their path, and these high level markup languages dont give me that fix. But i need to stop twiddling the bits and make something useful and this shoulld help, especially the easy wifi setup and integration into a control app. Thanks for introducing us to this.
You don't have to use ESPHome with Home Assistant, I use it directly with Node-RED And MQTT. Also, if using multiple devices, even of different types, one of the advantages of ESPHome is that you can split the YAML into components and then simply stich together the ones you want. So you get great reusability. ESPHome is the near enough the perfect balance between modularity and bespoke and I've used it now in preference to other ESP platforms for some years.
great, i moved to esphome when i started to use homeassistant heavily, it is very easy to use and there iis nearly always someone that had your same problem and someone else helped to solve it.... :)
4:19 The YAML specification states that the order of keys in a mapping is undefined (this corresponds e.g. to the behaviour of dict in Python 2), even though of course there is an ordering in the YAML document. That you can move around keys (and their values) in documents providing ESP32 specification is a logical result of that.
I agree with the definition. However, I never read it :-( Looking at the generated code helped me to understand it from the point of view of a "sequential" programmer...
@@AndreasSpiess Yes it is nice if you can get away with not reading the specs. I had to go over it multiple times for my Python library (ruamel.yaml) in which I wanted to be able keep the order of the keys (easier when you compare versions). And I still find things missed in the first few readings ...
an EXCELLENT video ! ...I have been wondering how to learn programming ESPHome for HomeAssistant, and have looked at the ESPHome website, but it really does not have a structured learning path, just examples of code for each sensor, ESP proce, etc... I am an old fart that programmed in FORTRAN many years ago, and was looking for a more detailed learning source, like also the C++ programming texts... while your video is VERY helpful in understanding, I still would like to find a good learning source... cheers !!
Influx? In the integration for influxDB (the yaml) you can set which data is stored in influx - and as soon as such data is populated, it's sent to influx instance. No problem at all. The only thing is you have to have HA in the middle of it.
Thank you for the tip! So I have to investigate a bit more. I do not want to have only one database for all data. I want to separate them (weather, energy, for example).
I currently use influxDB and Grafana that is integrated into HA. I currently run HA as a VM and works pretty well. I already have a separate influxDB and Grafana VM for other uses.
I haven't looked at the Influx problem, but if I were starting out, I'd get HA's Node Red listening on the sensors, then process, and feed them in to the database.
Thanks for the video. Will an ESPHome device continue to run unaffected if it loses connection to HA? If not then that's another use case for the IDE (i.e. hvac, water heater). I've had my water heater on an ESP32 since '17 after I got tired of the mechanical system failing. I wrote code for an HVAC controller back then too but have yet to test it. My telescope mount is driven by IDE code as well. 🙂
Working with Home Assistant and ESPhome for like 2 years now i still don't find it easy to work with YAML. The whole concept in both is still misterious at times. Recapping those concepts well surely help, t thanks for that.
You can use the mqtt component to publish to mqtt the values which will get picked up by influxdb. I think before the easy "homeassistant:" tag this is how it was done, many years ago, but I might confuse it with a different project.
How can one open the device dashboard shown at 7:39? I am running ESPHome from within Home Assistant running as a VM in VirtualBox, all on Win 11. Thank you
Writing JSON manually on one line is not easy for me. So I usually use a structure similar to YAML (Counting the {{}} is not easy for my old eyes). So the natural decision probably was: If you anyway need a sort of structure, why not omit the {{}}? As showed in the video, ESPhome YAML can contain also programming logic. So it is probably a mixture between both.
@@AndreasSpiess my first programming language was Algol 60 using 'begin' and 'end' as structural elements. C uses {} as json does. And I have not to count spaces which was the source of the majority of errors when I started ESPHome. Anyway, it is as it is and at the end of the day ESPHome is faster than writing arduino C-code by myself
@@AndreasSpiess json is not a programing language, YAML is not a language. Why always trying to reinvent the wheel ? All hat ESP home do could be done with library and an adhoc IDE, using C, C++, javascript or python. Using a data format to make code is absurd. And don't tell me it's easier for beginner just because not learning a real language is easier. What Home assistant have done is starting with creating a domotic system base you can managesd by configuring on the shelp component, but then they rapidly have been confronted to more complex logic and to keep a "simple" link between the graphical configuration interface and the scriptabale files they have put logic into configuration files. But it's confusing, annoying and quit cumbersome to write if you want complex logic to be implemented into Home Assistant. But as you conclude, it's the way to go if the project is adding relatively simple on the shelf components to our Home Assitant ecosystem.
This video is not for me (i use ESPHome for a few years now), still i learned some: coding and routines in ESPHome. I use the ESP's with ESPHome as a sensor-device, including buzzer, BME280 and RGB-led. But all the 'automations' are done in HomeAssistant. (Just as you stated in the end of the video). But if you don't have HA, an ESP with ESPHome can work on its own. How nice.
I share your concept of having the complexity inside HA. Still, some applications (particularly interactions) are probably better executed on the device itself (faster reaction, for example).
I see devices as standalone that get parameters from HA. So it HA fails, the basic functionality still works. Eg thermostat. I'm the only "technerd" in the family and everything is setup so no basic (house) functionality is lost when I'm out of the country or otherwise occupied. I like this video because it gives me options to keep local logic without the need to go full Arduino. Thanks.
I sometimes need things to be taken care of even if the (Wi-Fi) connection to Home Assistant is temporarily not available, so for these cases I write the automations to run on the esp device running ESPHome (BTW Andreas, I think it would have been useful to drop a quick mention in the video that ESPHome works on both esp8266 and esp32 chips). Example: I have one esp8266 module that monitors the temperature sensors in my 19" rack and sets the PWM ratio for the cooling fans. I want the fans to work even if the connection to HA is temporarily down for whatever reason. So running the automations on the esp module allows me to do that, simply updating HA with the current values when the connection is reestablished.
I have tones of devices in ESPhome but also another tone of C++ ones. All depends what the usage is - for Home Assistant for sure ESPHome is much, much easier, unless it is very complicated device i.e. Hot Plate or so.
@AndreasSpiess then you may be able to use an http request directly on esphome to the Influxdb url. I use this on my raspberry pi but never tried it on esphome.
It controlled via separate options. In binary sensor component you have filters, like delayed_on: 100ms or delayed_off: 100ms (i.e. you must hold for 100ms ). You can even implement different actions on short and long press, double and triple clicks - via automations IIRC (I did implement double click long time ago)
O man my petibro cat fountain has a mode that turns it on when the cat is in range if you have it set to battery mode which is the default setting when it's not plugged into the wall.
I find sometimes order matters In YAML. The file seems to execute top to bottom and sometimes A must happen before B. Maybe not a problem with ESP Home but definitely an issue for the HA config file.
I did not recognize it in ESPhome. But maybe it is also true here. But I only meant components in this respect. Inside components, the sequence can matter a lot.
Very interesting - It would be interesting to see you ask an AI to write the equivalent arduino studio code from your esphome code... In my experience people are massively underestimating the existing power of AI. With a good AI whisperer like me, things go amazingly fast.
And where does AI fit in? As a programmer, your boss or customer will ask you in the future to use these new tools to save time. He will call it "productivity increase" ;-)
Thanks for this good video. What do you think about micropython on esp32 ???? I already use arduino ide, but for my work i need to program some app and i think about learning python (one language multiple platform : i'm not a big c++ fan). Thanks for your response
Micropython is also a language on a higher level. For me, it is replaced by ESPhome for most applications. Complex and fast things are done in C++ anyway.
*YAML is not a "programming language"* -- it's just a data model language, similar to XML or JSON. In this case, the YAML data format is just used to configure the ESPHome framework. The difference between something like ESPHome and an Arduino INO is that the former can only execute whatever components have already been defined in the ESPHome ecosystem. That said, a lot of Arduino users like Arduino because it's "simple" and they are not programmers. In that case, a simple configuration language like the one used by ESPHome is much better for these users -- they can just use the existing bricks, without having to build their own.
The community is big already, and many solution are documented as entries there. If you do not find your problem discussed somewhere, you know: It will be hard ;-)
Like all forums, ESPHome is not immune to idiots and superior complex people... I moderate the FB group and we generally mute or remove the worst offenders...
Hello. Can you help me with ESPHome? How to work with SD? I wish to play a mp3 or wav file. I have media player and DAC and I can play music using Home Assistant but not from SD. I was looking for a solution for the past week 😢. I have esp32 and a SD board connected
I use ESPHome in some of my sensors at home...but on one occasion a ESPHome update screwed up my Hot Water sensor???...I re-flashed with a clean install of ESPHome...configured it...still did not work??? I think that updates should be pointed out is a possible flaw in their process???? I ended up reflashing it in Arduino MQTT code....been working ever since.
I generally don't update existing devices unless I'm making changes to the device... I would suggest not updating unless you really need to. If you do, then take the time to read the breaking changes carefully to understand the impacts of revision changes...
I agree: MQTT is more standardized. And the ESPhome (fast) update policy is not always good ( mentioned that fact in my HA video). I would create an issue in the sensor project that the maintainer can correct it. It seems to be a classical bug.
that's pretty, I have to do it in CLI, using Nano... then I type: esphome run thingy.yaml. Sometimes I have to add the name to my hosts file so it can upload to the esp32 OTA. HA then grabs it.
Internet says ESPHome uses Python to generate C++ code from YAML configuration files edited by the user. This is a very old idea, but not much used up to this point (I think).
hey andi! mini antwort im breite bärndütsch 😄 merci für dä abriib. also quasi es "deklerativs modäll" wome mit yaml files erstellt. gueti abstraktion vo esphome! mache itz ou no eine uf tüpflischisser... hesch gwüsst, yaml isch ke programiersprach 😂... uuhhh de muess me de aube grad korrigiere. aber weme z video luegt zeigsch ja genau dr ungerschiid vo programiere zu deklariere. aber houpsach me het öpis chönne "korrigiere" 🤪... mach witer mit tüftle, häb spass u aues guete🫡
Wenn wir ganz genau werden wollen gehen wir zum "Duden". Der schreibt: Programmiersprache: System von Wörtern und Symbolen, die zur Formulierung von Programmen (4) für die elektronische Datenverarbeitung verwendet werden. Jetzt bist du dran ;-)
Hello Sir this comment is not related to the video, but I’m looking for some information, im trying to make a device wireless I’m normally send and receive data from it but I have issues with the cable is an usb device so I was thinking to add an ESP32 on the end of the device and another ESP32 to the computer, I don’t have much knowledge, being watching your videos I’m trying to learn so any answer will be appreciated
Hassio cannot be run offline, right ? I dont trust the interweb, nor do i want to become dependent. So i need a fallback. I choose MQTT. So i prefer ESPEasy for my sensors.
If you prefer you can install Homeaasistan as python app to wheel and run it directly from there. As well as ESPHome can be installed directly (I run it from my notebook).
This style of modern programming with something like app.run() inside the main loop makes me frustrating. I once spent more than half an hour trying to understand how nordics ble example with simle blink logic works. It appeared that particular led.on/off() function was buried five leves deep (if count from main). I still don't understand why on earth they need so much levels of abstraction on a such small device. 😢
0:20 So if you understand YAML to be a programming language ... then there you have your error. YAML is a configuration language. Like TOML, Windows INI files etc. It is used to configure a program generator (this is what ESPHome actually is). But it isn't really a programming language in itself.
YAML is a markup language and therefore totally inappropriate for programming (sequences, loops, branching). So it fits well for describing the properties of a sensor but fails when it comes to automation (for example).
When you talk about using Home Assistant instead of Node Red, I guess you're not referring to automations, but all the rest. There's a lot of information coming from my esphome devices to home assistant, that I use in node red automations
I already started to transfer some of the simple automations to HA because then it is in one place. The more complex flows are still in Node-Red and I heavily use the interaction between the two.
@AndreasSpiess my reasoning is the opposite of yours: I don't transfer any automations from node red to Home Assistant, as otherwise I have my automations in two places which will confuse me when I need to start digging 😊
@@PersonXes All of my automations are in NodeRed... Automations in HA 5 years ago were terribly limited, thus NR was prefered. HA automations today are better, but I'm sticking with what I know and the flexibility NR offers still leaves HA in the dust.. I have elements in NodeRed that are not possible to get into HA natively, thus it is the better place for automation.
As a longtime software engineer, let me say that it’s okay that you didn’t like YAML. I don’t know anyone that actually _likes_ it, we just learned to deal with, like Stockholm Syndrome.
YAML is a very good and readable language. It's just too complex and the early versions had a few stupid decisions ("on" being interpreted as a bool, etc). We need a subset of it (not JSON but a readable one). Unfortunately TOML has appeared to fill this niche and it's basically all the worst traits of YAML and ini-files combined...
How would you save data to a SDcard in YAML, and make it write in a circular buffer, so only saving the latest data. It only works for an ESP32 ? Isn't that rather limited? Being an old salt, I can't stand having to learn new gizmo languages just to do what I already can do. I know I should learn python, but I just can't. I discovered uLisp (being an old Lisp guy) and it actually runs on all the micros that have enough memory. But frankly C does the job for small apps. In fact, I hate C++ when C is just fine for a tiny micro, I just rewrote the only actually working RTSP code for arduino I could find, and what a mess of C++ it was, crudely adapted to arduino. Now its a single arduino ino file you just load and compile in the ide, no libraries, it just works now.
ESP32 can interface with SD storage, there is example code in the ESPHome docs on how to do this. I'd recommend against rapid writes to flash media as they don't last long if constantly being written to. Might be better to use MQTT and have the data off loaded to a more appropriate storage device. You can still locally store latest data for on-chip logic of course...
The idea of ESPhome is to create connected devices. This is why I do not use SD cards anymore. I transfer the readings to a more capable device for future use. So I do not know.
@@AndreasSpiess That's the stu,pidest thing I heard since Go messed up K&R style curly braces. Developers, who limit everyone else just because they like one style of syntax, are bad.
Where are the "completely different things". Both create a device that does what I want (if I am happy). Just two different roads or vehicles, perfect for a comparison in my view.
to access cpp src from haos, do this:
- open terminal (don't have it? have it...)
- go inside the esphome container: docker exec -it $(docker ps --filter "name=esphome" --format "{{.Names}}") bash
- go in /data/build/your_device_name/src
pin this if you want
Cool! It works! Thank you. Pinned.
Classic, classic Spiess video.
Breaking down how things work, followed by examples and then a clear conclusion.
👍🏼💁🏻♂️
Thank you for your kind words!
@AndreasSpiess So well deserved.
You put so much work into those videos.
@andreasspiess thank you for all your great work!
A fantastic guide and a huge time saver. I might never have gone in this direction, but I probably will now. We definitely will need a way to get the data out to complete the job and enable so many other great projects.
Thanks again!
Good that I motivated you to try it!
MQTT is supported. Also, you can write your own components if the existing ones don't quite do what you want... Plenty of Open Source components to clone and modify for your needs.
00:00 Arduino IDE vs. ESPHome: Introduction
01:05 Understanding the Fundamentals: C++ vs. YAML
03:08 Basics of YAML for ESPHome: Key-Value Pairs & Objects
06:10 First ESPHome Project: Wi-Fi Connectivity and Basic Setup
07:50 Building a Sensor with ESPHome: BME280 Example
09:33 Adding Outputs and Switches: Controlling LEDs
10:48 Examining the Generated Arduino Code: PlatformIO Project
12:10 Integrating an OLED Display: Lambda Functions in YAML
14:08 Implementing Logic with Automations: Button and Switch Control
15:56 Using Scripts in ESPHome: Reusable Functionality
18:19 Verdict: ESPHome vs. Arduino IDE - Pros and Cons
21:03 Future Use Cases and Conclusion
These chapters were created entirely locally on my Debian machine using open-source software (Whisper, Ollama, Qwen2.5:14b).
@Andreas Spiess - Use the chapters in your video description if you want, no need for credits.
Great overview of ESPhome concepts - this would have saved me so much time when getting started. A few other tips that I learnt the hard way, and wish I took this path from the beginning: 1) Compiling ESPhome is so slow on something like a RPi for Home Assistant. It is far better to do the compiling and flashing from a high performance desktop (running ESPhome as a container). The devices can still be discovered by Home Assistant. 2) Keep all your secrets (passwords and IP addresses) in the secrets yaml file. This simplifiles your boilerplate code for each project. 3) Use name substitutions at the top of your file, which means the main yaml body is more generic and can easily be shared with others, or duplicated across similar projects and devices.
Thank you for your additions. I agree with all of them. Frequent users know that one of the reasons I moved to X86 and Proxmox was the slow speed of ESPhome compilation on the Raspberry 4. With my second-hand miniPC the speed is ok...
I kind of knew a lot of this, but had never really thought about it in a structured way. Thank you for making this video, it was really helpful and added to my knowledge! Merry Xmas to you and your family!
Merry Christmas, too!
A well structured and educational video from Andreas, what a nice way to spend a few relaxing moments on Sunday afternoon 😊
Thank you for your kind words!
YAML is not a programming language, but a configuration file (like JSON), by the way is quite similar to JSON but uses less data... 😊👍👍👍
Yes Sir.
"Human-readable data-serialization language."
You are right!
@@michaels3003 lol human readable, key value pairs? ... thats machine readable, if i have to memorize these high level abstractions of what they mean when they say "home:something" i might as well learn the code that manipulates the registers that set these functions instead, maybe not as "easy" to read but you have to understand what they mean just the same as any readable word anyway so i dont see the effeciencey gains here, infact you just have to memorize a layer of bloat and lose the undersatnding of what youre actually doing with these high level abstractions and now youre stuck when something goes wrong or want to add a feature. Im all for abstracting messy code awway, but it should be code you wrote, or at leaste copied. I have 250 lines of code that uses no libraries except a font.h file written in arduino IDE stm32c6 (the low ram version) that sets up the BME sensor and calibrates it too your liking, weather (pun intended) you want to oversample temp/ humidity or preasure, or not which is critical for any power savings for a usable weaher station on batttery. Outputting to an oled display with a handsome font ,fittingon 32 kb or ram. I wonder how much ram this esp32 bloatware version cost us eh Andreas? ;) I kid, the register manipulation code is ugly, but kind of simple, and now you know where the data is and can interface it with whatever database you want. By the way i not a pro programmer, i just used chatgtps help to setup this sensor with minimal libraries and resources.
I liked JSON immediately but YAML sucked at first.
Very good video! I have been using ESPHome for a couple of years now but I still learned a lot from your video! Thanks!
Glad it was helpful!
Very nice creating this overview, to the point and sufficient depth. Thank you!
Glad it was helpful!
As always, a good and informative video full of relevant info
Thank you!
One thing with YAML is to understand the difference between declarative (= describing the end result and the system figures everything out) and imperative (= do this then do something else, ...) coding. Most coding was always done imperative and declarative is a fairly new thing.
I agree. Plus, ESPhome is a mixture of both...
I have been avoiding ESPhome but after watching this video I see using ESPhome for HA projects in my future - thanks Andreas!
Very good! Trying is a good concept. Then you still can decide not to use it.
I love the way you can make almost any appliance or gadget smart with a quickly built esphome node. Just need a relay or a motor to actuate. So many integrated components. It is amazing !
Wow, wow, wow. So informative and useful. Its amazing what you do.
Thank you very much!
There are various ways to write ESPHome sensors to a database such as InfluxDB, depending on what you want to do.
- ESPHome + MQTT: ESPHome offers support for sending data to MQTT topics, so you can go the route completely without Home Assistant. The data could then be written to InfluxDB, for example, using your own program or Node-RED.
- ESPHome + Home Assistant + Nodered: The Home Assistant add-on for Node-RED can capture specific sensor data and write it to the desired database using a database add-on such as InfluxDB.
- Customize Home Assistant Recorder: There are ways to customize the recorder in Home Assistant so that certain values are written to the desired location, such as the Influx database.
- Long-term sensor data in Home Assistant: If the data ends up in Home Assistant anyway, there is the option of writing long-term data to the Home Assistant database. It is not always necessary to use an Influx database for long-term data.
Thank you for your answer. Currently, I use Node-Red to post the data to influxDB (your 3rd proposal) and I once used influxDB for all HA data. After your comment, I looked again at this integration, and it seems you can now limit the sensor data written to influxDB. And maybe I could even have more than one bucket. That would solve my problem of having topic-specific buckets.
@AndreasSpiess Yes, it did so too. (Inspired by your videos) But unfortunately Influx1.8 is discontinued and migration to newer versions is complicated. So i switched to postgres as my main database, since there is a "postgres for everything" movement.
@@ei23de I am also not happy with the "behavior" of the organization behind influx. For the moment, I try to stick with it because I did not want the effort for migration. Mabe, one day it anyway has to be done...
@@AndreasSpiess Kind of this is what they mean when they say "there is no free lunch", right?
I've been on the journey of learning ESPhome recently, and this video condenses much of what I've discovered. Thank you Andreas.
A tip I learned recently concerning the use of LVGL and local displays, is to build a simulation environment using SDL2. It saves all of those flash writes whilst making small changes to layout and data formatting and can connect to live ESPhome. eg: I connect my sensors to ESPhome, and then fiddle with the display output on my PC simulation until I'm happy, and then flash the local display.
So far I did not use LVGL. So thank you for the tip!
We are back at the first row!
Yes! Some viewers wished it...
The first row had several thousand seats today!
That was fantastic, you clearly explained the problems I was having.
Thank you!
Perfect timing, after just setting up my Home Assistant to monitor and control my home, and now adding modules to support my filament storage, and humidity control.
Indeed a perfect example for ESPhome.
What a nice subject to cover after our discussion on your previous video about the lora mailbox notifier. Thank you for bringing attention to ESPhome.
My pleasure!
Thank you again, even after experimenting and quite some frustrations on the YAML code I got things working. This video still learned me a lot! And happy to see you use chat gpt for help as well. This tool makes programming so much easier!
YAML is hard for many "conventional" programmers. I assume it is much easier for a guy not knowing how to program...
Thanks Andreas for the video and for the good and helpful information - I will try it also and I guess your info will save a lot of experimental time on my side.
Enjoy!
Thanks for this introduction on YAML, you triggered my interest.
Glad it was helpful!
Long over due clear explaination of YAML which I still loathe!!! Wish I had this 4 years ago. JSON is easier for me to read and understand due to the open/close separation of items. Seeing how list, ie, arrays, and automation, decision branches, are created helps a lot!
As always, you're clear and concise, and great to see an fellow DECcie still "Kicking it"
Indeed, some fellow DECies still kick while others are already dead. So let's enjoy the rest ;-)
Thanks Andreas, this was another very interesting video. I like the way you setup your videos. If I have a home project to do, I will definitely check back and let them guide me.
Thank you for your feedback!
My daily driver for hobby projects is PlatformIO, but after seeing your video, I will give ESP-IDF with yaml a shot. Thanks for the new ideas!
For a quick project it is perfect! My last one: A wake-on-lan button in a different subnet with an ESP8266...
A great video, that explains everything really really well. As a novice with esp32's in general you have massively increased my understanding. Especially thst red squiggly line don't always mean a syntax error in the code i've just pasted.. 😂.
Indeed, the best is really to hit "install"...
indeed, great thanks for this well explained guide. Even for using esphome for long time, you explained me the concept much better. That's what i really about your channel, the well explained concepts of various topcs.
Thank you for your kind words. giving a bit of structure to the things is one of the main goals of this channel.
Exactly what I need a great clarification from the Master :) with the help of chatGPT I managed to setup a Victron UART reader for my solar system, Bedroom Air Qualtiy sensor running BME680 and MH Z17 CO2 sensor, and HX711 for weight scale. Thank you!
Cool projects! Indeed, ChatGPT became a regular "CoPilot" for me. Sometimes very helpful and in the worst case just a waste of a bit of time.
I really like you videos, thanks soooooo much for your content!!
My pleasure!
Another super useful video! I had heard of ESPhome but didn't know its capabilities. I have a project idea for a stepper motor control that will raise and lower my window blinds and the Home Assistant instant integration made it an easy choice! As you say I'll still use Arduino/PlatformIO for things like my circuit board that drives the gas gauge in my converted electric Porsche based on the state of charge of the battery pack.
Cool! You have an electric Porsche!
Yes, I run home-assistant with esp-home. It is good but I am not a trusting sort. YAML is me calling other peoples code. I started programming in assembly language where nothing executed beside what you wrote. If you have a problem, it is your code that is causing it. As I progressed to C, C++, Python, and now YAML, not much of what is executing is code I wrote. It is a paradigm shift and a lesson in trust. And now I ask Claude AI to help me code and more trust required. I am an old dog having some problems learning new tricks, but alas, I am adjusting🤔 For sure this speeds up my results orders of magnitude in time. I watch the esp-home compile and ponder all the code I did not have to write
I understand your point. Unfortunately, I do not trust myself because many of my programs contain errors;-) Also with Ardino IDE and ESP32 we run on other's code (libraries or Wi-Fi for example).
Working in the industry with complex systems, my firm believe became that testing is the aproach, not understanding the code. Particularly not in programs with parallel execution. I always told people: "Assume that an untested system does not work".
However, I wonder how this will be done with "AI automations" when the response on certain input can be different.
The whole "IoT" thing is layers upon layers of code written by God knows who/where/how. Testing can help with some assurance for functionality. Now think how much trust you can put in the security of these things. For me it felt similar to bungee jumping 😀
And I know you're going to say that you don't care who can see the temperature in your fridge Andreas :) The trouble is - you never know where people use the same devices/libraries/framework for something more important, and you find out when it's too late
@@dan-nutu You can always review the component code that underpins the higher abstract layer ESPHome works on. The world runs on common libraries these days. With ESPHome, all of those are open source and thus available for inspection. Writing your own functions is entirely possible too.
@@AndreasSpiessDo they really run in parallel though?
Isn't it just you declare your components in parallel, but the compiler still calls an update function on each of the components you declare in YAML.
I didn't quite get the use of lambda functions and scripts in ESP-Home. (And their difference)
Thanks for the primer.
You are welcome!
I have waited for this video on this channel for about a year 🙂 - to me the Arduino IDE is already painful today if you do not need the millisecond response from the chip. Having different chips and screens around house and ESPhome makes it easy to implement new ideas.
Mentioning the easy implementation and immediate feedback from “system” is also to me an important feature when comparing ESPhome with Arduino IDE
Indeed, the speed of implementation is a good thing. Yesterday, I needed a Wake on LAN button in a different subnet. An ESP8266 and a few lines of YAML...
Your video has expanded my understanding of ESPhome immensely as I am a noob in the HA world.
If you feel comfortable with it, I would appreciate a video in which you expand on the methods for making sequential code in ESPhome. I see implementing this as bringing the best of both worlds together.
I showed the principle (with consecutive actions), so I do not plan such a video. And as I said, Ask ChatGPT. It can help a lot.
Great video, thank you for sharing. Definitely food for thought, I will try to use ESPHome more often. I've never seen a good example of running it standalone though, that is an interesting option
It should be easy: Omit api: and add for example MQTT for communication (if you need it).
To have direct control and read out without HomeAssistant use the included webserver this can have a output window for log too.
web_server:
port: 80
Thank you for the additional info.
Very informative and usefull!
Thank you!
Nice to see this video from a perspective of somebody who never quite got to play with arduino ide and only knows esphome. I know this is surely not helping but I ditched my grafana + influxdb stack due to the added complexity it brought + extra maintenance time it required. To be very honest I have enough data I need from Home Assistant itself. That being said, very good video! Learned some stuff as well which I had no idea about :)
Thank you for sharing your thoughts. Interesting to see that needs can be different. I interact much more with Grafana than with HA (things in HA are often automated).
Like the others commenting here, I found this to be an excellent resource. The comments add value too. Andreas Spiess made my day and earned 10 Attaboys. 🤩
Indeed, in the comments of my videos usually is more content than in the video ;-)
Another great video. EspHome is a very powerful tools.
Thank you!
ESPhome is a fantastic project! I have to agree with you that the documentation, while detailed, misses explaining some key concepts. It often talks about "platforms" and it took me quite a long time to realize platforms are analogous to components.
I treat "platforms" as containing the code, and "components" as the object containing code and other definitions. This helps me to understand lists, for example.
So true, lots and lots of details, but not an overview of the basic concepts. (For a beginner to wrap his/her head around)
This is the power of Andreas!!
Great video Andreas. I run InfluxDb and Grafana in Home Assistant OS, with sensor data being fed in etc. If this is of interest I'm more than happy to knowledge share etc. All the best from New Zealand.
Thank you! My question is very specific: How can I write the data of one sensor to one influxDB bucket and the data of another into a different bucket.
Thank you, Andreas! Perfect timing, and perfect "translation" from c++ concepts to yaml concepts ;-)
One question though: What do I do, if my new sensor is not covered by the vast list of ESPhome sensors? It is connected by I2C and there exists working Arduino code for it. How do I turn this into a ESPhome device?
First, I would use a different sensor. And second, I probably would use C++. Third: Learn how to write an ESP32 component. Not impossible, but probably too much for just one sensor.
@@AndreasSpiess thank you for your comment!
Thank you for this video. As a total noob and beginner to ESP and HA i can't get anything to work like i want 😅 especially since i don't even have HA yet
So: One step after the other ;-)
The declarative YAML stuff is also at the heart of what "DevOps" or "cloud engineers" do these days. It is in a way very powerful or expressive way to get a lot of done with "just a few lines". But on the contrast, it lacks a lot of convenient features developers have gotten used to with modern programming languages and IDE's such static analysis and autocomplete. In my experience there's typically 1:10 ratio of engineers that know their way around this in a typical project. These engineers often end up being the bottlenecks. In the worst case a "bus factor" of 1.
MCU's are a very different topic as cloud engineering, but the principle here is the same. In essence, it's a GUI interface without the GUI. It might contain snippets of code/script but code it is not. I guess it is called "infrastructure as code" as it can be committed to version control with the rest of the code and also peer reviewed the same way. 😁
At least, autocomplete is built-in ESPhome. And the squiggles help to avoid obvious errors. But many more complex errors are only discovered during compilation. Maybe this will become better in the future, if the overall code is regularly checked, not only the few lines around where your write.
Internet says ESPHome uses Python to generate C++ code that is then compiled.
@@michaels3003 this is true, the ESPHome CLI is at the end a program written in Python that parse YAML files and decide to copy blob of c++ code in a directory to form a real project and than compile it for you.
I was skeptical Andreas, with my recent forray into bare metal programming with stm32 I have an unhealthy obsession with having to know exactly what the bits are doing and why and even fondle them as they move along their path, and these high level markup languages dont give me that fix. But i need to stop twiddling the bits and make something useful and this shoulld help, especially the easy wifi setup and integration into a control app. Thanks for introducing us to this.
I am old, and therefore, time is valuable (it soon will run out). That is why I like such time-savers ;-)
You don't have to use ESPHome with Home Assistant, I use it directly with Node-RED And MQTT. Also, if using multiple devices, even of different types, one of the advantages of ESPHome is that you can split the YAML into components and then simply stich together the ones you want. So you get great reusability. ESPHome is the near enough the perfect balance between modularity and bespoke and I've used it now in preference to other ESP platforms for some years.
I agree that splitting YAML (also in HA) is a good idea. And I thought I had mentioned that ESPhome can be used stand-alone and integrated with MQTT.
great, i moved to esphome when i started to use homeassistant heavily, it is very easy to use and there iis nearly always someone that had your same problem and someone else helped to solve it.... :)
I agree. The community is already huge!
4:19 The YAML specification states that the order of keys in a mapping is undefined (this corresponds e.g. to the behaviour of dict in Python 2), even though of course there is an ordering in the YAML document. That you can move around keys (and their values) in documents providing ESP32 specification is a logical result of that.
I agree with the definition. However, I never read it :-( Looking at the generated code helped me to understand it from the point of view of a "sequential" programmer...
@@AndreasSpiess Yes it is nice if you can get away with not reading the specs. I had to go over it multiple times for my Python library (ruamel.yaml) in which I wanted to be able keep the order of the keys (easier when you compare versions). And I still find things missed in the first few readings ...
an EXCELLENT video ! ...I have been wondering how to learn programming ESPHome for HomeAssistant, and have looked at the ESPHome website, but it really does not have a structured learning path, just examples of code for each sensor, ESP proce, etc... I am an old fart that programmed in FORTRAN many years ago, and was looking for a more detailed learning source, like also the C++ programming texts... while your video is VERY helpful in understanding, I still would like to find a good learning source... cheers !!
The next step is trying a few projects with the help of ChatGPT (not Gemini)...
@@AndreasSpiess will try that, Thanks !!
Influx? In the integration for influxDB (the yaml) you can set which data is stored in influx - and as soon as such data is populated, it's sent to influx instance. No problem at all. The only thing is you have to have HA in the middle of it.
Thank you for the tip! So I have to investigate a bit more. I do not want to have only one database for all data. I want to separate them (weather, energy, for example).
I'd also be interested to find this (i.e. how to separate data sent to influxdb).
I currently use influxDB and Grafana that is integrated into HA. I currently run HA as a VM and works pretty well. I already have a separate influxDB and Grafana VM for other uses.
I haven't looked at the Influx problem, but if I were starting out, I'd get HA's Node Red listening on the sensors, then process, and feed them in to the database.
Thanks for the video. Will an ESPHome device continue to run unaffected if it loses connection to HA? If not then that's another use case for the IDE (i.e. hvac, water heater).
I've had my water heater on an ESP32 since '17 after I got tired of the mechanical system failing. I wrote code for an HVAC controller back then too but have yet to test it. My telescope mount is driven by IDE code as well. 🙂
Yeah all code runs locally. You won't be able to control it from ha for obvious reasons but all code that you write in esphome runs locally
If you omit the line "api:" you will have no HA connection. But you still have Wi-Fi or OTS, and can add MQTT
Working with Home Assistant and ESPhome for like 2 years now i still don't find it easy to work with YAML. The whole concept in both is still misterious at times. Recapping those concepts well surely help, t thanks for that.
You are welcome!
Perfect introduction. I found the esphome and yaml configuration very strange or confused to me, to be honest !
So we are already 2 ;-)
You can use the mqtt component to publish to mqtt the values which will get picked up by influxdb. I think before the easy "homeassistant:" tag this is how it was done, many years ago, but I might confuse it with a different project.
Thank you. So far, I have never come across a direct input of mqtt into influxDB. Maybe they use a converter. I will have to investigate
How can one open the device dashboard shown at 7:39? I am running ESPHome from within Home Assistant running as a VM in VirtualBox, all on Win 11. Thank you
This is device in Homeassistant. Settings --> devices and integrations --> ESPhome --> some device.
YAML is just a config data format. pure data. kinda like json or xml
@zeffster2 I am always asking why yaml was created instead of using existing standards such as json.
Writing JSON manually on one line is not easy for me. So I usually use a structure similar to YAML (Counting the {{}} is not easy for my old eyes).
So the natural decision probably was: If you anyway need a sort of structure, why not omit the {{}}?
As showed in the video, ESPhome YAML can contain also programming logic. So it is probably a mixture between both.
@@AndreasSpiess my first programming language was Algol 60 using 'begin' and 'end' as structural elements. C uses {} as json does. And I have not to count spaces which was the source of the majority of errors when I started ESPHome. Anyway, it is as it is and at the end of the day ESPHome is faster than writing arduino C-code by myself
@@AndreasSpiess json is not a programing language, YAML is not a language. Why always trying to reinvent the wheel ? All hat ESP home do could be done with library and an adhoc IDE, using C, C++, javascript or python. Using a data format to make code is absurd. And don't tell me it's easier for beginner just because not learning a real language is easier. What Home assistant have done is starting with creating a domotic system base you can managesd by configuring on the shelp component, but then they rapidly have been confronted to more complex logic and to keep a "simple" link between the graphical configuration interface and the scriptabale files they have put logic into configuration files. But it's confusing, annoying and quit cumbersome to write if you want complex logic to be implemented into Home Assistant. But as you conclude, it's the way to go if the project is adding relatively simple on the shelf components to our Home Assitant ecosystem.
This video is not for me (i use ESPHome for a few years now), still i learned some: coding and routines in ESPHome.
I use the ESP's with ESPHome as a sensor-device, including buzzer, BME280 and RGB-led. But all the 'automations' are done in HomeAssistant. (Just as you stated in the end of the video).
But if you don't have HA, an ESP with ESPHome can work on its own. How nice.
I share your concept of having the complexity inside HA. Still, some applications (particularly interactions) are probably better executed on the device itself (faster reaction, for example).
I see devices as standalone that get parameters from HA.
So it HA fails, the basic functionality still works.
Eg thermostat.
I'm the only "technerd" in the family and everything is setup so no basic (house) functionality is lost when I'm out of the country or otherwise occupied.
I like this video because it gives me options to keep local logic without the need to go full Arduino.
Thanks.
I sometimes need things to be taken care of even if the (Wi-Fi) connection to Home Assistant is temporarily not available, so for these cases I write the automations to run on the esp device running ESPHome (BTW Andreas, I think it would have been useful to drop a quick mention in the video that ESPHome works on both esp8266 and esp32 chips).
Example: I have one esp8266 module that monitors the temperature sensors in my 19" rack and sets the PWM ratio for the cooling fans. I want the fans to work even if the connection to HA is temporarily down for whatever reason. So running the automations on the esp module allows me to do that, simply updating HA with the current values when the connection is reestablished.
I have tones of devices in ESPhome but also another tone of C++ ones. All depends what the usage is - for Home Assistant for sure ESPHome is much, much easier, unless it is very complicated device i.e. Hot Plate or so.
Thank you for sharing your experience. It will help others to decide.
ESPhome works also fine on the Raspberry Pi Pico.
Thank you for the info. Where would you prefer it over an ESP32?
@@AndreasSpiess When more i/o ports are needed, ESP32 have a number of GPIO which are restricted in use, example 34 and up are input only.
have not a real preference for small projects. For real small projects as one or two sensors only the ESP 8266 prefers even.
For InfluxDB I have the esphome sensors send data to mqtt and then nodered takes it and sends to influx
Currently, I use HA sensors (from the companion app) in Node-Red and do the same. So, I do not need MQTT. This is what I would like to avoid...
@AndreasSpiess then you may be able to use an http request directly on esphome to the Influxdb url. I use this on my raspberry pi but never tried it on esphome.
I am curious: the push button you used requires debounce. Is that generated automatically? Time control?
It controlled via separate options. In binary sensor component you have filters, like delayed_on: 100ms or delayed_off: 100ms (i.e. you must hold for 100ms ). You can even implement different actions on short and long press, double and triple clicks - via automations IIRC (I did implement double click long time ago)
Super cool
Thank you!
you're breaking my 'tasmota-lover' heart, esphome looks more technically elegant. BTW have you tried berry on Tasmota for these purposes?
No, I never used it. I tend to stick to one solution for a particular problem to save the initial time for learning :-(
Yaml can seem difficult at first but it’s superior to JSON on the whole after you learn it.
JSON is probably more made for machines with all the patentesis...
O man my petibro cat fountain has a mode that turns it on when the cat is in range if you have it set to battery mode which is the default setting when it's not plugged into the wall.
It's the same here, with the exception that my PIR sensor also starts the pump when anyone else is within its range. That is what I want to omit.
I find sometimes order matters In YAML. The file seems to execute top to bottom and sometimes A must happen before B. Maybe not a problem with ESP Home but definitely an issue for the HA config file.
I did not recognize it in ESPhome. But maybe it is also true here. But I only meant components in this respect. Inside components, the sequence can matter a lot.
Very interesting - It would be interesting to see you ask an AI to write the equivalent arduino studio code from your esphome code...
In my experience people are massively underestimating the existing power of AI. With a good AI whisperer like me, things go amazingly fast.
I also use ChatGPT for coding C++ and I agree, it is very helpful. Still, the differences stay more or less the same.
this very nice
Thank you!
Well for me as a programmer its a big difference: ESPHome you are just configuring existing program. ArduinoIDE YOU are making the program
And where does AI fit in? As a programmer, your boss or customer will ask you in the future to use these new tools to save time.
He will call it "productivity increase" ;-)
what i hate about esphome is the lack of clear guidance and examples on what is supported and what not.
This frustration lead to this video ;-)
Same here. I had to do alot of research to figure out how to get MQTT devices working properly in HA. Once I figured out the logic it's not too bad.
Do we have a good source of YAML tutorial for beginners?
Many of the typical HA channels have some sort of YAML tutorials for HA (e.g.
Smart Home Junkie). UA-cam search should find them for you.
@AndreasSpiess Thankyou
How much time per line of code did it take? How much time would it take in either IDE?
No idea. But the # of lines of code would probably be 10x more in C++. And do not forget the debugging and testing...
Thanks for this good video. What do you think about micropython on esp32 ???? I already use arduino ide, but for my work i need to program some app and i think about learning python (one language multiple platform : i'm not a big c++ fan). Thanks for your response
Micropython is also a language on a higher level. For me, it is replaced by ESPhome for most applications. Complex and fast things are done in C++ anyway.
@@AndreasSpiess Thanks
*YAML is not a "programming language"* -- it's just a data model language, similar to XML or JSON. In this case, the YAML data format is just used to configure the ESPHome framework.
The difference between something like ESPHome and an Arduino INO is that the former can only execute whatever components have already been defined in the ESPHome ecosystem.
That said, a lot of Arduino users like Arduino because it's "simple" and they are not programmers. In that case, a simple configuration language like the one used by ESPHome is much better for these users -- they can just use the existing bricks, without having to build their own.
It depends on your definition of "programming language". However, most "programmers" would agree.
Wow, sounds great for the part time hobbiest. Wonder if the forums are full of people that will make you work to solve a question.
The community is big already, and many solution are documented as entries there. If you do not find your problem discussed somewhere, you know: It will be hard ;-)
Like all forums, ESPHome is not immune to idiots and superior complex people... I moderate the FB group and we generally mute or remove the worst offenders...
@dougle03 never thought about looking at the groups on Facebook.
Hello. Can you help me with ESPHome? How to work with SD? I wish to play a mp3 or wav file. I have media player and DAC and I can play music using Home Assistant but not from SD. I was looking for a solution for the past week 😢. I have esp32 and a SD board connected
I would have to google, too to find an answer :-(
I use ESPHome in some of my sensors at home...but on one occasion a ESPHome update screwed up my Hot Water sensor???...I re-flashed with a clean install of ESPHome...configured it...still did not work??? I think that updates should be pointed out is a possible flaw in their process???? I ended up reflashing it in Arduino MQTT code....been working ever since.
I generally don't update existing devices unless I'm making changes to the device... I would suggest not updating unless you really need to. If you do, then take the time to read the breaking changes carefully to understand the impacts of revision changes...
I agree: MQTT is more standardized. And the ESPhome (fast) update policy is not always good ( mentioned that fact in my HA video).
I would create an issue in the sensor project that the maintainer can correct it. It seems to be a classical bug.
How does it compare if you take Home Assistent and ChatGPT out of the comparison?
I think similar because I use ChatGPT also to write Arduino code...
How zigbee and ZHA which are native to home assistant fit in
Most ESP32 use WiFi, not Zigbee.
that's pretty, I have to do it in CLI, using Nano... then I type: esphome run thingy.yaml. Sometimes I have to add the name to my hosts file so it can upload to the esp32 OTA. HA then grabs it.
That is what I called "offline". A good way if your HA runs on a Raspberry Pi because compiling is usually much faster on a Desktop PC.
@AndreasSpiess I tried the other ways, but went back to core install.
Internet says ESPHome uses Python to generate C++ code from YAML configuration files edited by the user. This is a very old idea, but not much used up to this point (I think).
I meant code generation from configuration files, not from YAML specifically.
AFAIK you are right!
hey andi! mini antwort im breite bärndütsch 😄 merci für dä abriib. also quasi es "deklerativs modäll" wome mit yaml files erstellt. gueti abstraktion vo esphome! mache itz ou no eine uf tüpflischisser... hesch gwüsst, yaml isch ke programiersprach 😂... uuhhh de muess me de aube grad korrigiere. aber weme z video luegt zeigsch ja genau dr ungerschiid vo programiere zu deklariere. aber houpsach me het öpis chönne "korrigiere" 🤪... mach witer mit tüftle, häb spass u aues guete🫡
Wenn wir ganz genau werden wollen gehen wir zum "Duden". Der schreibt:
Programmiersprache: System von Wörtern und Symbolen, die zur Formulierung von Programmen (4) für die elektronische Datenverarbeitung verwendet werden. Jetzt bist du dran ;-)
I prefer personnaly Annex32 RDS and his mqtt commands, it runs on a esp8666/esp32 wich is programmable in basic via a web browser.😊
I never used it, so I cannot tell the difference :-(
Hello Sir this comment is not related to the video, but I’m looking for some information, im trying to make a device wireless I’m normally send and receive data from it but I have issues with the cable is an usb device so I was thinking to add an ESP32 on the end of the device and another ESP32 to the computer, I don’t have much knowledge, being watching your videos I’m trying to learn so any answer will be appreciated
Maybe you start acquiring knowledge with a simple project and add more functionality with more knowledge? But it will take time :-(
Hassio cannot be run offline, right ? I dont trust the interweb, nor do i want to become dependent. So i need a fallback. I choose MQTT. So i prefer ESPEasy for my sensors.
Home Assistant runs completely offline (except for getting the files and updates).
If you prefer you can install Homeaasistan as python app to wheel and run it directly from there. As well as ESPHome can be installed directly (I run it from my notebook).
This style of modern programming with something like app.run() inside the main loop makes me frustrating.
I once spent more than half an hour trying to understand how nordics ble example with simle blink logic works.
It appeared that particular led.on/off() function was buried five leves deep (if count from main).
I still don't understand why on earth they need so much levels of abstraction on a such small device. 😢
Welcome to the new world. Somebody has to use the power of the new MCUs ;-)
I enjoyed the video, @AndreasSpiess do you use platform IO as an alternative for Arduino IDE?
I sometimes do, but not for videos. The Arduino IDE is more used by my viewers.
@@AndreasSpiess Thanks
0:20 So if you understand YAML to be a programming language ... then there you have your error. YAML is a configuration language. Like TOML, Windows INI files etc. It is used to configure a program generator (this is what ESPHome actually is). But it isn't really a programming language in itself.
You are right!
YAML is a markup language and therefore totally inappropriate for programming (sequences, loops, branching). So it fits well for describing the properties of a sensor but fails when it comes to automation (for example).
I think, ESPhome found a good compromise with the "common actions" and with the "lambda code"
When you talk about using Home Assistant instead of Node Red, I guess you're not referring to automations, but all the rest.
There's a lot of information coming from my esphome devices to home assistant, that I use in node red automations
I already started to transfer some of the simple automations to HA because then it is in one place. The more complex flows are still in Node-Red and I heavily use the interaction between the two.
@AndreasSpiess my reasoning is the opposite of yours: I don't transfer any automations from node red to Home Assistant, as otherwise I have my automations in two places which will confuse me when I need to start digging 😊
@@PersonXes All of my automations are in NodeRed... Automations in HA 5 years ago were terribly limited, thus NR was prefered. HA automations today are better, but I'm sticking with what I know and the flexibility NR offers still leaves HA in the dust..
I have elements in NodeRed that are not possible to get into HA natively, thus it is the better place for automation.
@dougle03 I'm in exactly the same situation as you 😉
As a longtime software engineer, let me say that it’s okay that you didn’t like YAML. I don’t know anyone that actually _likes_ it, we just learned to deal with, like Stockholm Syndrome.
:-))
Liking is a strong word. I *prefer* it though 😅
YAML is a very good and readable language. It's just too complex and the early versions had a few stupid decisions ("on" being interpreted as a bool, etc). We need a subset of it (not JSON but a readable one). Unfortunately TOML has appeared to fill this niche and it's basically all the worst traits of YAML and ini-files combined...
I wrote a component for ESPhome (though not merged). The project is awesome, but yaml code is horrible to look at and it is not beginner friendly.
Cool! I have no clue how to write a component. So I am thankful for all of you doing this work!
@@AndreasSpiess Well I don't really know either, I took a similar component and adjusted the code :D
How would you save data to a SDcard in YAML, and make it write in a circular buffer, so only saving the latest data. It only works for an ESP32 ? Isn't that rather limited? Being an old salt, I can't stand having to learn new gizmo languages just to do what I already can do. I know I should learn python, but I just can't.
I discovered uLisp (being an old Lisp guy) and it actually runs on all the micros that have enough memory. But frankly C does the job for small apps.
In fact, I hate C++ when C is just fine for a tiny micro, I just rewrote the only actually working RTSP code for arduino I could find, and what a mess of C++ it was, crudely adapted to arduino. Now its a single arduino ino file you just load and compile in the ide, no libraries, it just works now.
ESP32 can interface with SD storage, there is example code in the ESPHome docs on how to do this. I'd recommend against rapid writes to flash media as they don't last long if constantly being written to. Might be better to use MQTT and have the data off loaded to a more appropriate storage device. You can still locally store latest data for on-chip logic of course...
The idea of ESPhome is to create connected devices. This is why I do not use SD cards anymore. I transfer the readings to a more capable device for future use. So I do not know.
This is not "programming". This is just configuring a library with a configuration file.
Indentation is tabs BTW, not spaces.
Definitions from Oxford Languages: Programming: the process or activity of writing computer programs. You decide.
And YAML does not work with tabs :-(
@@AndreasSpiess That's the stu,pidest thing I heard since Go messed up K&R style curly braces. Developers, who limit everyone else just because they like one style of syntax, are bad.
Biggest problem I've yet to figure out with esphome is how to do things that require deep sleep.
I played around with deep sleep, and it worked. However, I did not take any measurements (e.g., how long it takes to wake up).
@AndreasSpiess I must revisit....
@@calvinbrowne2126 It did not make it into the video (it was already too long ;-)
ProgramIO in VS code
Did I say that? Then it was definitively wrong :-(
It's silly to compare c++ with yaml. These technologies help us achieve completely different things. You could also compare it with Microsoft word...
Where are the "completely different things". Both create a device that does what I want (if I am happy). Just two different roads or vehicles, perfect for a comparison in my view.
* indentation.