esphome sntp offline fixes
This commit is contained in:
142
esphome/common/athompowermonv1_common.yaml
Normal file
142
esphome/common/athompowermonv1_common.yaml
Normal file
@@ -0,0 +1,142 @@
|
||||
##########################################################################################
|
||||
# GLOBAL VARIABLES
|
||||
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
|
||||
##########################################################################################
|
||||
globals:
|
||||
####################################################
|
||||
# total_energy: cumulative power
|
||||
# Not restored, so each boot starts fresh at 0.
|
||||
####################################################
|
||||
- id: total_energy
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: '0.0'
|
||||
|
||||
##########################################################################################
|
||||
# GENERAL COMMON SENSORS
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
sensor:
|
||||
#############################################
|
||||
# CSE7766 POWER SENSOR
|
||||
# https://esphome.io/components/sensor/cse7766.html
|
||||
#############################################
|
||||
- platform: hlw8012
|
||||
id: athom_hlw8012
|
||||
sel_pin:
|
||||
number: GPIO12
|
||||
inverted: True
|
||||
cf_pin: GPIO4
|
||||
cf1_pin: GPIO5
|
||||
voltage_divider: 780
|
||||
|
||||
current:
|
||||
name: "Current"
|
||||
id: current
|
||||
unit_of_measurement: A
|
||||
accuracy_decimals: 2
|
||||
icon: mdi:current-ac
|
||||
filters:
|
||||
- calibrate_linear:
|
||||
- 0.0000 -> 0.0110 # Relay off no load
|
||||
- 0.0097 -> 0.0260 # Relay on no load
|
||||
- 0.9270 -> 0.7570
|
||||
- 2.0133 -> 1.6330
|
||||
- 2.9307 -> 2.3750
|
||||
- 5.4848 -> 4.4210
|
||||
- 8.4308 -> 6.8330
|
||||
- 9.9171 -> 7.9830
|
||||
# Normalize for plug load
|
||||
- lambda: if (x < 0.0260) return 0; else return (x - 0.0260);
|
||||
on_value_range:
|
||||
- above: ${local_current_limit}
|
||||
then:
|
||||
- switch.turn_off: relay
|
||||
|
||||
voltage:
|
||||
name: "Voltage"
|
||||
id: voltage
|
||||
unit_of_measurement: V
|
||||
accuracy_decimals: 1
|
||||
icon: mdi:sine-wave
|
||||
filters:
|
||||
- skip_initial: 2
|
||||
|
||||
power:
|
||||
name: "Power"
|
||||
id: power_sensor
|
||||
unit_of_measurement: W
|
||||
accuracy_decimals: 1
|
||||
icon: mdi:power
|
||||
filters:
|
||||
- calibrate_linear:
|
||||
- 0.0000 -> 0.5900 # Relay off no load
|
||||
- 0.0000 -> 1.5600 # Relay on no load
|
||||
- 198.5129 -> 87.8300
|
||||
- 434.2469 -> 189.5000
|
||||
- 628.6241 -> 273.9000
|
||||
- 1067.0067 -> 460.1000
|
||||
- 1619.8098 -> 699.2000
|
||||
- 2043.0282 -> 885.0000
|
||||
# Normalize for plug load
|
||||
- lambda: if (x < 1.5600) return 0; else return (x - 1.5600);
|
||||
change_mode_every: 1
|
||||
update_interval: 5s
|
||||
|
||||
# Shows the Energy kWh since the device was last started
|
||||
energy:
|
||||
name: "Energy (Since Restart)"
|
||||
id: energy
|
||||
icon: mdi:lightning-bolt
|
||||
unit_of_measurement: kWh
|
||||
accuracy_decimals: 3
|
||||
filters:
|
||||
# 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();
|
||||
# internal: ${hide_energy_sensor}
|
||||
|
||||
#############################################
|
||||
# Total Energy (All Time)
|
||||
#############################################
|
||||
- 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: "60s"
|
||||
|
||||
#############################################
|
||||
# Total Daily Energy
|
||||
# https://esphome.io/components/sensor/total_daily_energy.html
|
||||
#############################################
|
||||
- platform: total_daily_energy
|
||||
name: "Total Daily Energy"
|
||||
restore: true
|
||||
power_id: power_sensor
|
||||
unit_of_measurement: kWh
|
||||
icon: mdi:hours-24
|
||||
accuracy_decimals: 3
|
||||
filters:
|
||||
- multiply: 0.001
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: True
|
127
esphome/common/athompowermonv3_common.yaml
Normal file
127
esphome/common/athompowermonv3_common.yaml
Normal file
@@ -0,0 +1,127 @@
|
||||
##########################################################################################
|
||||
# GLOBAL VARIABLES
|
||||
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
|
||||
##########################################################################################
|
||||
globals:
|
||||
####################################################
|
||||
# total_energy: cumulative power
|
||||
# Not restored, so each boot starts fresh at 0.
|
||||
####################################################
|
||||
- id: total_energy
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: '0.0'
|
||||
|
||||
##########################################################################################
|
||||
# GENERAL COMMON SENSORS
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
sensor:
|
||||
#############################################
|
||||
# CSE7766 POWER SENSOR
|
||||
# https://esphome.io/components/sensor/cse7766.html
|
||||
#############################################
|
||||
- platform: cse7766
|
||||
id: athom_cse7766
|
||||
current:
|
||||
name: "Current"
|
||||
icon: mdi:current-ac
|
||||
filters:
|
||||
- throttle_average: "10s"
|
||||
- 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: "${local_current_limit}"
|
||||
then:
|
||||
- switch.turn_off: relay
|
||||
voltage:
|
||||
name: "Voltage"
|
||||
icon: mdi:sine-wave
|
||||
filters:
|
||||
- throttle_average: "10s"
|
||||
power:
|
||||
name: "Power"
|
||||
id: power_sensor
|
||||
icon: mdi:power
|
||||
filters:
|
||||
- throttle_average: "10s"
|
||||
- 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
|
||||
icon: mdi:lightning-bolt
|
||||
unit_of_measurement: kWh
|
||||
filters:
|
||||
- throttle: "10s"
|
||||
# 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"
|
||||
icon: mdi:power
|
||||
filters:
|
||||
- throttle_average: "10s"
|
||||
reactive_power:
|
||||
name: "Reactive Power"
|
||||
icon: mdi:flash
|
||||
filters:
|
||||
- throttle_average: "10s"
|
||||
power_factor:
|
||||
name: "Power Factor"
|
||||
icon: mdi:percent-outline
|
||||
filters:
|
||||
- throttle_average: "10s"
|
||||
|
||||
#############################################
|
||||
# Total Energy (All Time)
|
||||
#############################################
|
||||
- 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: "60s"
|
||||
|
||||
#############################################
|
||||
# Total Daily Energy
|
||||
# https://esphome.io/components/sensor/total_daily_energy.html
|
||||
#############################################
|
||||
- platform: total_daily_energy
|
||||
name: "Total Daily Energy"
|
||||
restore: true
|
||||
power_id: power_sensor
|
||||
unit_of_measurement: kWh
|
||||
icon: mdi:hours-24
|
||||
accuracy_decimals: 3
|
||||
filters:
|
||||
- multiply: 0.001
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO06
|
||||
inverted: False
|
||||
|
||||
##########################################################################################
|
||||
# UART Bus
|
||||
# https://esphome.io/components/uart.html
|
||||
##########################################################################################
|
||||
uart:
|
||||
rx_pin: GPIO20
|
||||
baud_rate: 4800
|
||||
data_bits: 8
|
||||
stop_bits: 1
|
||||
parity: EVEN
|
@@ -37,6 +37,8 @@ substitutions:
|
||||
wifi:
|
||||
ssid: ${wifi_ssid}
|
||||
password: ${wifi_password}
|
||||
#enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management
|
||||
#enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management
|
||||
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
|
||||
manual_ip: # optional static IP address
|
||||
static_ip: ${local_static_ip_address}
|
||||
|
@@ -1,111 +0,0 @@
|
||||
#############################################
|
||||
# GENERAL COMMON SENSORS
|
||||
# https://esphome.io/components/sensor/
|
||||
#############################################
|
||||
sensor:
|
||||
- platform: uptime # Uptime for this device in seconds
|
||||
name: "Uptime (s):"
|
||||
update_interval: ${local_update_interval}
|
||||
id: uptime_sensor
|
||||
entity_category: "diagnostic"
|
||||
- platform: wifi_signal # Wifi Strength
|
||||
name: "Wifi (dB):"
|
||||
id: wifi_signal_db
|
||||
update_interval: ${local_update_interval}
|
||||
entity_category: "diagnostic"
|
||||
- platform: copy # Reports the WiFi signal strength in %
|
||||
source_id: wifi_signal_db
|
||||
name: "WiFi (%):"
|
||||
filters:
|
||||
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
|
||||
unit_of_measurement: "% Max"
|
||||
entity_category: "diagnostic"
|
||||
device_class: ""
|
||||
|
||||
binary_sensor:
|
||||
- platform: status
|
||||
name: "Network Status"
|
||||
icon: mdi:check-network-outline
|
||||
entity_category: diagnostic
|
||||
|
||||
#############################################
|
||||
# Text Sensors
|
||||
# https://esphome.io/components/text_sensor/index.html
|
||||
#############################################
|
||||
text_sensor:
|
||||
######################################################
|
||||
# General ESPHome Info
|
||||
######################################################
|
||||
- platform: version
|
||||
name: "Version:"
|
||||
entity_category: "diagnostic"
|
||||
- platform: wifi_info
|
||||
ip_address:
|
||||
icon: mdi:ip-network
|
||||
entity_category: diagnostic
|
||||
name: "IP Address:"
|
||||
ssid:
|
||||
name: "Connected SSID"
|
||||
icon: mdi:wifi-strength-2
|
||||
entity_category: diagnostic
|
||||
mac_address:
|
||||
name: "MAC Address:"
|
||||
icon: mdi:network-pos
|
||||
entity_category: diagnostic
|
||||
- platform: uptime # Uptime for this device human readable
|
||||
name: "Uptime:"
|
||||
icon: mdi:clock-start
|
||||
update_interval: ${local_update_interval}
|
||||
entity_category: "diagnostic"
|
||||
|
||||
|
||||
######################################################
|
||||
# Creates a sensor showing when the device was last restarted
|
||||
# Uptime template sensor, and SNTP are needed
|
||||
######################################################
|
||||
#- platform: template
|
||||
# name: ${local_friendly_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 (Days)"
|
||||
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
|
||||
|
||||
button:
|
||||
- platform: safe_mode
|
||||
name: "Safe Mode Restart: ${local_friendly_name}"
|
||||
entity_category: "diagnostic"
|
||||
- platform: restart
|
||||
name: "Restart: ${local_friendly_name}"
|
||||
entity_category: "diagnostic"
|
||||
disabled_by_default: true
|
||||
- platform: factory_reset
|
||||
name: "FACTORY RESET: ${local_friendly_name}"
|
||||
entity_category: "diagnostic"
|
||||
disabled_by_default: true
|
Reference in New Issue
Block a user