My ESPHOME Journey – Scargill’s Tech Weblog


I not too long ago wrote about experimenting with the LILYGO TTGO ESP32 improvement board and my first makes an attempt at utilizing ESPHOME as towards my firmware of alternative Tasmota. Properly, I’ve been heads-down for a number of days of studying – with a number of false begins I’ll add. The brief model of that is, I’ve now made some important progress in utilizing ESPHOME on each ESP8266 and ESP32 (together with discovering the command to double the ESP8266 working frequency from 80Mhz to 160Mhz – one thing usually missed within the battle between the 2 chips). The purpose of penning this weblog is to assist save others a few of my dead-ends and to function a reminder/immediate for me sooner or later. See February 2023 replace under, for utilizing ESPHOME with non-ESP boards.

Skip Background if you would like the “shorter” (it’s not brief) model – and head straight to The Meat however you might miss some helpful context.

Background

Seasoned ESPHOME customers might dismiss this, however this has been a problem for me regardless of a historical past together with a long time of C programming and extra not too long ago delving into Javascript (NodeJS) because of Node-Crimson. Principally I began utilizing machine code within the Nineteen Seventies, transferring on rapidly by meeting language to BASIC, writing my very own FORTH interpreter in a robust BASIC model (Cromemco 23K Structured BASIC) someday in 1980 or thereabouts. Round then I used to be satisfied by an older good friend that I used to be “barking up the unsuitable tree” and so got here my introduction to C.

Once I put collectively ESP-GO to program up ESP8266 chips for dwelling management, I prevented C++ just like the plague and caught with plain previous C (and the ESPRESSIF SDK) – not certainly one of my higher plans although I did handle to change some Adafruit and different libraries so as to add LCD/OLED show, ws2812b RGB LEDs and varied sensor controls to the ESP8266. Combine in some easy Node-Crimson NodeJS coding on Raspberry Pi (RPi2 initially) and I used to be beginning to see outcomes and a following on the weblog. The route I took mixed with the ESP8266 meant I used to be consistently up towards RAM limits to that route was by no means going to final – it nonetheless works and I’ve a pair of ESP8266+ILI941 wall thermostats again within the UK which stand as a testomony to ESP-GO – full with native buttons and naturally WiFi/MQTT management. All blogged in right here.

After which got here Tasmota which enjoys loads of assist to at the present time and by 2021 its show dealing with exceeds that of ESP-GO – but for me nonetheless leaves one thing to be desired in that space. Within the strategy of utilizing the Raspberry Pi as my dwelling management centre – together with Node-Crimson, I’ve been launched to JSON although I might not say I used to be an professional on the topic or something prefer it.

So, final week I went off on a tangent, grabbed each ESP8266 and ESP32 boards and went off to the net to see what ESPHOME is all about. The ESPHOME software program system makes use of YAML (a “digestible knowledge serialization language” that’s usually utilized to create configuration recordsdata, works in concurrence with any programming language and is seemingly a superset of JSON – additionally it is totally alien to me). ESPHOME is often related to “Residence Assistant” and I’m not a fan of the latter, which makes studying about ESPHOME that rather more tough as HA seems regularly all through ESPHOME documentation. My because of @ssieb, @WeekendWarrier and others within the ESPHOME Discord discussion board for his or her assist.

The Meat

So, to the meat – with unprecidented assist from a few people within the ESPHOME discussion board, I began from zero final week and labored my approach as much as a usefully working ESP32 (TTGO) board together with built-in IPS ST7789V 1.14 Inch LCD show, some ws2812b RGB lighting, a easy LED, a ~BME280 multi-purpose sensor and use of the on-board TTGO buttons (proven on the show utilizing easy crammed, colour-changing circles) – all utilizing ESPHOME software program. That reversed out textual content is black on yellow achieved with easy black textual content on high of a yellow crammed rectangle.

TTGO board with ESPHOME - a work in progress

Above you see the {hardware} and under, the ESPHOME software program in it’s present type. On the high of the panel, the interior chip temperature and WiFi connection state, then the output from the BME280 board (backside left – I2C and 3v3), time, date and WiFi standing. It will grow to be one thing truly helpful however I’m nonetheless studying – and it IS PRETTY. Disgrace the ws2812b LEDs don’t actually present the constantly-cycling, individual-colour-per-LED rainbow impact within the picture. Belief me.

The code under (My First ESP32 ESPHOME Challenge) to go together with the picture above, seems concerned however I ought to level out right here that it’s constructed up largely from modified examples (I’ve left seemingly pointless feedback in as reminders for my very own future) pieced collectively and modified as I study. My WiFi password is hidden to guard the harmless.

So, ESPHOME software program seems to be constructed up in blocks (beginning factors for just about all of this may be seen unfold across the ESPHOME web site) – after putting in the ESPHOME package deal on my PC – trivial – it’s all carried out for you and a plug-in referred to as PILLOW for Python (once more all automated setup), I began the ball rolling. ESPHOME works (in Home windows) on the command line and utilizing NotePad++ to edit the code the 2 of which that just about put me off proper in the beginning, till one of many individuals giving me recommendation stated “No, what you want is that this…. the brand new, free Home windows Terminal – which pulls in Powershell and is EASY and nice to make use of, additionally the free Microsoft Visible Code for enhancing.”

With that start line I made a begin on ESPHOME.

Setup

I took a useful NODEMCU-type ESP8266 board and plugged it right into a spare USB port on the PC utilizing an ordinary USB lead.

On the immediate in Home windows terminal – not paying any consideration to folders although the truth is I used to be sitting within the new”C:UsersUseresphome” folder, I merely began by typing:

esphome wizard myesp8266.yaml

— which is the way you begin off a model new ESPHOME mission. Keep in mind that NodeMCU-type boards don’t want you to mess about with reset and programming (GPIO0) buttons – others might. In brief – a brand new mission we’ll name “fred” begins with an automatically-created fred.yaml file within the robotically created esphome folder… and finally ends up with a “fred” folder beneath – together with folders for no matter initiatives you create.

That is the way it all begins in my case:

Hello there!
I am the wizard of ESPHome :)
And I am right here that can assist you get began with ESPHome.
In 4 steps I'll information you thru making a primary configuration file on your customized ESP8266/ESP32 firmware. Yay!



============= STEP 1 =============
    _____ ____  _____  ______
   / ____/ __ |  __ |  ____|
  | |   | |  | | |__) | |__
  | |   | |  | |  _  /|  __|
  | |___| |__| | |  | |____
   _________/|_|  _______|

===================================
First up, please select a reputation on your node.
It must be a singular title that can be utilized to establish the system later.
For instance, I like calling the node in my lounge livingroom.

(title):myesp8266

At this level I gave the mission a reputation “myesp8266” – hardly imaginative however there you go. I used to be then requested if I used to be utilizing an ESP32 or ESP8266 – I responded with the latter. I used to be then requested what TYPE of ESP8266 board – I responded with nodemcuv2 (a guess).

The recommendation on the finish, above, is invaluable – as https://esphome.io is FULL of helpful reference materials and examples. At this level the PC got here again to the immediate. No chip flashing had been carried out – so I left the board plugged into USB and the PC and took a take a look at the brand new YAML file in VSC (Visible Studio Code editor). Don’t ask me why it was referred to as “myesphome” once I’d used “myesp8266” – however I simply checked the file title – positive sufficient.

Out-of-the-box YAML code

Anyway, right here (minus my password which I’ve left right here as xxxxxxx) is the content material of that file…

esphome:
  title: myesp8266
  platform: ESP8266
  board: nodemcuv2

# Allow logging
logger:

# Allow Residence Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: "xxxxxxx"
  password: "yyyyyyy"

  # Allow fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Myesp8266 Fallback Hotspot"
    password: "Olv9HILOgwrE"

captive_portal:

I’d already found out at this level that I might not be needing the Residence assistant API and could be needing MQTT however that may comply with:

After that preliminary setup, a barely modified command-line instruction (wizard changed by run) created the very first FLASHED ESP8266:

esphome run myesp8266.yaml
C:UsersUseresphome> esphome run myesphome.yaml
INFO Studying configuration myesphome.yaml...
INFO Producing C++ supply...
INFO Compiling app...
INFO Working:  platformio run -d myesp8266
Processing myesp8266 (board: nodemcuv2; framework: arduino; platform: platformio/[email protected])
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode will be enabled by way of `-v, --verbose` choice
CONFIGURATION: https://docs.platformio.org/web page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 (2.6.2) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
 - framework-arduinoespressif8266 3.20704.0 (2.7.4)
 - tool-esptool 1.413.0 (4.13)
 - tool-esptoolpy 1.20800.0 (2.8.0)
 - toolchain-xtensa 2.40802.200502 (4.8.2)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ tender
Library Supervisor: Putting in Replace
Library Supervisor: Already put in, built-in library
Discovered 32 suitable libraries
Scanning dependencies...
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.3.0
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ArduinoJson-esphomelib> 5.13.3
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
Constructing in launch mode
Retrieving most program dimension .pioenvsmyesp8266firmware.elf
Checking dimension .pioenvsmyesp8266firmware.elf
Superior Reminiscence Utilization is obtainable by way of "PlatformIO Residence > Challenge Examine"
RAM:   [====      ]  39.6% (used 32424 bytes from 81920 bytes)
Flash: [====      ]  37.8% (used 394400 bytes from 1044464 bytes)
================================================================================= [SUCCESS] Took 3.98 seconds =================================================================================INFO Efficiently compiled program.
Discovered a number of choices, please select one:
  [1] COM11 (USB-SERIAL CH340 (COM11))
  [2] Over The Air (myesp8266.native)
(quantity): 1

You received’t just like the completely automated output that follows (above) as it is vitally lengthy and took a minute or two on my PC to run – however did you discover above – I solely typed in “1” – and that’s the final time for that mission that the board must be plugged into the PC until you need o see serial logging – from there on any previous USB hub or USB provide will do (not related to the PC) and there’s no menu. I typed in “1” and a torrent of data poured out to inform me that the board was being “Flashed” after which to inform me that it was related to the WiFi – for the sake of it, right here’s a few of that output.

[I][app:106]: ESPHome model 2021.8.2 compiled on Sep 26 2021, 12:15:48
[12:27:57][C][wifi:499]: WiFi:
[12:27:57][C][wifi:359]:   SSID: 'xxxxxxx'
[12:27:57][C][wifi:360]:   IP Deal with: 192.168.1.238
[12:27:57][C][wifi:362]:   BSSID: 94:83:C4:01:84:6E
[12:27:57][C][wifi:363]:   Hostname: 'myesp8266'
[12:27:57][C][wifi:367]:   Sign power: -59 dB ▂▄▆█
[12:27:57][C][wifi:371]:   Channel: 1
[12:27:57][C][wifi:372]:   Subnet: 255.255.255.0
[12:27:57][C][wifi:373]:   Gateway: 192.168.1.1
[12:27:57][C][wifi:374]:   DNS1: 192.168.1.1
[12:27:57][C][wifi:375]:   DNS2: (IP unset)
[12:27:57][C][logger:189]: Logger:
[12:27:57][C][logger:190]:   Stage: DEBUG
[12:27:57][C][logger:191]:   Log Baud Price: 115200
[12:27:57][C][logger:192]:   {Hardware} UART: UART0
[12:27:57][C][captive_portal:148]: Captive Portal:
[12:27:57][C][web_server:152]: Internet Server:
[12:27:57][C][web_server:153]:   Deal with: myesp8266.native:90
[12:27:57][C][ota:029]: Over-The-Air Updates:
[12:27:57][C][ota:030]:   Deal with: myesp8266.native:8266
[12:27:57][C][api:095]: API Server:
[12:27:57][C][api:096]:   Deal with: myesp8266.native:6053

As soon as carried out, I eliminated the USB lead from the PC and caught the lead right into a USB hub. The board powered up (not solely true for my FIRST time as I received issues unsuitable and forgot so as to add a WEB SERVER block so the board may very well be visibly seen to be working with out serial – so let’s cheat slightly). With the board now plugged into non-PC USB for energy solely – I added THIS (under) to the very finish of YAML file… formatting is vital so “internet server:” must be on the left and that tab earlier than “port: 80” is vital as is the house earlier than the 80 – port 80 is often a sensible choice – I might have used one other different port(90 for instance) however 80 is the default alternative for internet pages and saves keying in a port quantity within the browser

I saved the file and used the RUN command as above.

At this level, here’s a screenshot of myesp8266 in my browser (you would possibly see :90 appended within the graphic – certainly ignore that high URL within the picture under solely – I received it unsuitable at first – your system may have myesp8266.native or myesp8266.broadband or related. is dependent upon the router or any customising that’s been carried out to it – in my case the road under is what I ended up keying into my browser…

 http://myesp8266.lan

The router could have picked the IP deal with – you would FIX the IP deal with in fact. The online web page doesn’t truly DO something at this level – however in my first initiatives the net server proved very helpful, significantly for on-screen buttons whereas determining the way to wire up and use REAL inputs.

AS time goes on I’ll flesh this out and present different take a look at initiatives as they mature.

The remainder – as you will notice under is essentially a case of including blocks and modifying them to swimsuit. Beneath is my first functioning TTGO mission – there isn’t a different code than what you see under. In addition to SPI for the show, I additionally wanted I2c – that’s SO straightforward so as to add – simply specify GPIO pins. That complex-looking BME sensor was simply copied immediately from an instance on the ESPHOME web site… What makes it DO one thing? It reviews all by itself at common intervals.

As soon as I discovered that the time period LAMBDA (see under code Lambda |- and the C (ish) code that follows it to drive the show and which refers to objects within the YAML largely by ID… I merely used three strains of display house to show temperature, humidity and strain on the built-in show. If you happen to learn the code under you’ll see I seek advice from fonts and CSS colors – there’s a fonts folder below ESPHOME and I merely downloaded a couple of normal TTF fonts into the fonts folder on my PC, the compiler utilizing solely what I wanted – however this appears WAY extra versatile than Tasmota font dealing with. Colors – I’ve a colour folder with some easy definitions for helpful colors… a file therein referred to as COLOR_CSS_AQUAMARINE incorporates slightly textual content solely…

colour:
  # title and values from https://www.w3.org/wiki/CSS/Properties/colour/key phrases

  # #7fffd4
  # 127,255,212
  - id: COLOR_CSS_AQUAMARINE
    pink:   0.4980
    inexperienced: 1.0000
    blue:  0.8314
    white: 0.0000

and so right here I went (not with no battle) from by no means having taken any discover of YAML to having a working file together with embedded C directions for an ESP32+ILI9341-based board in a matter of days.. I’ll come throughout many extra bottlenecks however one thing tells me it will likely be well worth the effort. With MQTT I can combine these items with Node-Crimson simply as I all the time have however a lot show dealing with is finished entiely within the ESP32 itself – and may very well be in an ESP8266 although my expertise so far means that the pliability of ESPHOME signifies that ILI9341 and related bigger shows might not achieve this properly on the latter (show buffer sizes and RAM)- as you’ll see later nevertheless, little OLED shows – no drawback. I need to stress that I HAVE had the ILI9341 working on ESP8266 utilizing Tasmota.

On the decrease a part of the code block under – that straightforward time period LAMBDA alows me to proceed and obtain show actions in C with which I AM acquainted. Once more I stress what you see is what you get – ESPHOME + the file under is all there’s to it – any libraries should not the priority of the person as ESPHOME handles all of that robotically together with show and sensor initialisation.

My First ESP32 ESPHOME Challenge – the TTGO Board

esphome:
  title: ttgo
  platform: ESP32
  board: ttgo-t7-v13-mini32
  on_boot:
    precedence: 250
    then:
      - mild.turn_on: 
          id: LLED
          impact: rainbow    
 #     - mild.turn_on:
 #         id: LLED
 #         brightness: 50%
 #         pink: 0%
 #         inexperienced: 30%
 #         blue: 100%    

packages:
  colours: !embody colour/COLOR_CSS

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: True

sensor:
  - platform: bme280
    temperature:
      title: "BME280 Temperature"
      id: bme280_temperature
    strain:
      title: "BME280 Stress"
      id: bme280_pressure
    humidity:
      title: "BME280 Relative Humidity"
      id: bme280_humidity
    deal with: 0x77
    update_interval: 15s
  - platform: template
    title: "Altitude"
    lambda: |-
      const float STANDARD_SEA_LEVEL_PRESSURE = 1013.25; //in hPa, see word
      return ((id(bme280_temperature).state + 273.15) / 0.0065) *
        (powf((STANDARD_SEA_LEVEL_PRESSURE / id(bme280_pressure).state), 0.190234) - 1); // in meter
    update_interval: 15s
    icon: 'mdi:sign'
    unit_of_measurement: 'm'
  - platform: template
    title: "Absolute Humidity"
    lambda: |-
      const float mw = 18.01534;    // molar mass of water g/mol
      const float r = 8.31447215;   // Common fuel fixed J/mol/Okay
      return (6.112 * powf(2.718281828, (17.67 * id(bme280_temperature).state) /
        (id(bme280_temperature).state + 243.5)) * id(bme280_humidity).state * mw) /
        ((273.15 + id(bme280_temperature).state) * r); // in grams/m^3
    accuracy_decimals: 2
    update_interval: 15s
    icon: 'mdi:water'
    unit_of_measurement: 'g/m³'
  - platform: template
    title: "Dew Level"
    lambda: |-
      return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/
      (243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-
      ((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state))));
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'

# Allow logging
logger:

# Allow Residence Assistant API
#api:
# password: ""

ota:
  password: ""

wifi:
  ssid: "wififorus"
  password: "xxxxxxxxx"

  # Allow fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ttgo Fallback Hotspot"
    password: "xni6I5D4VC4m"

captive_portal:

mild:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: GPIO32
    num_leds: 20
    rgb_order: GRB
    title: "LLED"
    id: LLED
    results:
      - addressable_random_twinkle:
          title: "twinkle"
      - addressable_fireworks:
          title: "fireworks"
      - addressable_color_wipe:
          title: "wipe"
      - addressable_rainbow:
          title: rainbow

font:
  - file: "fonts/digital7.ttf"
    id: ubuntuBig
    dimension: 60
  - file: "fonts/ubuntu-r.ttf"
    id: ubuntuMedium
    dimension: 28
  - file: "fonts/ubuntu-r.ttf"
    id: ubuntuSmall
    dimension: 14
    glyphs: '♡ÆØÅæøå!"%()+,-_.:*=°?~#0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'

binary_sensor:
  - platform: standing
    title: "Node Standing"
    id: system_status
  - platform: gpio
    pin:
      quantity: GPIO0
      inverted: true
      mode: INPUT_PULLUP
    title: "T-Show Button Enter 0"
    id: tdisplay_button_input_0
    on_press:
      then:
        - mild.turn_on: 
            id: LLED
            impact: rainbow
    on_state:
    - part.replace: mydisplay

  - platform: gpio
    pin:
      quantity: GPIO35
      inverted: true
    title: "T-Show Button Enter 1"
    id: tdisplay_button_input_1
    on_press:
      then:
        - mild.turn_off: LLED
    on_state:
    - part.replace: mydisplay

# Backlight management
change:
  - platform: gpio
    pin: GPIO4
    title: "Backlight"
    id: backlight
  - platform: gpio
    pin: 17
    title: "WiFi LED"
    id: wifiLED

#picture:
 # - file: "picture.png"
 #   id: my_image
 #   resize: 200x200
 #   kind: RGB24

#time:
#  - platform: homeassistant
#    id: esptime

time:
  - platform: sntp
    id: esptime

text_sensor:
  - platform: template
    inside: true
    title: "mydis"
    id: mydis

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO19

mqtt:
  dealer: 192.168.1.19
  username: admin
  password: T9quila123
  id: mqtt_client
  on_message:
    - subject: ttgo
      then:
         - text_sensor.template.publish:
            id: mydis
            state: !lambda return x;

interval:
  - interval: 1s
    then:
      if:
        situation:
          wifi.related:
        then:
          - change.turn_on: wifiLED
        else:
          - change.turn_off: wifiLED

show:
  - platform: st7789v
    backlight_pin: GPIO4
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
    rotation: 270
    id: mydisplay

    update_interval: 1s
    lambda: |-
      it.rectangle(0,  0, it.get_width(), it.get_height(), id(COLOR_CSS_LIGHTSKYBLUE));
      it.rectangle(0, 20, it.get_width(), it.get_height(), id(COLOR_CSS_LIGHTSKYBLUE));   // header bar

      if (id(system_status).state) {
        it.print(235, 3, id(ubuntuSmall), id(COLOR_CSS_LIGHTGREEN), TextAlign::TOP_RIGHT, "On-line");
      }
      else {
        it.print(235, 3, id(ubuntuSmall), id(COLOR_CSS_RED), TextAlign::TOP_RIGHT, "Offline");
      }
      //it.strftime((240 / 2), (140 / 3) * 1 - 10, id(ubuntuMedium), id(COLOR_CSS_ORANGE), TextAlign::CENTER, "%A", id(esptime).now());
      //it.strftime((240 / 2), (140 / 3) * 1 + 20, id(ubuntuMedium), id(COLOR_CSS_SILVER), TextAlign::CENTER, "%d-%m-%Y", id(esptime).now());

      it.rectangle(170, 20, 70, 60, id(COLOR_CSS_LIGHTSKYBLUE));
      it.rectangle(00, 20, 171, 60, id(COLOR_CSS_LIGHTSKYBLUE));
      it.strftime((205), (140 / 3) * 1 - 10, id(ubuntuMedium), id(COLOR_CSS_ORANGE), TextAlign::CENTER, "%a", id(esptime).now());
      it.strftime((205), (140 / 3) * 1 + 16, id(ubuntuMedium), id(COLOR_CSS_SILVER), TextAlign::CENTER, "%d", id(esptime).now());

      it.filled_rectangle(1, 80, 238, 58,id(COLOR_CSS_YELLOW));
      it.strftime((240 / 2), (140 / 3) * 2 + 8, id(ubuntuBig), id(COLOR_CSS_BLACK), TextAlign::CENTER, "%H:%M:%S", id(esptime).now());
      // it.print(5, 3, id(ubuntuSmall), id(COLOR_CSS_YELLOW), TextAlign::TOP_LEFT, "ESPHome");
      it.printf(5, 3, id(ubuntuSmall),id(COLOR_CSS_YELLOW),"%s",(id(mydis).state).c_str());
 
      if (id(bme280_temperature).has_state()) 
        {
        it.printf(5, 25, id(ubuntuSmall),id(COLOR_CSS_GOLDENROD),"BME280 T: %.*f°c",1,id(bme280_temperature).state);
        it.printf(5, 41, id(ubuntuSmall),id(COLOR_CSS_GREENYELLOW),"BME280 H: %.*ff",1,id(bme280_humidity).state);
        it.printf(5, 57, id(ubuntuSmall),id(COLOR_CSS_HOTPINK),"BME280 P: %.*f°hPA",1,id(bme280_pressure).state);
        }

      if (id(tdisplay_button_input_0).state==0)
        it.filled_circle(155, 40, 6, id(COLOR_CSS_BLUE));
        else
        it.filled_circle(155, 40, 6, id(COLOR_CSS_HOTPINK));

      if (id(tdisplay_button_input_1).state==0)
        it.filled_circle(155, 60, 6, id(COLOR_CSS_BLUE));
        else
        it.filled_circle(155, 60, 6, id(COLOR_CSS_HOTPINK));
        
      // it.picture(0, 0, id(my_image));

web_server:
    port: 80

Coming Up

I now have an ESP8266 working a Dallas temperature chip (in stainless tube), a set of ws2812b RGB LEDs and an SH1106 128×64 1.2″ OLED show which is my second mission having realised that ILI9341 on ESP8266 utilizing ESPHOME isn’t a fantastic concept – I even have mission #3, slightly ATOM LITE ESP32 board which appears to have some points with RGB LEDs so that’s at the moment working an SSD1306 128×32 show – on this board I discovered the way to use PAGES of shows – at the moment cycled utilizing internet web page template buttons as I consider growing the pages and my WiFi graphical sign show – finally I’ll have the pages self-timed. Ignore the board NAME under – I initially went for an S1351 show…

esphome:
  title: s13512
  platform: ESP8266
  board: nodemcuv2
  #on_boot:
   # precedence: 250
   # then:
   #     - mild.turn_on: 
   #         id: LLED
   #         impact: rainbow
  platformio_options:
    board_build.f_cpu: 160000000L
     # then:
     #   - mild.turn_on:
     #       id: LLED
     #       brightness: 50%
     #       pink: 0%
     #       inexperienced: 30%
     #       blue: 100%    

# Allow logging
logger:

change:
  - platform: template
    title: "Rainbow"
    optimistic: true
    turn_on_action:
      - mild.turn_on: 
          id: LLED
          impact: rainbow
    turn_off_action:
      - mild.turn_off: 
          id: LLED
  - platform: template
    title: "Cyan"
    optimistic: true
    turn_on_action:
      - mild.turn_on: 
          id: LLED
          brightness: 100%
          pink: 0%
          inexperienced: 100%
          blue: 100%    
    turn_off_action:
      - mild.turn_off: 
          id: LLED
  - platform: template
    title: "Magenta"
    optimistic: true
    turn_on_action:
      - mild.turn_on: 
          id: LLED
          brightness: 100%
          pink: 100%
          inexperienced: 0%
          blue: 100%    
    turn_off_action:
      - mild.turn_off: 
          id: LLED

mqtt:
  dealer: 192.168.1.19
  username: admin
  password: T9quila123
  id: mqtt_client

sensor:
  - platform: dallas
    deal with: 0xD000000628016C28
    title: "Check Temperature"
    id: testtem

dallas:
  - pin: GPIO2

# Allow Residence Assistant API
#api:
#  password: ""

ota:
  password: ""

binary_sensor:
  - platform: standing
    title: "Node Standing"
    id: system_status

wifi:
  ssid: "wififorus"
  password: "xxxxxxxx"

  # Allow fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "SH1106 Fallback Hotspot"
    password: "nsa9P6d0UPQR"

#captive_portal:
web_server:
    port: 80

font:
  - file: "fonts/digital7.ttf"
    id: sseg
    dimension: 33
  - file: "fonts/ubuntu-r.ttf"
    id: tiny
    dimension: 10
   
time:
  - platform: sntp
    id: esptime

# Instance configuration entry
i2c:
  sda: D1
  scl: D2

mild:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: D8
    num_leds: 5
    rgb_order: GRB
    title: "LLED"
    id: LLED
    results:
      - addressable_random_twinkle:
          title: "twinkle"
      - addressable_fireworks:
          title: "fireworks"
      - addressable_color_wipe:
          title: "wipe"
      - addressable_rainbow:
          title: rainbow

show:
  - platform: ssd1306_i2c
    mannequin: "SH1106_128X64"
    deal with: 0x3C
    lambda: |-
      it.rectangle(0,  0, 128, 64);
      it.rectangle(0,  0, 128, 16);
      if (id(system_status).state) {
        it.print(124, 2, id(tiny), TextAlign::TOP_RIGHT, "On-line");
      }
      else {
        it.print(124, 2, id(tiny), TextAlign::TOP_RIGHT, "Offline");
      }
      if (id(testtem).has_state()) 
        it.printf(3, 2, id(tiny),"Dallas %.*f°c",1,id(testtem).state);

      it.strftime(3, 18, id(tiny), TextAlign::LEFT, "%A", id(esptime).now());
      it.strftime(124, 18, id(tiny), TextAlign::RIGHT, "%d-%m-%Y", id(esptime).now());

      it.strftime((128 / 2),40, id(sseg), TextAlign::CENTER, "%H:%M:%S", id(esptime).now());

I’ve had the latter board (LITE + SSD1306) out on the hill above our place working on a USB battery pack to examine for vary limits and to make sure my sign indicator works (4 easy rectangles, crammed or not as wants be by studying an inside worth from the YAML code). The opposite two boards merely say on-line or offline as applicable – however in actuality I’ve now updates all of them to the graphical indicator).

SH1106 display and ssd1306 display (3 PAGES)

And the code for the smaller SD1306-based board… within the YAML code the hash is a remark line – within the C part, typical C single-line feedback apply – however be cautious about indents – you’ll be able to’t put C feedback any extra left than the code itself – YAML is, it appears as unhealthy as PYTHON for being choosy about indents.

esphome:
  title: atomlite
  platform: ESP32
  board: m5stack-core-esp32
 
mqtt:
  dealer: 192.168.1.19
  username: admin
  password: T9quila123
  id: mqtt_client

i2c:
  sda: GPIO21
  scl: GPIO22

globals:
  - id: mypages
    kind: int
    restore_value: no
    initial_value: '0'

# Allow logging
logger:

# Allow Residence Assistant API
#api:
#  password: ""

ota:
  password: ""

wifi:
  ssid: "wififorus"
  password: "xxxxxxxxxx"

  # Allow fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Atomlite Fallback Hotspot"
    password: "OkUUvcffPVMG"

captive_portal:

time:
  - platform: sntp
    id: esptime

output:
  - platform: gpio
    pin: GPIO33
    id: leds

mild:
  - platform: binary
    title: "mylight"
    id: mylight
    output: leds

binary_sensor:
  - platform: standing
    title: "Node Standing"
    id: system_status

sensor:
  - platform: wifi_signal
    title: "WiFi Sign Sensor"
    update_interval: 15s
    id: sstrength
  - platform: uptime
    title: Uptime Sensor
    id: upt

web_server:
    port: 80

font:
  - file: "fonts/digital7.ttf"
    id: sseg
    dimension: 26
  - file: "fonts/ubuntu-r.ttf"
    id: tiny
    dimension: 12
  - file: "fonts/ubuntu-r.ttf"
    id: teeny
    dimension: 10

change:
  - platform: template
    title: "Easy LED"
    optimistic: true
    turn_on_action:
      - mild.turn_on: 
          id: mylight
    turn_off_action:
      - mild.turn_off: 
          id: mylight
  - platform: template
    title: "subsequent web page"
    #optimistic: true   - use this if utilizing on_turn_on however turn_on_action appears higher.
    turn_on_action:
      - show.web page.show_next: the_display

text_sensor:
  - platform: wifi_info
    ip_address:
      title: ESP IP Deal with
      id: ipaddr
    ssid:
      title: ESP Related SSID
    bssid:
      title: ESP Related BSSID
    mac_address:
      title: ESP Mac Wifi Deal with
      id: mac

show:
  - platform: ssd1306_i2c
    mannequin: "ssd1306_128X32"
    id: the_display
    deal with: 0x3C
    pages:
      - id: page1
        lambda: |-
              int x=(int)id(sstrength).state; 
              if (x<0)
              {
                if ((x>-90) && (x<0)) it.filled_rectangle( 0,14,5,4); else  it.rectangle( 0,14,5,4);          
                if ((x>-70) && (x<0)) it.filled_rectangle( 6,11,5,7); else  it.rectangle( 6,11,5,7);   
                if ((x>-50) && (x<0)) it.filled_rectangle( 12, 8,5,10); else it.rectangle( 12, 8,5,10);
                if ((x>-30) && (x<0)) it.filled_rectangle( 18,5,5,13); else it.rectangle( 18,5,5,13); 
              }

              it.strftime(0, 18, id(tiny), TextAlign::LEFT, "%A", id(esptime).now());
              it.strftime(127, 18, id(tiny), TextAlign::RIGHT, "%d-%m-%Y", id(esptime).now());
              it.strftime(127, 0, id(sseg), TextAlign::RIGHT, "%H:%M:%S", id(esptime).now());

      - id: page2
        lambda: |-
              int x=(int)id(sstrength).state; 
              it.printf(0,0,id(teeny), "WiFi: %idb",x);
              it.printf(0,10,id(teeny),"Addr: %s",(id(ipaddr).state).c_str());
              it.printf(0,20,id(teeny),"MAC:  %s",(id(mac).state).c_str());             

      - id: page3
        lambda: |-
              //it.printf(0,0,id(teeny),"UP: %0.0fs",(id(upt).state));
              int seconds = spherical(id(upt).state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              it.printf(0,0,id(teeny),"Uptime: %d days, %02d:%02d:%02d",days,hours,minutes,seconds);


Atom Lite ESPHOME code

If I’ve carried out something the arduous approach round, be at liberty to inform me the way to make a greater job. If you happen to don’t perceive the code, be at liberty to ask in right here however don’t anticipate miracles but – I’m nonetheless studying.

On the left you see the net server web page generated by the Atom lite – fairly useful for testing eithout having to wire up precise buttons – simply as properly, contemplating my new discovery that 4 of the ESP32 GPIOS can’t use inside pullups (that saved me going for some time till a sort chat within the ESPHOME boards enlightened me)

And for me one of the simplest ways to study is iterative small modifications to {hardware} and software program.

Good job I’ve a relentless provide of latest boards to check and play with – most of that are on my limited-space desk proper now. At this price I’m going to want a smaller keyboard.

See on the left the place it say “subsequent web page”? See the SWITCH part above and the platform: template named “subsequent web page” – properly that controls the pages outlined within the show part of the above code.

It’s all a little bit of a problem the primary time round however then you definitely rapidly get used to the thought, like a lot of ESPHOME.

AND NOW – the M5Stack Stamp Pico board

I didn’t even hassle with different environments for this board (I might have tried UIFLOW or Arduino) – I went straight in on the deep finish with ESPHOME.

I picked ESP32 because the goal and m5stack-atom because the board, as this was the closest out there choice – properly – it appears to work.

I repeated steps as earlier, utilizing the ESPHOME wizard and serial port to start out the ball rolling, then added:

After which with the PICO board + provided FTDI (USB-C) plugged into a standard USB charger I used to be able to rock – I went to http://stamp.lan on my community… by now I knew the way to get my credentials from the SECRETS.YAML file and began to repeat over helpful capabilities to the Stamp – however first…

Beneath, the preliminary YAML file for the STAMP (which doesnt truly DO something apart from hook up with WiFi and present that “stamp Internet Server” web page) – quickly I’ll begin pushing this little board to see simply what it might do. Because it has a couple of extra pins than the Atom Lite – I’m hopeful.

Quickly I can see an try coming as much as run a pair of OLED shows off thge similar I2C – pins – it must be potential to vary the default deal with od 3C to 3D simply sufficient – it stays to be seen if ESPHOME handles this or not.

Time will inform.

esphome:
  title: stamp
  platform: ESP32
  board: m5stack-atom

# Allow logging
logger:

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Allow fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Stamp Fallback Hotspot"
    password: !secret wifi_password
  
mqtt:
  dealer: !secret mqtt_broker
  username: !secret mqtt_user
  password: !secret mqtt_password
  id: mqtt_client

captive_portal:

web_server:
    port: 80

February 2023 Replace – Non-ESP boards and ESPHOME

My because of weblog subscriber Rogan Dawes for an thrilling replace on ESPHOME – two issues – regardless of the title – ESPHOME has apparently been ported to the Saspberry Pi Pico and Pico W boards and there’s a fork to be used with different chips.. See under:

There’s a new mission referred to as LibreTuya-ESPHome, which goals to port ESPHome to run on the varied Tuya modules. Could be attention-grabbing to know which module is in use inside this system.

Rogan has managed to get two Tuya units reflashed, one a RTL8710BN-based sensible change, and the opposite a BK7231T-based dimmer.

The cloud cutter mission goals to be Tuya-convert for the non-ESP modules.

The Tuya implementation is a fork with the intention of a future merge so as to add to that.

Cloud cutter is right here: https://github.com/tuya-cloudcutter/tuya-cloudcutter

Facebooktwitterpinterestlinkedin