Need Help for fan control node-red, esphome and HA

Hello,

i try to get a answere about that already, but i think my questions was wrong-
Now i try again. And please understand, im, new and not a professional

What configuration do I have:
I have an HA server with HA, Node-Red and ESPhome and some other apps.

How are my devices connected to HA?
Almost all are connected to HA via an ESP (fan’s , lights, sensors, switches… all connected only over a ESP8266 or ESP32.

Which protocol do I use:
Currently I only use HA-esphome-api.

I would like to:
I now want to create some automations in Node-Red.
The automation card from HA is too confusing for me.

Current problem:
I want to automate a dimmable fan.
It should increase or reduce its speed depending on a room temperature, a set max temp and a set tolerance (i create in HA helpers for that already (max-temp, and tolerance).
However, he may never rotate more than 85% or less than 15%.

I just want to automate it.

I need help with that.
greetings Achim

I’ve done something similar to this but I’ve done it through HA scripts. I also use node red but I think it would be too complex to do it through nodes alone and you’d have to write a script/javascript to do it.

I have 2 scripts for my purpose. My esp32 running esphome controls a stepper motor. This first script sets the value of the steps to set the controller to base on an input percentage. It controls an input_number with a max and min set with the step values. The rotation is reversed and this is why I have negative value for max. It updates the input_number for the second script and send the command to set the new step value on the esp32/esphome. I have node red sending values to this script based on an attached thermister to turn it on, whether I’m watching TV (turn speed down because it is loud) or someone is in the room (turn up when no presence to get max heat output)

alias: Set Fireplace Fan Speed
description: Set fan speed based on input value %
fields:
  percent:
    description: Percent of Fan speed to set. Default state is off.
    example: 25
variables:
  percent: >-
    {{ state_attr('input_number.firefan','min') /
    state_attr('input_number.firefan','max') * 100}}
  target: null
sequence:
  - service: input_number.set_value
    data:
      value: "{{ state_attr('input_number.firefan','max') * percent | int / 100 }}"
    target:
      entity_id: input_number.firefan
  - service: esphome.fireplace_fan_controller_control_stepper
    data:
      target: "{{ state_attr('input_number.firefan','max') * percent  | int / -100 }}"
mode: single

The second script is mapped to physical buttons on the esp32 and verifies that the value being set by the up/down buttons does not go beyond the sent max/min. Which is similar to what I think you want to do. This script then calls the previous script to set the value on the esp32/esphome. You could combine this with the previous script to set your max and min values there.

alias: Fireplace Button Press
description: Physical Button Press on Controller Box
fields:
  direction:
    description: Set the fan speed using physical buttons
    example: up / down
variables:
  direction: up
  percent: "{{ states('sensor.fireplace_fan_status') }}"
  step: 20
  newValue: |-
    {% if direction == 'up' -%}
        {% if percent | int + step <= 100 -%}
          {{ percent | int + step }}
        {%- else -%}
          100
        {%- endif %}
    {%- else -%}
        {% if percent | int - step > step -1 -%}
          {{ percent | int - step }}
        {%- else -%}
          {{ state_attr('input_number.firefan','min') / state_attr('input_number.firefan','max') * 100}}
        {%- endif %}
    {%- endif %}
sequence:
  - service: script.set_fireplace_fan_speed
    data:
      percent: "{{ newValue }}"
mode: single

This is the yaml for esphome

esphome:
  name: "fireplace-fan-controller"
esp32:
  board: esp32dev
  framework:
    type: esp-idf

# Enable logging
logger:
api:
  encryption:
    key: "<redacted>"
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - logger.log: "Fan Adjusted"
        - stepper.set_target:
            id: firefan
            target: !lambda 'return target;'

ota:
  password: "<redacted>"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fireplace-Controller"
    password: "<redacted>"
    
binary_sensor:
  - platform: gpio
    pin:
      number: 27
      mode: INPUT_PULLUP
      inverted: True
    name: FanUp
    filters:
      - delayed_on: 10ms 
    on_press:
      then:
        - logger.log: FanUp Pressed
        - homeassistant.service:
            service: script.fireplace_button_press
            data:
              direction: 'up'
  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLUP
      inverted: True
    name: FanDown
    filters:
      - delayed_on: 10ms 
    on_press:
      then:
        - logger.log: FanDown Pressed
        - homeassistant.service:
            service: script.fireplace_button_press
            data:
              direction: 'down'        
  - platform: gpio
    pin:
      number: 15
      mode: INPUT_PULLUP
      inverted: True
    name: FireThermister
    filters:
      - delayed_on: 100ms
      - delayed_off: 100ms
    on_press:
      then:
        - logger.log: Thermistor On
        - homeassistant.service:
            service: input_boolean.turn_on
            data: 
              entity_id: input_boolean.fireplace_toggle
    on_release:
      then:
        - logger.log: Thermistor On
        - homeassistant.service:
            service: input_boolean.turn_off
            data: 
              entity_id: input_boolean.fireplace_toggle

stepper:
  - platform: uln2003
    id: firefan
    sleep_when_done: true
    pin_a: 26
    pin_b: 25
    pin_c: 33
    pin_d: 32
    max_speed: 500 steps/s

I know it is not exactly what you’re looking for but I hope it helps

1 Like