From 8be1017d4abd2de2f67e3eac856991ded85e6d6d Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 22 Oct 2025 21:08:52 +0200 Subject: rename printer switch config --- esphome/config/printerswitch.yaml | 172 ++++++++++++++++++++++++++++++++++++++ esphome/config/pswitch.yaml | 172 -------------------------------------- 2 files changed, 172 insertions(+), 172 deletions(-) create mode 100644 esphome/config/printerswitch.yaml delete mode 100644 esphome/config/pswitch.yaml diff --git a/esphome/config/printerswitch.yaml b/esphome/config/printerswitch.yaml new file mode 100644 index 0000000..55ca307 --- /dev/null +++ b/esphome/config/printerswitch.yaml @@ -0,0 +1,172 @@ +substitutions: + device_name: printerswitch + friendly_name: "Printer Switch" + current_resistor: 0.0007978220592127652 + voltage_divider: 4422.084168336673 + # max power is 3450W for 15A and 2300W for 10A + max_power: "3450" + +esphome: + name: ${device_name} + friendly_name: ${friendly_name} + +esp8266: + board: esp01_1m + +# Enable logging +logger: + # make RXD / TXD available + baud_rate: 0 + level: DEBUG + +# Enable Home Assistant API +api: + encryption: + key: !secret api_encryption_key + +# OTA +ota: + - platform: esphome + password: !secret ota_password + +# WiFi Credentials +wifi: + domain: .lan + ssid: !secret wifi_ssid + password: !secret wifi_password + # see https://github.com/esphome/issues/issues/1532 + power_save_mode: HIGH + + # Enable fallback hotspot (captive portal) in case wifi connection fails + ap: + ssid: "${device_name} Hotspot" + password: !secret wifi_ap_password + +captive_portal: + +binary_sensor: + - platform: gpio + name: "Button" + device_class: power + pin: + number: GPIO01 + inverted: true + on_press: + - switch.toggle: relay + internal: true + +sensor: + - platform: hlw8012 + model: BL0937 + sel_pin: GPIO12 + cf_pin: GPIO04 + cf1_pin: GPIO05 + current_resistor: ${current_resistor} + voltage_divider: ${voltage_divider} + voltage: + id: voltage + filters: + - skip_initial: 2 + power: + id: power + internal: true + filters: + - skip_initial: 2 + on_value: + then: + # calculate current through P=U*I + - lambda: id(current).publish_state(x / id(voltage).state); + # idle power down. <5W + - if: + condition: + for: + time: 5min + condition: + and: + - switch.is_on: relay + - lambda: return id(power).state < 5.0; + then: + - logger.log: "idle power down" + - switch.turn_off: relay + on_value_range: + - above: ${max_power} + then: + - switch.turn_off: relay + energy: + id: energy + internal: true + update_interval: 1s + initial_mode: "VOLTAGE" + change_mode_every: never + + - platform: template + id: current + accuracy_decimals: 3 + update_interval: never + internal: true + + # templates sensors for the ui. we only update the sensor on relay events or through interval + # but only if switch is on. this way we don't push updates without changes to frontend + - platform: template + name: "Current" + id: current_ui + unit_of_measurement: "A" + accuracy_decimals: 3 + icon: "mdi:flash-outline" + update_interval: never + + - platform: template + name: "Voltage" + id: voltage_ui + unit_of_measurement: "V" + icon: "mdi:flash-outline" + update_interval: never + + - platform: template + name: "Power" + id: power_ui + unit_of_measurement: "W" + icon: "mdi:flash-outline" + update_interval: never + + - platform: template + name: "Energy" + id: energy_ui + unit_of_measurement: "Wh" + icon: "mdi:flash-outline" + update_interval: never + +switch: + - platform: gpio + name: "Relay" + id: relay + pin: GPIO14 + on_turn_on: + - output.turn_on: led + - lambda: id(current_ui).publish_state(id(current).state); + - lambda: id(voltage_ui).publish_state(id(voltage).state); + - lambda: id(power_ui).publish_state(id(power).state); + - lambda: id(energy_ui).publish_state(id(energy).state); + on_turn_off: + - output.turn_off: led + - lambda: id(current_ui).publish_state(0.0); + - lambda: id(voltage_ui).publish_state(0.0); + - lambda: id(power_ui).publish_state(0.0); + - lambda: id(energy_ui).publish_state(0.0); + +output: + - platform: esp8266_pwm + id: led + pin: GPIO13 + +interval: + - interval: 10s + then: + - if: + condition: + switch.is_on: relay + then: + - lambda: id(current_ui).publish_state(id(current).state); + - lambda: id(voltage_ui).publish_state(id(voltage).state); + - lambda: id(power_ui).publish_state(id(power).state); + - lambda: id(energy_ui).publish_state(id(energy).state); diff --git a/esphome/config/pswitch.yaml b/esphome/config/pswitch.yaml deleted file mode 100644 index 3b361e1..0000000 --- a/esphome/config/pswitch.yaml +++ /dev/null @@ -1,172 +0,0 @@ -substitutions: - device_name: pswitch - friendly_name: "Printer Switch" - current_resistor: 0.0007978220592127652 - voltage_divider: 4422.084168336673 - # max power is 3450W for 15A and 2300W for 10A - max_power: "3450" - -esphome: - name: ${device_name} - friendly_name: ${friendly_name} - -esp8266: - board: esp01_1m - -# Enable logging -logger: - # make RXD / TXD available - baud_rate: 0 - level: DEBUG - -# Enable Home Assistant API -api: - encryption: - key: !secret api_encryption_key - -# OTA -ota: - - platform: esphome - password: !secret ota_password - -# WiFi Credentials -wifi: - domain: .lan - ssid: !secret wifi_ssid - password: !secret wifi_password - # see https://github.com/esphome/issues/issues/1532 - power_save_mode: HIGH - - # Enable fallback hotspot (captive portal) in case wifi connection fails - ap: - ssid: "${device_name} Hotspot" - password: !secret wifi_ap_password - -captive_portal: - -binary_sensor: - - platform: gpio - name: "Button" - device_class: power - pin: - number: GPIO01 - inverted: true - on_press: - - switch.toggle: relay - internal: true - -sensor: - - platform: hlw8012 - model: BL0937 - sel_pin: GPIO12 - cf_pin: GPIO04 - cf1_pin: GPIO05 - current_resistor: ${current_resistor} - voltage_divider: ${voltage_divider} - voltage: - id: voltage - filters: - - skip_initial: 2 - power: - id: power - internal: true - filters: - - skip_initial: 2 - on_value: - then: - # calculate current through P=U*I - - lambda: id(current).publish_state(x / id(voltage).state); - # idle power down. <5W - - if: - condition: - for: - time: 5min - condition: - and: - - switch.is_on: relay - - lambda: return id(power).state < 5.0; - then: - - logger.log: "idle power down" - - switch.turn_off: relay - on_value_range: - - above: ${max_power} - then: - - switch.turn_off: relay - energy: - id: energy - internal: true - update_interval: 1s - initial_mode: "VOLTAGE" - change_mode_every: never - - - platform: template - id: current - accuracy_decimals: 3 - update_interval: never - internal: true - - # templates sensors for the ui. we only update the sensor on relay events or through interval - # but only if switch is on. this way we don't push updates without changes to frontend - - platform: template - name: "Current" - id: current_ui - unit_of_measurement: "A" - accuracy_decimals: 3 - icon: "mdi:flash-outline" - update_interval: never - - - platform: template - name: "Voltage" - id: voltage_ui - unit_of_measurement: "V" - icon: "mdi:flash-outline" - update_interval: never - - - platform: template - name: "Power" - id: power_ui - unit_of_measurement: "W" - icon: "mdi:flash-outline" - update_interval: never - - - platform: template - name: "Energy" - id: energy_ui - unit_of_measurement: "Wh" - icon: "mdi:flash-outline" - update_interval: never - -switch: - - platform: gpio - name: "Relay" - id: relay - pin: GPIO14 - on_turn_on: - - output.turn_on: led - - lambda: id(current_ui).publish_state(id(current).state); - - lambda: id(voltage_ui).publish_state(id(voltage).state); - - lambda: id(power_ui).publish_state(id(power).state); - - lambda: id(energy_ui).publish_state(id(energy).state); - on_turn_off: - - output.turn_off: led - - lambda: id(current_ui).publish_state(0.0); - - lambda: id(voltage_ui).publish_state(0.0); - - lambda: id(power_ui).publish_state(0.0); - - lambda: id(energy_ui).publish_state(0.0); - -output: - - platform: esp8266_pwm - id: led - pin: GPIO13 - -interval: - - interval: 10s - then: - - if: - condition: - switch.is_on: relay - then: - - lambda: id(current_ui).publish_state(id(current).state); - - lambda: id(voltage_ui).publish_state(id(voltage).state); - - lambda: id(power_ui).publish_state(id(power).state); - - lambda: id(energy_ui).publish_state(id(energy).state); -- cgit v1.2.3