Finaler "smarter" Code für die Lüftersteuerung

 avatar
unknown
plain_text
4 months ago
2.5 kB
14
Indexable
esphome:
  name: pwmfan
  friendly_name: pwmfan

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "123456789123456"

ota:
  platform: esphome
  password: "12345612345678"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  manual_ip:
    static_ip: 192.168.178.126
    gateway: 192.168.178.1
    subnet: 255.255.255.0

  ap:
    ssid: "Pwmfan Fallback Hotspot"
    password: "123456789"

captive_portal:

# Output configurations for PWM signals
output:
  - platform: ledc
    pin: GPIO27
    frequency: 5000 Hz
    id: fan_pwm_1
  - platform: ledc
    pin: GPIO33
    frequency: 5000 Hz
    id: fan_pwm_2
  - platform: ledc
    pin: GPIO32
    frequency: 5000 Hz
    id: fan_pwm_3

# Input controls for the GUI
number:
  - platform: template
    name: "Fan Speed [%]"
    id: fan_speed
    min_value: 0
    max_value: 100
    step: 1
    optimistic: true
    set_action:
      - lambda: |-
          ESP_LOGD("fan_speed", "Fan Speed set to: %.2f", x);

  - platform: template
    name: "Night Reduction [%]"
    id: night_reduction
    min_value: 0
    max_value: 100
    step: 1
    optimistic: true
    set_action:
      - lambda: |-
          ESP_LOGD("night_reduction", "Night Reduction set to: %.2f", x);

switch:
  - platform: template
    name: "Winter Mode"
    id: winter_mode
    optimistic: true
    turn_on_action:
      - lambda: |-
          ESP_LOGD("winter_mode", "Winter Mode turned ON");
    turn_off_action:
      - lambda: |-
          ESP_LOGD("winter_mode", "Winter Mode turned OFF");

# Fan speed automation
interval:
  - interval: 1s
    then:
      - lambda: |
          float speed = id(fan_speed).state;
          float reduction = id(night_reduction).state;
          bool winter = id(winter_mode).state;

          static bool reverse = false;
          static unsigned long last_swap = millis();

          if (winter && (millis() - last_swap >= 45000)) {
            reverse = !reverse;
            last_swap = millis();
          }


          float fan1_speed = 50 + (reverse ? -1 : 1) * speed * 0.5;
          float fan2_speed = 50 + (reverse ? 1 : -1) * speed * 0.5;
          float fan3_speed = 50 + ((reverse ? -1 : 1) * speed * 0.5 * (100 - reduction)/100);

          // Apply fan speeds
          id(fan_pwm_1).set_level(fan1_speed / 100.0);
          id(fan_pwm_2).set_level(fan2_speed / 100.0);
          id(fan_pwm_3).set_level(fan3_speed / 100.0);
Editor is loading...
Leave a Comment