substitutions: # Default name name: "hallway-light-switch" # Default friendly name friendly_name: "Hallway Light Switch" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. Typically used for areas such as 'Lounge Room', 'Kitchen' etc room: "Hallway" # Description as appears in ESPHome & top of webserver page device_description: "Hallway Light Switch" # Project Name project_name: "Athom Technology.Mini Relay V2" # Projection version denotes the release version of the yaml file, allowing checking of deployed vs latest version project_version: "v2.0.4" # Restore the relay (GPO switch) upon reboot to state: light_restore_mode: RESTORE_DEFAULT_OFF # Set the update interval for sensors sensor_update_interval: 10s # Current Limit in Amps. current_limit : "10" # Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs) dns_domain: ".cloonar.smart" # Set timezone of the smart plug. Useful if the plug is in a location different to the HA server. Can be entered in unix Country/Area format (i.e. "Australia/Sydney") timezone: "" # Set the duration between the sntp service polling ntp.org servers for an update sntp_update_interval: 6h # Network time servers for your region, enter from lowest to highest priority. To use local servers update as per zones or countries at: https://www.ntppool.org/zone/@ sntp_server_1: "0.pool.ntp.org" sntp_server_2: "1.pool.ntp.org" sntp_server_3: "2.pool.ntp.org" # Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken wifi_fast_connect: "false" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "WARN" # Hide the ENERGY sensor that shows kWh consumed, but with no time period associated with it. Resets when device restarted and reflashed. hide_energy_sensor: "true" # Enable or disable the use of IPv6 networking on the device ipv6_enable: "false" esphome: name: "${name}" friendly_name: "${friendly_name}" comment: "${device_description}" area: "${room}" name_add_mac_suffix: false min_version: 2024.5.0 project: name: "${project_name}" version: "${project_version}" platformio_options: board_build.mcu: esp32c3 board_build.variant: esp32c3 board_build.flash_mode: dio esp32: board: esp32-c3-devkitm-1 flash_size: 4MB variant: ESP32C3 framework: type: arduino version: recommended preferences: flash_write_interval: 5min api: ota: - platform: esphome mdns: disabled: false web_server: port: 80 network: enable_ipv6: ${ipv6_enable} wifi: ssid: !secret wifi_ssid password: !secret wifi_password fast_connect: True domain: ${dns_domain} esp32_improv: authorizer: none uart: rx_pin: GPIO20 baud_rate: 4800 data_bits: 8 stop_bits: 1 parity: EVEN globals: - id: total_energy type: float restore_value: yes initial_value: '0.0' binary_sensor: - platform: status name: "Status" entity_category: diagnostic - platform: gpio pin: number: GPIO3 mode: INPUT_PULLUP inverted: true name: "Power Button" disabled_by_default: true on_multi_click: - timing: - ON for at most 1s - OFF for at least 0.2s then: - light.toggle: mini_relay - timing: - ON for at least 4s then: - button.press: Reset - platform: gpio id: the_switch name: "Power Switch" pin: number: GPIO4 mode: INPUT_PULLUP inverted: true on_multi_click: - timing: - ON for at most 1s then: - light.toggle: mini_relay sensor: - platform: uptime name: "Uptime Sensor" id: uptime_sensor entity_category: diagnostic internal: true - platform: wifi_signal name: "WiFi Signal dB" id: wifi_signal_db update_interval: 60s entity_category: "diagnostic" - platform: copy source_id: wifi_signal_db name: "WiFi Signal Percent" filters: - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); unit_of_measurement: "Signal %" entity_category: "diagnostic" device_class: "" - platform: cse7766 id: athom_cse7766 current: name: "Current" filters: - throttle_average: ${sensor_update_interval} - lambda: if (x < 0.060) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected on_value_range: - above: ${current_limit} then: - light.turn_off: mini_relay voltage: name: "Voltage" filters: - throttle_average: ${sensor_update_interval} power: name: "Power" id: power_sensor filters: - throttle_average: ${sensor_update_interval} - lambda: if (x < 3.0) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected energy: name: "Energy" id: energy unit_of_measurement: kWh filters: - throttle: ${sensor_update_interval} # Multiplication factor from W to kW is 0.001 - multiply: 0.001 on_value: then: - lambda: |- static float previous_energy_value = 0.0; float current_energy_value = id(energy).state; id(total_energy) += current_energy_value - previous_energy_value; previous_energy_value = current_energy_value; id(total_energy_sensor).update(); apparent_power: name: "Apparent Power" filters: - throttle_average: ${sensor_update_interval} reactive_power: name: "Reactive Power" filters: - throttle_average: ${sensor_update_interval} power_factor: name: "Power Factor" filters: - throttle_average: ${sensor_update_interval} - platform: template name: "Total Energy" id: total_energy_sensor unit_of_measurement: kWh device_class: "energy" state_class: "total_increasing" icon: "mdi:lightning-bolt" accuracy_decimals: 3 lambda: |- return id(total_energy); update_interval: ${sensor_update_interval} - platform: total_daily_energy name: "Total Energy Today" restore: true power_id: power_sensor unit_of_measurement: kWh accuracy_decimals: 3 filters: - multiply: 0.001 button: - platform: restart name: "Restart" entity_category: config - platform: factory_reset name: "Factory Reset" id: Reset entity_category: config - platform: safe_mode name: "Safe Mode" internal: false entity_category: config output: - platform: gpio id: relay_output pin: GPIO6 light: - platform: status_led id: led name: "Blue LED" disabled_by_default: true pin: number: GPIO7 inverted: true - platform: binary id: mini_relay output: relay_output name: "Mini Switch" restore_mode: ${light_restore_mode} on_turn_on: - light.turn_on: led on_turn_off: - light.turn_off: led text_sensor: - platform: wifi_info ip_address: name: "IP Address" entity_category: diagnostic ssid: name: "Connected SSID" entity_category: diagnostic mac_address: name: "Mac Address" entity_category: diagnostic # Creates a sensor showing when the device was last restarted - platform: template name: 'Last Restart' id: device_last_restart icon: mdi:clock entity_category: diagnostic # device_class: timestamp # Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds - platform: template name: "Uptime" entity_category: diagnostic lambda: |- int seconds = (id(uptime_sensor).state); int days = seconds / (24 * 3600); seconds = seconds % (24 * 3600); int hours = seconds / 3600; seconds = seconds % 3600; int minutes = seconds / 60; seconds = seconds % 60; if ( days > 3650 ) { return { "Starting up" }; } else if ( days ) { return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() }; } else if ( hours ) { return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() }; } else if ( minutes ) { return { (String(minutes) +"m "+ String(seconds) +"s").c_str() }; } else { return { (String(seconds) +"s").c_str() }; } icon: mdi:clock-start time: - platform: sntp id: sntp_time # Define the timezone of the device timezone: "${timezone}" # Change sync interval from default 5min to 6 hours (or as set in substitutions) update_interval: ${sntp_update_interval} # Set specific sntp servers to use servers: - "${sntp_server_1}" - "${sntp_server_2}" - "${sntp_server_3}" # Publish the time the device was last restarted on_time_sync: then: # Update last restart time, but only once. - if: condition: lambda: 'return id(device_last_restart).state == "";' then: - text_sensor.template.publish: id: device_last_restart state: !lambda 'return id(sntp_time).now().strftime("%a %d %b %Y - %I:%M:%S %p");'