mirror of
https://github.com/nuttytree/ESPHome-Devices.git
synced 2024-08-30 18:12:19 +00:00
3cffad99dd
* Update most everything to report power and energy to Home Assistant and Sense * ESPSense is pulled from GitHub Co-authored-by: Chris Nussbaum <chris.nussbaum@protolabs.com>
275 lines
8.4 KiB
YAML
275 lines
8.4 KiB
YAML
substitutions:
|
|
device_id: pool_pumps
|
|
device_name: Pool Pumps
|
|
platform: ESP8266
|
|
board: modwifi
|
|
ip_address: !secret pool_pumps_ip
|
|
ota_pwd: !secret pool_pumps_ota_pwd
|
|
api_pwd: !secret pool_pumps_api_pwd
|
|
ap_wifi_pwd: !secret pool_pumps_ap_wifi_pwd
|
|
|
|
packages:
|
|
device_base: !include ../packages/device_base.yaml
|
|
|
|
external_components:
|
|
- source: github://cbpowell/ESPSense
|
|
components: [ espsense ]
|
|
|
|
espsense:
|
|
plugs:
|
|
- name: Pool Pump
|
|
power_sensor: pool_pump_power
|
|
current_sensor: pool_pump_current
|
|
voltage_sensor: voltage
|
|
- name: Pool Cleaner
|
|
power_sensor: pool_cleaner_power
|
|
current_sensor: pool_cleaner_current
|
|
voltage_sensor: voltage
|
|
|
|
i2c:
|
|
sda: GPIO12
|
|
scl: GPIO14
|
|
|
|
sensor:
|
|
- platform: ade7953
|
|
voltage:
|
|
name: ${device_name} Voltage
|
|
id: voltage
|
|
filters:
|
|
- multiply: 2
|
|
current_a:
|
|
name: Pool Cleaner Current
|
|
id: pool_cleaner_current
|
|
filters:
|
|
- lambda: |-
|
|
// Filter the initial high current spike when the motor starts to prevent tripping the on_value_range logic
|
|
static float last_cleaner_current = 0.0;
|
|
if (isnan(x))
|
|
{
|
|
return {};
|
|
}
|
|
if (last_cleaner_current <= 7 && x > 7)
|
|
{
|
|
last_cleaner_current = x;
|
|
return {};
|
|
}
|
|
return last_cleaner_current = x < .1 ? 0.0 : x;
|
|
on_value_range:
|
|
above: 7
|
|
then:
|
|
- switch.turn_off: pool_cleaner
|
|
current_b:
|
|
name: Pool Pump Current
|
|
id: pool_pump_current
|
|
filters:
|
|
- lambda: |-
|
|
// Filter the initial high current spike when the motor starts to prevent tripping the on_value_range logic
|
|
static float last_pump_current = 0.0;
|
|
if (isnan(x))
|
|
{
|
|
return {};
|
|
}
|
|
if (last_pump_current <= 8 && x > 8)
|
|
{
|
|
last_pump_current = x;
|
|
return {};
|
|
}
|
|
return last_pump_current = x < .1 ? 0.0 : x;
|
|
on_value_range:
|
|
above: 8
|
|
then:
|
|
- switch.turn_off: pool_pump
|
|
active_power_a:
|
|
name: Pool Cleaner Power
|
|
id: pool_cleaner_power
|
|
filters:
|
|
- lambda: "return x < .1 ? 0 : x * 2;"
|
|
active_power_b:
|
|
name: Pool Pump Power
|
|
id: pool_pump_power
|
|
filters:
|
|
- lambda: "return abs(x) < .1 ? 0 : abs(x) * 2;"
|
|
update_interval: 2s
|
|
- platform: ntc
|
|
sensor: temp_resistance_reading
|
|
name: ${device_name} Temperature
|
|
unit_of_measurement: "°C"
|
|
accuracy_decimals: 1
|
|
icon: "mdi:thermometer"
|
|
calibration:
|
|
b_constant: 3350
|
|
reference_resistance: 10kOhm
|
|
reference_temperature: 0°C
|
|
- platform: resistance
|
|
id: temp_resistance_reading
|
|
sensor: temp_analog_reading
|
|
configuration: DOWNSTREAM
|
|
resistor: 32kOhm
|
|
- platform: adc
|
|
id: temp_analog_reading
|
|
pin: A0
|
|
- platform: template
|
|
name: "Pool Mode Id"
|
|
id: pool_mode_id
|
|
internal: true
|
|
- platform: total_daily_energy
|
|
name: "Pool Pump Total Daily Energy"
|
|
power_id: pool_pump_power
|
|
state_class: "measurement"
|
|
- platform: total_daily_energy
|
|
name: "Pool Cleaner Total Daily Energy"
|
|
power_id: pool_cleaner_power
|
|
state_class: "measurement"
|
|
|
|
status_led:
|
|
pin:
|
|
number: GPIO0
|
|
inverted: yes
|
|
|
|
switch:
|
|
- platform: gpio
|
|
pin: GPIO4
|
|
name: "Pool Pump"
|
|
id: pool_pump
|
|
icon: mdi:pump
|
|
on_turn_off:
|
|
then:
|
|
- switch.turn_off: pool_cleaner
|
|
- platform: gpio
|
|
pin: GPIO15
|
|
name: "Pool Cleaner"
|
|
id: pool_cleaner
|
|
icon: mdi:robot-vacuum
|
|
on_turn_on:
|
|
then:
|
|
- switch.turn_on: pool_pump
|
|
|
|
text_sensor:
|
|
- platform: homeassistant
|
|
name: "Pool Mode Text"
|
|
entity_id: input_select.pool_mode
|
|
on_value:
|
|
then:
|
|
- sensor.template.publish:
|
|
id: pool_mode_id
|
|
state: !lambda 'return x == "Off" ? 0 : x == "Normal" ? 1 : x == "Continuous Without Heat" ? 2 : x == "Continuous With Heat" ? 3 : id(pool_mode_id).state;'
|
|
|
|
time:
|
|
- platform: homeassistant
|
|
id: the_time
|
|
on_time:
|
|
seconds: 0
|
|
minutes: 0,15,30,45
|
|
then:
|
|
lambda: |-
|
|
if (id(pool_mode_id).state == 0)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_off");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
id(pool_cleaner).turn_off();
|
|
id(pool_pump).turn_off();
|
|
}
|
|
else if (id(pool_mode_id).state == 1)
|
|
{
|
|
auto now = id(the_time).now();
|
|
int hour = now.hour;
|
|
int minute = now.minute;
|
|
|
|
if (hour == 4 && minute == 45)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_off");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
id(pool_cleaner).turn_off();
|
|
id(pool_pump).turn_on();
|
|
}
|
|
else if (hour >= 5 && hour <= 6)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_off");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
if (id(pool_pump).state)
|
|
{
|
|
id(pool_cleaner).turn_on();
|
|
}
|
|
else
|
|
{
|
|
id(pool_pump).turn_on();
|
|
}
|
|
}
|
|
else if (hour == 7)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_on");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
id(pool_cleaner).turn_off();
|
|
id(pool_pump).turn_on();
|
|
}
|
|
else if (hour >= 8 && hour <= 21 && (minute == 0 || minute == 30))
|
|
{
|
|
id(pool_pump).turn_off();
|
|
}
|
|
else if (hour >= 8 && hour <= 21 && (minute == 15 || minute == 45))
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_on");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
id(pool_cleaner).turn_off();
|
|
id(pool_pump).turn_on();
|
|
}
|
|
else if (hour == 22 && minute == 0)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_off");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
id(pool_cleaner).turn_off();
|
|
id(pool_pump).turn_on();
|
|
}
|
|
else
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_off");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
id(pool_cleaner).turn_off();
|
|
id(pool_pump).turn_off();
|
|
}
|
|
}
|
|
else if (id(pool_mode_id).state == 2)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_off");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
if (id(pool_pump).state)
|
|
{
|
|
id(pool_cleaner).turn_on();
|
|
}
|
|
else
|
|
{
|
|
id(pool_pump).turn_on();
|
|
}
|
|
}
|
|
else if (id(pool_mode_id).state == 3)
|
|
{
|
|
auto ha_service = new api::HomeAssistantServiceCallAction<>(api_apiserver, false);
|
|
ha_service->set_service("switch.turn_on");
|
|
ha_service->add_data("entity_id", "switch.pool_heater");
|
|
ha_service->play();
|
|
if (id(pool_pump).state)
|
|
{
|
|
id(pool_cleaner).turn_on();
|
|
}
|
|
else
|
|
{
|
|
id(pool_pump).turn_on();
|
|
}
|
|
}
|