Tag: ESPHome

  • Everything Open 2024, Gladstone

    The Everything Open Conference, in 2024, was held in Gladstone Queensland, and I was able to go and make a presentation on ESPHome:

    Free your mind and your devices will follow, using ESPHome.

    It was a most enjoyable time exploring topics covering Free and Open Source Software (FOSS) topics, including some of the social and inclusivity issues.

    The videos of the conference will be made available at some stage.

    The Everything Open 2025 Conference will be held in Adelaide, so watch out for the announcements (and subscribe to the Linux Australia mailing list).

  • Installing ESPHome – A Quick Start Guide

    These instructions are summarised from the online instructions. See: https://esphome.io/guides/installing_esphome.html

    Quickstart

    Installation

    The following installs ESPhome on a Windows computer so that it can be run from the ‘cmd’ window (text input).

    Install Python (and Pip)
    See instructions here: https://www.python.org/downloads/

    Ensure that option “Add Python to PATH” is selected before installing the package.

    Check that Python is installed

    In a Windows ‘cmd’ window (command prompt).

    python --version
    => Should return something like: Python 3.10.1

    Install dependencies

    pip3 install wheel

    Install ESPHome

    pip install esphome

    Check installation

    esphome version
    => Should return something like: Version: 2023.12.0

    ESPHome is now installed, and can be run from the Windows CMD

    Using ESPHome

    Create/Edit YAML files

    ESPHome is driven via YAML configuration files in the working directory. YAML (Yet Another Markup Language) files are text files which are formatted in a specific way. They can be edited with any tool which can edit text files. (MS Notepad is good, MS Word may cause problems. MS Visual Studio (Code) is a good place to start.)

    Once installed, view available ESPhome options

    esphome -h

    A simple YAML file that works with the Heltec Wifi LoRa 32 V3, which can be extended, looks like the following. (Copy and save this file as ‘esphome-device.yaml’) To understand the parts of this fle and the YAML configuration options, see: https://esphome.io/

    esphome:
      name: "lora-sx126x"
    
    esp32:
      board: esp32-s3-devkitc-1
      framework:
        type: arduino
    
    logger:
    
    wifi:
      networks:
      - ssid: WIFI_SSID_GOES_HERE
        password: WIFI_PASSWORD_GOES_HERE
     
    ota:
      password: OTA_PASSWORD_GOES_HERE
    
    # Enable Home Assistant API
    api:
      encryption:
        key: API_KEY_GOES_HERE
    
    web_server:
      port: 80

    With an ESP32 board, new firmware can be built and installed using a YAML configuration file with:

    esphome run esphome-device.yaml

    These commands can be run individually as the following.

    esphome compile configuration-file.yaml
    esphome upload configuration-file.yaml
    esphome logs configuration-file.yaml

    When the program is running, it can be interupted by pressing the key combination: Ctrl-C

    Over the Air (OTA) Updates

    If enabled in the YAML file, ESPHome also supports “Over the Air” updates. This means that if the ESP board is currently connected to a Wifi network then using this connection, it can be directly upgraded with new firmware.

    This option can be selected during the ‘upload’ step. If the board is not connected with USB and only connected to Wifi, this will happen automatically.

    Additional notes – For Linux Users

    Using a Virtual Environment – venv

    The above process is very similar when installing on Linux or MacOS. On Linux, it is possible to setup a ‘virtual environment’ (venv) for development by installing and using the ‘venv’ command. This will allow the local Python libraries to be installed and run separately to the system libraries. This is useful to allow the development environment to use more recent library versions and/or allow the development environment to use more stable version. This helps when debugging and tracking down issues that may be caused by libraries.

    Ensire that you are working in the required local project directory (eg. with the ‘cd’ command)

    With Python and Pip installed as installed, create the venv development environment in the current working directory.

    pip3 install venv
    python -m venv venv
    . venv/bin/activate

    Install and run ESPHome as before.

    To restart editing session in an existing venv enabled directory

    Setup the venv environment again by using:

    . venv/bin/activate

    At this stage, it is also possible to install ESPHome directly from the GitHub
    development repository. This is useful for debugging, bug fixing and testing.

    Install development version from the Github ESPHome repository

    This requires that the ‘git’ lool has been installed. (Use ‘apt git install’ on Ubuntu.)

    git clone https://github.com/esphome/esphome.git
    cd esphome
    python -m venv venv
    . venv/bin/activate
    ./scripts/setup

    As required, update the local copy of the code with the following.

    git pull
    ./scripts/setup

  • Developing a component for ESPHome, for the SX1262 LoRa Radio Chip – Part 1

    Developing a component for ESPHome, for the SX1262 LoRa Radio Chip – Part 1

    Introduction

    This post describes “Work in Progress”. I have deliberately decided to put these details together now as it has been possible to build something that ‘sort of’ works, in that all the pieces are there, ot nearly there. The end is in sight, albeit a reasonably long way away in time and effort.

    The original aim was to make the SX1282 LoRa radio chip available, for both LoRa and LoRaWAN modes, directly in ESPHome. It is hoped that the use of the SX126X series of radio chips can be as easy as possible to use and in most cases wholly driven from the ESPHome YAML files. When creating an IoT device with a new dev board, this has been one of the frustrating pieces of the excercise, particularly when using the Arduino IDE and programmer.

    The Github repository of the component is here: https://github.com/PaulSchulz/esphome-lora-sx126x

    These notes assume that you have ESPHome installed (

    To include this external component in your own ESPHome yaml file, see below, or read the repository’s documentation (which will be newer than this).

    Hardware

    This ESPHome component is being developed on the Heltec V3 Development Boards which use the LoRa SX1262 chip. These dev boards are:

    At the present time, these boards are not available for selecting directly in the
    ESPHome YAML file (when using the Arduino framework). In order to make these
    boards work with the available version of ESPHome, the following YAML is required:

    esp32:
      board: esp32-s3-devkitc-1
      framework:
        type: arduino

    These board definitions are imported from the platform-espessif32 project here.

    The LoRa Arduino Library

    The Arduino library being used is beegee-tokyo/SX126X-Arduino, which itself is based on several other libraries. It appear to currently be the best and most maintained LoRa library available for these radio chips.

    The following header file contains the descriptions of the functions and fields used by the library: https://github.com/beegee-tokyo/SX126x-Arduino/blob/master/src/radio/radio.h

    Testing and Usage

    The files lora-sx126x.yaml and secret.yaml provide an example of how to use the
    component. To use with a working version of ESPHome, edit secret.yaml to add
    your local Wifi details, then run:

    esphome run lora-sx126x.yaml

    Development Comments

    To get the component into a working state, this ESPHome component currently does some things which are not encouraged by the ESPHome Core and Component developers (see below).

    It is always hoped that this component will become compliant enough to be
    included in ESPHome, but in the meantime, it can be included in your ESPHome
    build by either cloning this repository locally and adding an external_component
    with a local source; or by including the github repository directly as an
    external_component. See the External Components documentation for more details

    If downloading and using as a local source for external component:

    external_components:
    - source:
        type: local
        path: esphome/components
      components: ["lora_sx126x"]

    and, using directly from the Github source for an external component

    external_components:
    - source:
        type: git
        url: https://github.com/PaulSchulz/esphome-lora-sc126x
        ref: main
      components: ["lora_sx126x"]

    Considerations / Things to fix

    Direct use of SPI and SX126x-Arduino libraries

    If possible, the SX126x-Arduino library needs to be implemented natively in
    ESPHome, to make use of the native ESPHome SPI code.

    By using the Library directly, it is uncertain at the moment whether this component can be used generally with other devices that use the same SPI interface.

    Example YAML

    The following is the proposed example YAML configuration, for a ESPHome image that will enable the SX126X radio.

    esphome:
      name: "lora-sx126x"
      libraries:
        - "SPI"
        - "Ticker"
        - "SX126x-Arduino"
    
    ...
    
    external_components:
      - source:
          type: local
          path: esphome/components
    
    ...
    
    lora_sx126x:
      # The frequency to use needs to be specified as will depend on the
      # hardware and the region in which the it is being used.
      frequency: 915000000

    Development

    Proposed YAML Options

    The following is an example of the proposed full option list, for using the LoRa radio chip.

    lora_sx126x:
      # optional, with sensile defaults, if possible from board id.
      pin_lora_reset: 12
      pin_lora_dio_1: 14
      pin_lora_busy: 13
      pin_lora_nss: 8
      pin_lora_sclk: 9
      pin_lora_miso: 11
      pin_lora_mosi: 10
      radio_txen: -1
      radio_rxen: -1
      use_dio2_ant_switch: true
      use_dio3_tcx0: true
      use_dxo3_ant_switch: false
    
      # required - depends on region and frequency band being used
      rf_frequency:           915000000
      # optional (sensible defaults)
      tx_output_power:               22
      lora_bandwidth:                 0
      lora_spreading_factor:          7
      lora_codingrate:                1
      lora_preamble_length:           8
      lora_symbol_timeout:            0
      lora_fix_length_layload_on: false
      lora_iq_inversion_on:       false
      rx_timeout_value:            3000
      tx_timeout_value:            3000

    It should then be possible to use the radio with the various builtin types. This has yet to be implemented.

    text_sensor:
      - platform: lora_sx126x
        id: lora_message
        name: LoRa Message
    
    # Is there a component for this in ESPHome?
    # Sending a string to a component?
    text_message:
      - platform: lora_sx126x
        id: send_message
        name: "Send LoRa Message"
    
    binary_sensor:
      - platform: lora_sx126x
        id: lora_sensor
        name: LoRa Sensor
        on_string: "@+++"
        off_string: "@---"
    
    switch:
      - platform: lora_sx126x
        id: lora_switch
        name: LoRa Switch
        on_string: "@^^^"
        off_string: "@vvv"
    
    binary_input:
     - platform: lora_sx126x
       id: lora_input
       name: LoRa Binary Input
       on_string: "@***"
       off_string: "@..."
      
    binary_output:
     - platform: lora_sx126x
       id: lora_output
       name: LoRa Binary Ouput
       on_string: "@>>>"
       off_string: "@<<<"