• Skip to main content
  • Shop
  • Learn
  • Blog
  • Forums
  • IO
  • LIVE!
  • AdaBox
Adafruit Logo
0
  • Sign In | Create Account
  • Playground
  • Shop
  • Learn
  • Blog
  • Forums
  • IO
  • LIVE!
  • AdaBox
Sign In
0
Adafruit Logo
  • Learn Categories
    • 3D Printing
    • AdaBox
    • Adafruit Products
    • Arduino Compatibles
    • Breakout Boards
    • Circuit Playground
    • CircuitPython
    • CLUE
    • Community Support
    • Components
    • Crickit
    • Customer & Partner Projects
    • Development Boards
    • Educators
    • EL Wire/Tape/Panel
    • Feather
    • Gaming
    • Hacks
    • Internet of Things - IOT
    • LCDs & Displays
    • LEDs
    • Machine Learning
    • MakeCode
    • Maker Business
    • micro:bit
    • Microcontrollers
    • Programming
    • Raspberry Pi
    • Robotics & CNC
    • Sensors
    • STEMMA
    • Tools
    • Trellis
    • Wearables
    Explore, Groups to get your gears turning
    Explore
    Groups to get your gears turning
    Explore Groups
  • New Guides
  • Playground
dholth Notes

dholth

u/dholth

Getting Started

Adafruit Playground is a wonderful and safe place to share your interests with Adafruit's vibrant community of makers and doers. Have a cool project you are working on? Have a bit of code that you think others will find useful? Want to show off your electronics workbench? You have come to the right place.

The goal of Adafruit Playground is to make it as simple as possible to share your work. On the Adafruit Playground users can create Notes. A note is a single-page space where you can document your topic using Adafruit's easy-to-use editor. Notes are like Guides on the Adafruit Learning System but guides are high-fidelity content curated and maintained by Adafuit. Notes are whatever you want them to be. Have fun and be kind.

Click here to learn more about Adafruit Playground and how to get started.

  • By dholth

    Home Assistant WiFi Button with CircuitPython

    Have you ever wanted to connect a simple button or sensor to Home Assistant using Circuit Python? This script demonstrates registering a device with Home Assistant so that it can be automatically connected to an Automation. The script triggers its event on power-on. The example uses the "trigger" type, which is better than "button" for a simple remote control. Other MQTT integrations could put a sensor reading on the dashboard, or turn your CircuitPython board into a WiFi light or fan.

    Ingredients

    • ESP32-C3 board running CircuitPython 9.1.4
    • Home Assistant with the MQTT integration and broker, accessible to the local network

    This script also demonstrates setting a BSSID, a 12-digit hexadecimal string, to connect to a specific access point.

    I was not able to connect to my local mosquitto MQTT broker over ssl; something about how the the MQTT client and broker interact prevents CircuitPython from validating the certificate. The comments include an example of loading a custom root certificate for the connection.

    How It Works

    Home Assistant's MQTT integration listens on the homeassistant/device_automation/# topic for discovery messages. When it sees a properly formatted message, it adds or updates that device under Settings > Devices and Services > MQTT > devices. It also listens on topic, here circuitpy/{unique_id}/action, for commands from the device. For a two-way device, you can also set a topic for Home Assistant to send commands back to CircuitPython.

    Now, we can add our device to an automation in Home Assistant without any additional configuration.

    Going Further

    Can we send our configuration messages with mqtt_client.publish(topic, msg, retain=True) so Home Assistant will remember us, even if it restarts before we do?

    Can we configure our CircuitPython board as a Home Assistant temperature sensor?

    Can we put the device in low power mode, wake on a pin change, and make a real battery-operated remote control?

    Use nginx to proxy SSL instead of mosqitto's idiosyncratic support.

    See also

    Screenshot_2024-10-11_at_20-18-23_Settings_–_Home_Assistant.png
    Save
Search

Getting Started

Adafruit Playground is a wonderful and safe place to share your interests with Adafruit's vibrant community of makers and doers. Have a cool project you are working on? Have a bit of code that you think others will find useful? Want to show off your electronics workbench? You have come to the right place.

The goal of Adafruit Playground is to make it as simple as possible to share your work. On the Adafruit Playground users can create Notes. A note is a single-page space where you can document your topic using Adafruit's easy-to-use editor. Notes are like Guides on the Adafruit Learning System but guides are high-fidelity content curated and maintained by Adafuit. Notes are whatever you want them to be. Have fun and be kind.

Click here to learn more about Adafruit Playground and how to get started.

    • Contact Us
    • Tech Support Forums
    • FAQs
    • Shipping & Returns
    • Freebies
    • Terms of Service
    • Privacy & Legal
    • Website Accessibility
    • LLMs.txt
    • About Us
    • Press
    • Educators
    • Distributors
    • Jobs
    • Gift Cards
    "Ever tried. Ever failed. No matter. Try again. Fail again. Fail better"
    Samuel Beckett
    Adafruit Logo
    A Minority and Woman-owned Business Enterprise (M/WBE)