From cac1949e3a1e3073b1ece7fc1ac05163ae81b520 Mon Sep 17 00:00:00 2001 From: Aiden <891483489@qq.com> Date: Fri, 20 Sep 2024 10:33:43 +0800 Subject: [PATCH] add without relay plug --- .github/workflows/ci.yml | 1 + .github/workflows/publish.yml | 3 +- athom-without-relay-plug.yaml | 325 ++++++++++++++++++++++++++++++++++ 3 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 athom-without-relay-plug.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9059bd0..33dd636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: - athom-sw03.yaml - athom-sw04.yaml - athom-wall-outlet.yaml + - athom-without-relay-plug.yaml steps: - name: Checkout source code uses: actions/checkout@v4.1.7 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 03587a6..51ace1b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,6 +31,7 @@ jobs: athom-sw02.yaml, athom-sw03.yaml, athom-sw04.yaml, - athom-wall-outlet.yaml + athom-wall-outlet.yaml, + athom-without-relay-plug.yaml # CHANGEME: Set the name of your project here: name: Athom ESP8285 Device \ No newline at end of file diff --git a/athom-without-relay-plug.yaml b/athom-without-relay-plug.yaml new file mode 100644 index 0000000..af2ec1c --- /dev/null +++ b/athom-without-relay-plug.yaml @@ -0,0 +1,325 @@ +substitutions: + name: "athom-without-relay-plug" + friendly_name: "Smart Plug" + # Allows ESP device to be automatically lined to an 'Area' in Home Assistant. Typically used for areas such as 'Lounge Room', 'Kitchen' etc + room: "" + device_description: "athom esp8285 without relay plug" + project_name: "Athom Technology.Athom Without Relay Plug" + project_version: "v2.0.5" + sensor_update_interval: "10s" + # 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: "" + # 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: "INFO" + # Enable or disable the use of IPv6 networking on the device + ipv6_enable: "false" + # 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: "false" + +esphome: + name: "${name}" + friendly_name: "${friendly_name}" + comment: "${device_description}" + area: "${room}" + name_add_mac_suffix: true + min_version: 2024.6.0 + project: + name: "${project_name}" + version: "${project_version}" + +esp8266: + board: esp8285 + restore_from_flash: true + +preferences: + flash_write_interval: 5min + +api: + +ota: + - platform: esphome + +logger: + level: ${log_level} + baud_rate: 0 + +mdns: + disabled: false + +web_server: + port: 80 + +network: + enable_ipv6: ${ipv6_enable} + +wifi: + # This spawns an AP with the device name and mac address with no password. + ap: {} + # Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID + fast_connect: "${wifi_fast_connect}" + # Define dns domain / suffix to add to hostname + domain: "${dns_domain}" + +captive_portal: + +dashboard_import: + package_import_url: github://athom-tech/athom-configs/athom-without-relay-plug.yaml + +# Dentra Components - Adds 'Platform - Energy Statistics' +# https://github.com/dentra/esphome-components/tree/master/components/energy_statistics +# external_components: +# - source: github://dentra/esphome-components + +uart: + rx_pin: RX + baud_rate: 4800 + +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: 5 + mode: INPUT_PULLUP + inverted: true + name: "Button" + disabled_by_default: true + on_multi_click: + - timing: + - ON for at least 4s + then: + - button.press: Reset + +sensor: + - platform: uptime + name: "Uptime Sensor" + id: uptime_sensor + entity_category: diagnostic + internal: true + + # Reports the WiFi signal strength/RSSI in dB + - platform: wifi_signal + name: "WiFi Signal dB" + id: wifi_signal_db + update_interval: 60s + entity_category: diagnostic + + # Reports the WiFi signal strength in % + - 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: "%" + entity_category: diagnostic + device_class: "" + + - platform: 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 + + 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 + internal: ${hide_energy_sensor} + 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} + + 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 Since Boot" + restore: true + power_id: power_sensor + unit_of_measurement: kWh + icon: mdi:hours-24 + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + # # Dentra Components - Define the id of the sensor providing 'Total Energy' used + # - platform: "energy_statistics" + # total: total_energy_sensor + + # # Dentra Components - Adds Energy Today. Persistents if restarted, unlike 'total_daily_energy' + # energy_today: + # name: "Energy Today" + # id: total_energy_today + # accuracy_decimals: 3 + # icon: mdi:hours-24 + + # # Dentra Components - Adds Energy Yesterday + # energy_yesterday: + # name: "Total Energy Yesterday" + # id: total_energy_yesterday + # accuracy_decimals: 3 + + # # Dentra Components - Adds Energy Week + # energy_week: + # name: "Total Energy Week" + # id: total_energy_week + # accuracy_decimals: 3 + + # # Dentra Components - Adds Energy Month + # energy_month: + # name: "Total Energy Month" + # id: total_energy_month + # accuracy_decimals: 3 + +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 + +light: + - platform: status_led + name: "Status LED" + id: blue_led + disabled_by_default: true + pin: + inverted: true + number: GPIO13 + +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");' \ No newline at end of file