News for hackers. Stuff that matters.
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by e28eta on Thursday May 26, 2022 @02:45PM (#31522001)
In addition to enjoying esphome for the ease of use and solid integration with Home Assistant, I find the technical underpinnings interesting.

- Users produce yaml describing a microcontroller connected to (sensors, inputs, outputs, networks, services, etc).

- A python layer type checks that yaml, and spits out autogenerated C++ code (which can be inspected if desired)

- C++ is compiled and installed onto the hardware

- future updates can be made OTA

- extensible by either writing (hopefully small amounts of) C++ inside yaml (lambdas), or including/referencing C++ code (external components)

I’m still not positive I like yaml for the DSL, but that might be a personal bias and I’m not sure what an obviously better solution would be.

Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by gerdesj on Thursday May 26, 2022 @06:53PM (#31524253)
"I’m still not positive I like yaml for the DSL"

Back in the day HA was all about YAML. It's still there but mostly hidden behind the GUI but /config/configuration.yaml still does a lot of work.

ESPHome is simply amazing. I've got several ESP80266s with various lash ups all just working. For example, when my work computer room generator fires up a GPIO on a ESP8266 gets twitched from the power distribution board, another pin gives me mains power state from the perspective of the board. A few dozen lines of YAML - mostly copy n paste and I have a really decent sensor for less than £10 parts.

We test the system every few weeks by turning a key. The UPSs beep for a few seconds, and the genny fires up. After a while you turn the key back, the UPSs beep again and then the mains takes the load back. Meanwhile your phone goes off several times with notifications (SMS, Teams etc)

I particularly enjoy watching customer's expressions when I'm showing them around and I do a test there and then.

I'm just doing a link to our rather ancient building alarm to get notifications. This will be a ESP01-S thing to get it really small. I was quoted many £1000s for a "modern system" with an app etc. The existing sensors are fine and the alarm itself works fine. It now has a length of CAT5e connected to some of its terminals for an external sounder. It delivers 12V, earth and a 12V signal. I just have to turn the 12V into 3.3V via some Zeners and stabilize it with a capacitor to power the ESP and the signal down to 3.3V via some resistors. I think!

Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by kelvie on Thursday May 26, 2022 @05:01PM (#31523315)
Fairly heavy user of ESPhome here (I have about 15 or so devices automating several parts of my home).

What would be a better option than YAML? The main advantages are ease of in-lining C++, and it's ubiquitous.

Having to use k8s at work also makes it not much of a context switch to use for me, and the secrets management is great using the `!include`s.

But yeah the killer feature here is the inlining of C++, and the use of platformio. You really can do anything without much work (maybe at most one or two external C++ header files for really custom stuff) inside ESPhome, and it's easy to see where your snippets go when you inspect the generated C++ code.

ESPHome just automates all the super tedious parts of working with esp32s (stuff like connecting to wifi, MQTT, OTA upgrades, logging to mqtt, etc), without sacrificing any power.

My only complaint is that because it uses arduino (I think?) you can't really do powersaving really well, but I don't think many people use battery powered esp32, but this basically eliminates that possibility, at least in my research.

Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by thedanbob on Thursday May 26, 2022 @05:39PM (#31523669)
> ESPHome just automates all the super tedious parts of working with esp32s (stuff like connecting to wifi, MQTT, OTA upgrades, logging to mqtt, etc), without sacrificing any power.

I write my own firmware for all of my ESP devices and I can confirm, those definitely are the bulk of the work. The latest one (for a relay to power cycle my modem if the internet goes down) took less than an hour to write since I was able to copy-paste all of that boilerplate from a previous project.

Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by cptskippy on Thursday May 26, 2022 @06:03PM (#31523872)
> I write my own firmware for all of my ESP devices and I can confirm, those definitely are the bulk of the work.

I was doing that too for all of my projects. I was developing them as if they were products I could potentially sell. When I accepted that I wasn't ever going to do that, I gave ESPHome a try.

> took less than an hour to write since I was able to copy-paste all of that boilerplate from a previous project.

It would probably take 5 minutes to configure from scratch ESPHome, less time if you're copying from an existing config. In addition to that, you get automatic logging into Home Assistant and deep integration for free.

Using Hypfer's discovery[1] that you could read the raw values from Ikea's Vindriktning using an ESP, I wrote an ESPHome script for an ESP01 that pipes the data into Home Assistant. Now when I'm cooking and the air quality gets too bad my HVAC fan kicks on to clear the air. It took longer to solder everything up than it did to "code".

YAML:

    esphome:
      name: air-quality-sensor-1

    esp8266:
      board: esp01_1m

    # Enable logging
    logger:
    # Disable logging
      baud_rate: 0

    # Enable Home Assistant API
    api:

    ota:
      password: !secret aqs_ota_password

    wifi:
      ssid: !secret wifi_ssid
      password: !secret wifi_password

      # Enable fallback hotspot (captive portal) in case wifi connection fails
      ap:
        ssid: "Air-Quality-Sensor-1"
        password: !secret aqs_hotspot_password

    captive_portal:

    # Setup Ikea Vindriktning PM2.5 sensor
    uart:
      rx_pin: GPIO3
      baud_rate: 9600

    sensor:
      - platform: pm1006
        pm_2_5:
          name: "Ikea Vindriktning PM25"
          filters:
            - sliding_window_moving_average:
                window_size: 10
                send_every: 10







[1] https://github.com/Hypfer/esp8266-vindriktning-particle-sens...
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by thedanbob on Thursday May 26, 2022 @06:39PM (#31524147)
That’s pretty cool! If I had know about ESPHome when I first got into home automation I’d probably have gone with it. Although I’m kind of glad I didn’t because I actually really enjoy programming in C++.
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by kelvie on Thursday May 26, 2022 @07:14PM (#31524436)
FYI this could have been done really easily in esphome:

  switch:
    - platform: gpio
      pin: 25
      name: "Modem relay"
      restore_state: ALWAYS_ON
      id: modem_relay

  interval:
    - interval: 1min
      if:
        condition:
          not:
            wifi.connected
      then:
        - switch.turn_off: modem_relay
        - delay: 1s
        - switch.turn_on: modem_relay
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by thedanbob on Friday May 27, 2022 @06:52AM (#31528068)
Mostly I write my own firmware to improve my C++ skills :)
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by Beta-7 on Thursday May 26, 2022 @05:04PM (#31523354)
>What would be a better option than YAML?

It isn't a 1:1 alternative, but I've always thought that ESPhome would be much more accessible for the non-devs if they introduced a GUI similar to Home Assistant's automation GUI.

Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by windexh8er on Thursday May 26, 2022 @08:37PM (#31524920)
There's always Tasmota [0]. Personally I prefer ESPHome but recently tossed Tasmota on some OTS Sonoff plug switches. Best part is you can just drop ESPHome firmware in the Tasmota OTA upgrade and switch at any point.

[0] https://tasmota.github.io/docs/

Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by cptskippy on Thursday May 26, 2022 @05:48PM (#31523738)
> I’m still not positive I like yaml for the DSL, but that might be a personal bias and I’m not sure what an obviously better solution would be.

The yaml files in ESPHome aren't any different than yaml for Git Pipelines, Docker, or K8.

The don't contain much if any logic.

Here's my garage door based on a Malouf ESP Dev board (https://maloufelectronics.com/):

    esphome:
      name: garagedoor

    esp8266:
      board: esp01_1m

    # Enable logging
    logger:

    # Enable Home Assistant API
    api:

    ota:
      password: !secret garagedoor_ota_password

    wifi:
      ssid: !secret wifi_ssid
      password: !secret wifi_password

      # Enable fallback hotspot (captive portal) in case wifi connection fails
      ap:
        ssid: "Garage Fallback Hotspot"
        password: !secret garagedoor_hotspot_password

    # Enable Captive Portal
    captive_portal:

    # Define Hall Effect Sensor
    binary_sensor:
      platform: gpio
      pin: 
        number: GPIO16
        inverted: true
      name: "Garage Door Sensor"
      device_class: garage_door

    # Define Relay
    switch:
      - platform: gpio
        name: "Garage Door Relay"
        id: garage_door_relay
        pin: GPIO14
        restore_mode: ALWAYS_OFF
        on_turn_on:
        - delay: 1000ms
        - switch.turn_off: garage_door_relay
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by rexfuzzle on Thursday May 26, 2022 @05:15PM (#31523455)
I find the yaml works fine for the basics, but the real power comes with being able to include your own c code and use that along with whatever is in the yaml. Basically means you can have normal arduino code that is the tied into hass very easily.
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by pathartl on Thursday May 26, 2022 @02:47PM (#31522016)
I agree with the last point, so I usually end up delegating any sort of logic handling to my automations. ESPHome will just report the state of sensors, my code figures out what to do with them.
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by darknavi on Thursday May 26, 2022 @04:30PM (#31523017)
I _really_ like that you can do light automations easily with ESPHome as well. For my cat feeder, it has some cron-like scheduling to go off ever so often and I do not want my cats to starve if my Home Assistant VM is down.
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by michaelmior on Thursday May 26, 2022 @04:05PM (#31522768)
That's understandable although of course doing things in YAML in ESPHome has the advantage that it will continue to work if HA is unavailable for some reason.
Re:ESPHome – Connect ESP32 with Sensors to HomeAssistant by godsfshrmn on Thursday May 26, 2022 @05:02PM (#31523323)
I prefer the same but still for important uses I'll write native code to serve as a back up - e.g sprinkler auto shut off after x minutes