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’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