From 192ea652d37afdbeea634751795009b3af2d6183 Mon Sep 17 00:00:00 2001 From: Roving Ronin <108674933+Roving-Ronin@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:28:09 +1100 Subject: [PATCH 1/2] Update athom-smart-plug-v2.yaml Changes: entity_category: diagnostic and entity_category: config - In HA this places these sensors and configuration items in the correct location, when viewing the individual devices in the ESP Home integration Uptime Sensor & WiFi Signal - Change to internal, whilst allowing their use in sensors that format the output to be more useful or meaningful WiFi Strength - Add sensor that reports signal as a %, as compared to Db that is meaningless to most people. Pulls data from WiFi Signal sensor. Device Uptime - Add a sensor that uses Uptime Sensor to provide a formatted output of the days/hours/seconds the device has been up, as opposed to a xxxxxx seconds, that to be meaningful needs deciding with a calculator sntp_time - Add a sensor that reports the actual day, date and time of when the device was last restarted --- athom-smart-plug-v2.yaml | 74 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/athom-smart-plug-v2.yaml b/athom-smart-plug-v2.yaml index c12c2976..6f94d246 100644 --- a/athom-smart-plug-v2.yaml +++ b/athom-smart-plug-v2.yaml @@ -37,6 +37,8 @@ web_server: port: 80 wifi: + # Directly connects to WiFi network without doing a full scan first + fast_connect: true ap: {} # This spawns an AP with the device name and mac address with no password. captive_portal: @@ -57,6 +59,7 @@ globals: binary_sensor: - platform: status name: "Status" + entity_category: diagnostic - platform: gpio pin: @@ -79,10 +82,26 @@ binary_sensor: sensor: - platform: uptime name: "Uptime Sensor" + id: uptime_sensor + entity_category: diagnostic + internal: True - platform: wifi_signal name: "WiFi Signal" + id: wifi_signal_db update_interval: 60s + entity_category: diagnostic + internal: true + + # Reports the WiFi signal strength in % + - platform: copy + source_id: wifi_signal_db + name: "WiFi Strength" + filters: + - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); + unit_of_measurement: "%" + entity_category: diagnostic + - platform: cse7766 current: @@ -146,11 +165,13 @@ button: - platform: factory_reset name: "Restart with Factory Default Settings" id: Reset - + entity_category: config + - platform: safe_mode name: "Safe Mode" internal: false - + entity_category: config + switch: - platform: gpio name: "${friendly_name}" @@ -172,11 +193,60 @@ 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: 'Device 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: "Device 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 + # Change sync interval from default 5min to 6 hours + update_interval: 360min + # 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");' From 0b49ab1488f80282eed24190834f45bb794b7ae2 Mon Sep 17 00:00:00 2001 From: Roving Ronin <108674933+Roving-Ronin@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:31:29 +1100 Subject: [PATCH 2/2] Update athom-smart-plug-v2.yaml Removed WiFi Fast Connection --- athom-smart-plug-v2.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/athom-smart-plug-v2.yaml b/athom-smart-plug-v2.yaml index 6f94d246..edc1931e 100644 --- a/athom-smart-plug-v2.yaml +++ b/athom-smart-plug-v2.yaml @@ -37,8 +37,6 @@ web_server: port: 80 wifi: - # Directly connects to WiFi network without doing a full scan first - fast_connect: true ap: {} # This spawns an AP with the device name and mac address with no password. captive_portal: