3ative / PWM-Fan-controller

An ESPHome Automatic PWM Fan controller with Alarm
MIT License
25 stars 5 forks source link

temperature and humidity #3

Closed grssll closed 1 year ago

grssll commented 1 year ago

Hi, thanks for the excellent work and explanation on the code. I've managed to implement your code with BME280 and 0-10v GP8403 component to control whirlybird fans. Trying to modify the code to use with both temperature and humidity but so far no luck. Any chance for the guidance in the right direction? Coffee on me to keep u up! Thank you

3ative commented 1 year ago

Thank you for the compliment, I'm happy to hear my project was/is useful to you.

It's unclear what help you are looking for and I'd need some more info: -- What have you done so far -- What, if any, errors are you getting -- How have you configured the new components

3ative commented 1 year ago

Also, is this for DAC you are using? 2-Channel I2C DAC Module (0-10V)

grssll commented 1 year ago

What I'm trying to achieve is Lambda automation based on temperature and humidity. For example in the morning temperature drops and the fan turns off. But at the same time humidity rises and it would be nice to get automation based on two readings. BME280 provides both temperature and humidity. I'm using Dfrobot dac and it works perfectly on your Lambda code and temperature from bme280. I hope it's little bit clear. Cheers George

grssll commented 1 year ago

Take PCT of temperature as u did before, Take PCT of humidity, combine them together and use that for the automation.

3ative commented 1 year ago

Yep, I get what you're trying to do. Please send me your code (minus any passwords etc), I'll take a look at where you're at and try to add the humidity for you.

grssll commented 1 year ago

`My code

substitutions:
  name: "Redia Centre" # Location and Entity Names (Capitals and Spaces Allowed)
  max_temp: "65" # Threshold for MAX Fan Speed and Alarm
  max_humd: "85"

esphome:
  name: "fan-redia-centre"
esp32:
  board: esp32dev
  framework:
    type: arduino

preferences:
  flash_write_interval: 10000s

# Enable logging
logger:
  logs:
    dallas.sensor: none
    number: none
    sensor: none
    light: none
    fan: none
  level: DEBUG

# Enable Home Assistant API
api:

ota:
  password: 

wifi:
  ssid: 
  password:
  # Optional manual IP

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: 
    password: 

captive_portal:

spi:
  mosi_pin: GPIO23
  clk_pin: GPIO18
  miso_pin: GPIO19

display:
  - platform: ili9xxx
    model: TFT 2.4
    cs_pin: GPIO5
    dc_pin: GPIO32
    reset_pin: GPIO33
    rotation: 270
    lambda: |-
      it.printf(0, 20, id(bold), Color(255, 0, 0), " %.1f", id(temp_sensor_1).state);
      it.print(150, 20, id(bold), Color(255, 255, 255), "/");
      it.printf(200, 20, id(bold), Color(0, 0, 255), " %.1f", id(rpm_1).state);
      auto red = Color(255, 0, 0);
        auto green = Color(0, 255, 0);
        auto blue = Color(0, 0, 255);
        auto white = Color(255, 255, 255);

color:
  - id: my_red50
    red: 100%
    green: 3%
    blue: 5%

font:
  # gfonts://family[@weight]
  - file: "gfonts://Roboto"
    id: roboto
    size: 80
  - file:
      type: gfonts
      family: Roboto
      weight: 900
    id: bold
    size: 60

  - file: "gfonts://Oswald"
    id: oswald
    size: 30

animation:
  - file: "fan.gif"
    id: my_animation
    resize: 50x50

# Testing 2 Channel 0-10v I2C DAC GP8403
external_components:
  - source: github://pr#4495
    components: gp8403
    refresh: 1min

i2c:
  - id: bus_a
    sda: 3
    scl: 1
    scan: true
    frequency: 400000Hz
  - id: bus_b
    sda: 21
    scl: 22
    scan: true

# Set voltage of 0-5v or 0-10v 
gp8403:
  i2c_id: bus_b
  id: gp8403_hub
  voltage: 10v
  address: 0x58

number:
  # Slider to set Min Temperature to start fan
  - platform: template
    id: set_temp
    name: $name Set Temp
    optimistic: True
    min_value: 25
    max_value: 65
    initial_value: 25
    step: 1
    restore_value: true # Restore setting between reboots
  - platform: template
    id: set_temp_1
    name: $name Set Temp 1
    optimistic: True
    min_value: 25
    max_value: 65
    initial_value: 25
    step: 1
    restore_value: true # Restore setting between reboots
 - platform: template
    id: set_humidity
    name: $name Set Humd
    optimistic: True
    min_value: 45
    max_value: 85
    initial_value: 45
    step: 1
    restore_value: true # Restore setting between reboots

sensor:
  - platform: ina219
    i2c_id: bus_a
    address: 0x45
    shunt_resistance: 0.01 ohm
    current:
      name: "Roof_fan_current"
    power:
      name: "Roof_fan_power"
    bus_voltage:
      name: "Roof_fan_voltage"
    max_voltage: 32 v
    max_current: 8 amp
    update_interval: 30sec 

  - platform: bme280
    i2c_id: bus_b
    address: 0x76
    humidity:
      name: roof humidity
      id: humid

       # Adjust humid speed(1-100%). Else, turn it off and set the speed to 1
      on_value:
        - lambda: !lambda |
            auto pct = map(x, id(set_humid).state, $max_humid, 1, 85);
            if (pct>1) {
              auto call = id(the_fan).turn_on(); call.set_speed(pct); call.perform();
            } else {
              auto call = id(the_fan).turn_off(); call.set_speed(1); call.perform();
            }

    temperature:
      name: $name Temperature
      id: temp_sensor
      accuracy_decimals: 0
      oversampling: 16x

       # Adjust fan speed(1-100%). Else, turn it off and set the speed to 1
      on_value:
        - lambda: !lambda |
            auto pct = map(x, id(set_temp).state, $max_temp, 1, 100);
            if (pct>1) {
              auto call = id(the_fan).turn_on(); call.set_speed(pct); call.perform();
            } else {
              auto call = id(the_fan).turn_off(); call.set_speed(1); call.perform();
            }

  - platform: bme280
    i2c_id: bus_b
    address: 0x77
    humidity:
      name: roof humidity 1
      id: humid_1
    temperature:
      name: $name Temperature 1
      id: temp_sensor_1
      accuracy_decimals: 0
      oversampling: 16x

       # Adjust fan speed(1-100%). Else, turn it off and set the speed to 1
      on_value:
        - lambda: !lambda |
            auto pct = map(x, id(set_temp_1).state, $max_temp, 1, 100);
            if (pct>1) {
              auto call = id(the_fan_1).turn_on(); call.set_speed(pct); call.perform();
            } else {
              auto call = id(the_fan_1).turn_off(); call.set_speed(1); call.perform();
            }

# Reports RPM by pulse_counter
  - platform: pulse_counter
    pin:
      number: 27
      mode: INPUT_PULLUP
    name: $name RPM
    unit_of_measurement: 'RPM'
    filters:
      - multiply: 0.333
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 10s
  - platform: pulse_counter
    pin:
      number: 26
      mode: INPUT_PULLUP
    name: $name RPM 1
    id: rpm_1
    unit_of_measurement: 'RPM'
    filters:
      - multiply: 0.333
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 10s

switch:
  # Fan power (MOSFET)
  - platform: gpio
    pin: 2
    id: fan_power

fan:
  - platform: speed
    id: the_fan
    output: gp8403_0
    name: $name Fan
    speed_count: 100
    restore_mode: ALWAYS_OFF
  - platform: speed
    id: the_fan_1
    output: gp8403_1
    name: $name Fan 1
    speed_count: 100
    restore_mode: ALWAYS_OFF

light:
  # On-Board LED
  - platform: monochromatic
    id: d4_light
    output: d4_light_pwm
    effects:
      - pulse:
          name: flashfast
          transition_length: 0.0s
          update_interval: 0.04s

  - platform: monochromatic
    name: $name Fan
    output: gp8403_0
    gamma_correct: 1.2
  - platform: monochromatic
    name: $name Fan 1
    output: gp8403_1
    gamma_correct: 1.2

output:    
  - platform: gp8403
    channel: 0
    id: gp8403_0
  - platform: gp8403
    channel: 1
    id: gp8403_1

  - platform: ledc
    id: d4_light_pwm
    pin:
      number: GPIO16
      inverted: true
3ative commented 1 year ago

Looking at your code: line 174: - Calling "id(set_humid).state" but there's no "set_humid" ID

It's unclear why you are using two BME sensors, two fans and two i2c busses yet setting and checking the temperature twice and humidity only once.

grssll commented 1 year ago

Sorry, line 140 should be "humid". This is just the tryout code to work out humidity and temperature combined logic. Esp is in the server rack and two fans in different parts of the house with separate sensors to get more accurate reading.

3ative commented 1 year ago

So with that correction, is it working now?

3ative commented 1 year ago

I've sent you an email with my Discord ID - Let's continue on there.

3ative commented 1 year ago

Help continued directly on Discord