Programming


Basic node functionality

Configuration code to put in the NODE_NAME.yaml file to get basic node functionality.

Replace the following in the code to suit your specific setup:

  • NODE_NAME
  • NODE_NAME_API_KEY
  • NODE_NAME_OTA_PASSWORD
  • WIFI_NAME
  • WIFI_PASSWORD
  • NODE_NAME_FALLBACK_WIFI
  • NODE_NAME_FALLBACK_PASSWORD
# Basic functionality
esphome:
  name: NODE_NAME
  platform: ESP32
  board: esp32-devkitlipo

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "NODE_NAME_API_KEY"

# Enable Over the Air updates
ota:
  - platform: esphome
    password: "NODE_NAME_OTA_PASSWORD"

# Configure primary and fallback WiFi
wifi:
  ssid: "WIFI_NAME"
  password: "WIFI_PASSWORD"
  ap:
    ssid: "NODE_NAME_FALLBACK_WIFI"
    password: "NODE_NAME_FALLBACK_PASSWORD"

captive_portal:

# Web server settings
web_server:
  port: 80
  ota: false

# Remote board switches
switch:
  - platform: restart
    name: "NODE_NAME reboot node"
#  - platform: shutdown
#    name: "NODE_NAME shutdown node"

# System sensors
text_sensor:
  - platform: wifi_info
    ip_address:
      name: "NODE_NAME IP"
      icon: "mdi:ip-network-outline"
    mac_address:
      name: "NODE_NAME MAC"
      icon: "mdi:network-outline"

Digital temperature sensors

Configuration code for digital temperature sensors. The code is for three temperature sensors but can be adapted for any reasonable number of sensors.

Begin by uploading just the first block dallas: and watch for the hardware address of each temperature sensor in the console log output. Then use those addresses to complete the second block sensor: and upload. Sensor hardware addresses are on hexadecimal form, for example 0x6C00000CA32B7B23.

Replace the following in the code to suit your specific setup:

  • INPUT_PIN_NUMBER
  • TEMPERATURE_SENSOR_NAME_1
  • TEMPERATURE_SENSOR_ADDRESS_1
  • TEMPERATURE_SENSOR_NAME_2
  • TEMPERATURE_SENSOR_ADDRESS_2
  • TEMPERATURE_SENSOR_NAME_3
  • TEMPERATURE_SENSOR_ADDRESS_3
# Temperature sensor input
one_wire:
  - platform: gpio
    pin: INPUT_PIN_NUMBER
    update_interval: 30s

# Temperature sensors
sensor:
  - platform: dallas_temp
    address: TEMPERATURE_SENSOR_ADDRESS_1
    name: "TEMPERATURE_SENSOR_NAME_1"
    resolution: 12
  - platform: dallas_temp
    address: TEMPERATURE_SENSOR_ADDRESS_2
    name: "TEMPERATURE_SENSOR_NAME_2"
    resolution: 12
  - platform: dallas_temp
    address: TEMPERATURE_SENSOR_ADDRESS_3
    name: "TEMPERATURE_SENSOR_NAME_3"
    resolution: 12

Pulse counters

Configuration code for a pulse counter. The code is for an reading the flashing indicator light on an energy meter. Each kilowatt-hour (kWh) corresponds to 1000 flashes. The pulse counter reads the number of flashes during 1 minute which can be used to calculate the current average power usage in kilowatts (kW).

Replace the following in the code to suit your specific setup:

  • INPUT_PIN_NUMBER
  • POWER_SENSOR_NAME
  • ENERGY_SENSOR_NAME
# Power sensor settings
sensor:
  - platform: pulse_counter
    pin: INPUT_PIN_NUMBER
    name: "POWER_SENSOR_NAME"
    device_class: power
    state_class: measurement
    unit_of_measurement: "kW"
    accuracy_decimals: 3
    update_interval: 60s
    filters:
      - multiply: 0.06  # 60s/1000 impulses per kW
# Energy sensor settings
    total:
      name: "ENERGY_SENSOR_NAME"
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: "kWh"
      accuracy_decimals: 3
      filters:
        - multiply: 0.001  # 1/1000 impulses per kWh