Node_Red Fan set Fan Speed at ESPhome-Device

Hello,
i try to set the fan-speed .
i try a function but the payload what i send is wrong.
i get the error (in Node-Red)

“Call-service error. Service not found.”

when I go to the debug mode of the web interface, I see that speed_level is sent there when I increase the power of the fan.

Is there something wrong with my names in the function code?

Node-Red function Code

if (msg.payload["sensor.temperatur_an_kronendach"] < (msg.payload["input_number.temperatur_min_max"] - msg.payload["input_number.temperatur_toleranz"])){
    msg.payload = {
        "service": "on",
        data:
            { "speed": "50" }
        }   
    return [msg,msg];
}
else if (msg.payload["sensor.temperatur_an_kronendach"] > (msg.payload["input_number.temperatur_min_max"] + msg.payload["input_number.temperatur_toleranz"])) {
    msg.payload = {
        "service": "on",
        data:
            { "speed": "50" }
        }
    return [msg, msg];
}

ESPhome Code

substitutions: 
  devicename: "air-con-service-esp8266"
  upper_devicename: AirController_ESP8266_D1Mini
  device_location: Kueche
  device_description: Anzuchtbox Steuerung platform using ESPhome firmware
  ipaddress: 192.168.2.110
  esp_board: d1_mini
  last_update: "2023-05-06 22:54:12"

esphome:
  name: $devicename
  friendly_name: AirController_ESP8266_D1Min
  platform: ESP8266
  board: d1_mini

web_server:
  port: 80
  auth:
    username: admin
    password: admin

api: # Enable Home Assistant API
  encryption:
    key: !secret ESPHOME_API_KEY

#mqtt:
#  broker: !secret mqtt_broker 
#  username: !secret mqtt_username
#  password: !secret mqtt_password
#  topic_prefix: AnzuchtBox
#  id: mqtt_client

wifi:
  power_save_mode: none # none (default for esp8266), light (default for esp32), high
  ssid: !secret WLAN_ASUS_SSID
  password: !secret WLAN_ASUS_PASSWORD
  manual_ip:
    static_ip: !secret D1MINI-TESTESP8266_IP
    gateway: !secret WLAN_ASUS_GATEWAY_IP
    subnet: !secret WLAN_ASUS_SUBNET
    dns1: !secret WLAN_ASUS_DNS1
    #fast_connect: on
  ap: # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Anzuchtbox Fallback Hotspot"
    password: !secret WIFI_AP_PASSWORD
ota:
  safe_mode: true
  password: !secret HA_OTA_PASSWORD


output:
  - platform: esp8266_pwm
    pin: GPIO16
    inverted: True # 0
    frequency: 1000 Hz
    #channel: 0
    id: fan_output

# Example usage in a light
fan:
  - platform: speed
    output: fan_output
    name: "LTI FAN"
    speed_count: 100
    # name: ${friendly_name} Override Enable
    id: fan_controll_speed # rack_fan_toggle
    on_turn_on:
     - output.set_level:
          id: fan_output
          level: 100% # !lambda |-
            # return id(fan_speed_override).state/100.0;
      # speed: 100%
    
# Enable logging
logger:

Best reagrds
Achim

Your Node-RED function node has a service of on. That’s not a valid service.

Without the entire flow, there’s no way to know how that function node is supposed to talk to the ESPHome device. Sorry, can’t help you further.

Thank you.
i changed now to “turn_on” now i have the connection free.

maybe you can help me there too.
I’m trying to address entities ESPhome & Homeassistant) that I have on the ESPhome device with a call service under Node-Red.

I think I always use the wrong entities or rather the wrong commands in Node-Red.

Example:
I want to turn a fan on/off
that works.
But I also want to change its speed and that doesn’t work

How do I find out where to use the correct data object?

if i send all with the esphomne-webserver page from my device… then works fine…, i can change the speed and the logoutput is that

'LTI FAN' - Sending state:
18:59:30	[D]	[fan:093]	
  State: ON
18:59:30	[D]	[fan:095]	
  Speed: 67

but if i use the speed:
in the node-red function then also
not works

Uh it looks like you’re sending messages from Node-RED to ESPHome? I assume you have the ESPHome device paired up with Home Assistant? If you do, then all you have to do is use the Node-RED “call service” node to directly call your entity’s fan set speed / fan on service, and that’s it. No futzing around with function call nodes.

Again, without the complete flow, I can’t read your computer’s state via osmosis, therefore I can’t help you. Sorry but this is my last message on this thread.

yes, I already have the esp-device in HAOS as a device and also its entity-ID.
And yes, I call the ESP directly.
Isn’t that a good way? do you normally do it differently?
sorry i very new in that system:(

this is how I set it up==>

I created 2 helpers.
1 helper = set the temperature 0-50 °C
2 helpers = set the tolerance to e.g. 3%

This is how I built my flow
4 x HA-Node’s events: state (1x get temperature of the room, 1 x value of the helper max temperature, 1 x value of helper tolerance % and 1 x the state of the fan (fan is connected to the ESP-device, i can switch on/off and over PWM control the speed)

these 4 event: state nodes are connected to join node for collect all incoming data

I set it there as shown in the picture

after the join node comes the function node.
I have a function there
which compares the temperatures taking into account the tolerance

here is my code in function node

if (msg.payload["sensor.temperatur_an_kronendach"] < (msg.payload["input_number.temperatur_min_max"] - msg.payload["input_number.temperatur_toleranz"])){
    msg.payload = {
        "domain": "fan",
            "service": "turn_on",
            "target": {
                "area_id": ["BigBox"],
                "device_id": ["a90693de1094d36dcc8d0d620b6cac82"],
                "entity_id": ["fan.aircontroller_esp8266_d1min_lti_fan"]
            },
            "data": {
                "brightness_pct": 50
            }
    }
    return [msg, msg];
}
else if (msg.payload["sensor.temperatur_an_kronendach"] > (msg.payload["input_number.temperatur_min_max"] + msg.payload["input_number.temperatur_toleranz"])) {
    msg.payload = {
        "domain": "fan",
        "service": "turn_on",
        "target": {
            "area_id": ["BigBox"],
            "device_id": ["a90693de1094d36dcc8d0d620b6cac82"],
            "entity_id": ["fan.aircontroller_esp8266_d1min_lti_fan"]
        },
            "data": {
            "brightness_pct": 88
        }
    }
    return [msg, msg];
}

after the function node, it goes on to the call service node
I set it there as shown in the picture

I think too complicated… i try maybe 20 different things but not find the right way

Oh you’re using MQTT.

I only have experience with ESPHome, sorry. ESPHome is nice — it lets you build fan devices out of ESP devices, no need to Node-RED at all. The thing just shows up as a fan on Home Assistant after you’ve flashed the device and paired it with HA.

I like NR and it definitely has a place here but, why people use it for stuff like this where they way overcomplicate things and add potential failure points that aren’t necessary, it baffles me. Most or maybe all of what they’re trying to do could be done in esphome alone and IMO it would have been far easier than creating entities in esphome, automations in NR and then using HA for the GUI. No wonder they’re confused and struggling.

1 Like

To be fair, I started doing automations and building custom stuff with NR because I found it much easier than doing it in Home Assistant. E.g. variables are trivial in NR, very hard in HA.

But yes, if your stuff is already attached to an ESP-type microcircuit, best do it all directly in ESPHome.