Skip to content

Instantly share code, notes, and snippets.

@deosrc
Last active January 24, 2024 17:13
Show Gist options
  • Save deosrc/5861d64e8a81fea78dc3e46ed2a12822 to your computer and use it in GitHub Desktop.
Save deosrc/5861d64e8a81fea78dc3e46ed2a12822 to your computer and use it in GitHub Desktop.
ESPHome WIP Config for Adafruit MagTag
# Common Sensors
binary_sensor:
- platform: status
name: "${device_name} Status"
# System
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret lan_domain
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: $device_name
password: !secret wifi_password
ota:
password: !secret ota_password
logger:
baud_rate: 0
substitutions:
device_id: office-magtag
device_name: Office MagTag
# Device Details
esphome:
name: $device_id
esp32:
board: adafruit_magtag29_esp32s2
framework:
type: arduino
# Common
packages:
base: !include base_modified.yaml
mqtt: !include mqtt.yaml
switch:
- platform: gpio
pin:
number: GPIO21
inverted: yes
name: ${device_name} Aux Power # Used for LEDs and Light Sensor
restore_mode: ALWAYS_ON
internal: true # Don't export this, just leave it always on
# Lights
light:
- id: header_lights
platform: neopixelbus
type: GRB
variant: WS2811
pin: GPIO1
num_leds: 4
name: "NeoPixel"
effects:
- pulse:
- random:
- strobe:
- addressable_rainbow:
- addressable_color_wipe:
- addressable_scan:
- addressable_twinkle:
- addressable_random_twinkle:
- addressable_fireworks:
- platform: status_led
name: ${device_name} Status LED
pin: GPIO13
# Light Sensor
# FIXME: src/esphome/components/adc/adc_sensor.cpp:65:21: error: 'ADC_WIDTH_BIT_12' was not declared in this scope
# sensor:
# - platform: adc
# pin: A3
# name: ${device_name} Light Sensor
# Buttons
binary_sensor:
- name: Button Left
platform: gpio
internal: true
pin:
number: GPIO15
inverted: true
mode:
input: true
pullup: true
- name: Button Up
platform: gpio
internal: true
pin:
number: GPIO14
inverted: true
mode:
input: true
pullup: true
- name: Button for Light
platform: gpio
pin:
number: GPIO12
inverted: true
mode:
input: true
pullup: true
- name: Button Right
platform: gpio
internal: true
pin:
number: GPIO11
inverted: true
mode:
input: true
pullup: true
# Display
font:
- file:
type: gfonts
family: Ubuntu
id: font_default
size: 12
spi:
clk_pin: GPIO36
mosi_pin: GPIO35
miso_pin: GPIO37
display:
- id: device_display
platform: waveshare_epaper
cs_pin: GPIO8
dc_pin: GPIO7
busy_pin: GPIO5
reset_pin: GPIO6
model: gdey029t94
update_interval: 60s
rotation: 270
lambda: |-
it.print(0, 0, id(font_default), "Hello World!");
broker: !secret mqtt_host
username: esphome
password: !secret mqtt_password
client_id: $device_id
topic_prefix:
esphome/${device_id}
@deosrc
Copy link
Author

deosrc commented Jan 8, 2024

@adavidzh I've gotten the magtag working much better since posting this gist. I've updated the above based on my current config but not sure it's complete and I've not tested the above on it's own.

@adavidzh
Copy link

adavidzh commented Jan 9, 2024

Interesting. I also got the light sensor and VBAT measurement to work:

sensor:
  # Light Sensor
  - platform: adc
    pin: GPIO3
    name: Pronote Light Sensor
    filters:
      - offset: -0.030

  - platform: adc
    pin: GPIO4
    name: Battery voltage
    id: battery_voltage
    accuracy_decimals: 2
    update_interval: 60s
    attenuation: 11db
    filters:
      # From the schematics there is a by-2 divider:
      # https://learn.adafruit.com/assets/96946
      - multiply: 2.0

The I2C is also correctly scanned:

i2c:
  sda: GPIO33
  scl: GPIO34
  scan: true

The speaker also works:

# Based on https://esphome.io/components/output/ledc
# and https://esphome.io/components/rtttl.html
output:
  - platform: ledc
    id: spk_out
    pin: GPIO17

rtttl:
  output: spk_out
  id: speaker
  on_finished_playback:
    - switch.turn_off: speaker_power

I am using deep_sleep and before entering sleep the power to the LEDs, light sensor, and speakers can be automatically turned off using:

esphome: # https://esphome.io/components/esphome
  # [...]
  on_shutdown:
    priority: 700
    then:
      - switch.turn_off: neopixel_power
      - switch.turn_off: speaker_power

Another thing that works is to power on/off the LEDs automatically:

light:
  - platform: fastled_clockless
     #[...]
    on_turn_on:
      - switch.turn_on: neopixel_power
    on_turn_off:
      - switch.turn_off: neopixel_power

@mjpiratex
Copy link

mjpiratex commented Jan 24, 2024

The speaker also works:

# Based on https://esphome.io/components/output/ledc
# and https://esphome.io/components/rtttl.html
output:
  - platform: ledc
    id: spk_out
    pin: GPIO17

rtttl:
  output: spk_out
  id: speaker
  on_finished_playback:
    - switch.turn_off: speaker_power

I am using deep_sleep and before entering sleep the power to the LEDs, light sensor, and speakers can be automatically turned off using:

esphome: # https://esphome.io/components/esphome
  # [...]
  on_shutdown:
    priority: 700
    then:
      - switch.turn_off: neopixel_power
      - switch.turn_off: speaker_power

Another thing that works is to power on/off the LEDs automatically:

light:
  - platform: fastled_clockless
     #[...]
    on_turn_on:
      - switch.turn_on: neopixel_power
    on_turn_off:
      - switch.turn_off: neopixel_power

Can you elaborate on what you are using to define 'speaker_power'?

@adavidzh
Copy link

Can you elaborate on what you are using to define speaker_power?

This is the pin that powers the audio amplifier:

switch:
  - platform: gpio
    name: NeoPixel Power # Used for LEDs and Light Sensor
    pin:
      number: GPIO21
      inverted: yes
    id: neopixel_power
    internal: true # Don't export this
  
  - platform: gpio
    name: Speaker Power # Used for Speaker amplifier
    pin:
      number: GPIO16
    id: speaker_power
    internal: true # Don't export this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment