[Announce] node-red-contrib-esphome

Hello,
I’d like to introduce

This is Alpha release, support Native API Component — ESPHome

there is no support for bt proxy and encryption, if possible, test the node

Interesting. What configuration do you need on the ESPhome side?

I use MQTT throughout since that is easy with ESPhome. Sensor data goes to a standardised topic structure. Inputs generally use existing topics because I've not actually implemented any external controls as yet. If I did, I would choose a standardised topic structure aligned to the output structure.

the ESPhome protocol supports the announcement of the services that are in the equipment, you see, for example, all the operating modes of the air conditioner ( supportedFanModesList, supportedCustomPresetsList) as far as I know, mqtt and mqtt discovery (HA MQTT discovery ) does not announce this

well, the main idea is to communicate directly with esphome

Ah, the native api thing, I see. I've skipped over that before because I don't use Home Assistant.

Not sure all of their listed advantages over MQTT stack up.

Efficiency isn't an issue unless you need ms level responses or are sending crazy amounts of messages (in the hundreds of thousands at least).

"One less single point of failure" - you could equally argue that you now have N points of failure where N is the number of ESP devices :slight_smile:. You now have to monitor multiple devices for failure. With MQTT, while the broker going down stops all comms, a device going down is automatically registered on MQTT through the use of the Last Will and Testament feature. With a sensibly chosen topic structure, a single, simple flow in Node-RED can monitor and alert on all devices.

"Stability" - never had any problems with ESP device stability since I moved to ESPhome! Nor with MQTT stability.

I think MQTT discovery is an HA thing only? MQTT doesn't have native discovery and this could indeed be useful when handling dozens to thousands of devices. Thankfully, not something I need to do - I have around 5 or 6 :rofl:


Sorry, not trying to undermine what you are doing, it is a great addition. Just trying to get my head around the different ways of working.

2 Likes

Off topic from this post, but @TotallyInformation I am intrigued about your (home?) automation solution. If you don't use HA, what do you have for controling/measuring or centralization of you devices? Do you have a post about it?
Just to know :slight_smile:
Thanks
Jav

@TotallyInformation here is a use case.

I am a farmer that used Node-RED and ESPHome to finesse our boreholes to find the sweet spot where you can pump from a borehole without it running dry during a brutal five year drought. Using flow sensors (and again, mostly Node-RED), it also detects air in the pipe and shuts down a pump to save it from burning out (they don't like sucking air).

Using this tech, I found 40,000 litres of water a day that I didn't have before. For context, I need about 5 times that. So when it's the choice between dust and 40,000 litres, I'll take the water, thanks.

I also helped a bunch of other farmers do the same thing. It was massively impactful.

Home Assistant only needs to be there to deliver ESPHome to Node-RED.

Then for reasons I won't get into here, HA becomes a threat actor (ie not safe to run on home network). I would say it isn't to most users, but to people with my background, it represents a threat, because we don't live where you do, and the landscape is real different out here. I shouldn't have to tell you why my consent statement is No; it just is.

So then I realised that, OK, it's actually only ESPHome that's useful, and since most of the people I've helped share the same specific experience that makes HA a threat actor, I have to look at ways of removing HA from the equation.

This here node-RED-contrib-esphome thingy will be life changing.

Thank you, thank you, thank you @twocolors for your work on this. You have no idea how many lives this will affect.

1 Like

I just did a quick ESPHome test on an ESP8266 NodeMcu, with an i2c HDC1080 (temperature and humidity sensor) connected.
I can clearly see my sensors in the Web_Server:

Now, I would like to display my sensors in NR with node-red-contrib-esphome but I cannot connect to it:
image

image
there is nothing in the drop-down list

My question @twocolors : is Home Assistant required for node-red-contrib-esphome to work in NR ? Because I don't use it like @TotallyInformation .
Otherwise, what should I add to my .yaml Configuration for the link to work ?
(otherwise I will switch to MQTT...)

Can't really help as I don't use HA. But I can say that ESPHome can simply output to MQTT and that's how I use it.

I don't want to use HA either. So I found this node-red-contrib-esphome interesting to directly link ESPHome and NR without any other addition.
Because in the documentation it is not clearly said: "with or without HA", I was hoping that my .yaml was missing some lines to work.
I wanted to do an easy "plug and play" test... but if i have to install HA for it to work, I'll let it pass (even if the MQTT option was interesting :wink: ).

There is no need to use the esphome contrib node or HA, just use MQTT directly.

3 Likes

As both I and Colin have said, you can simply output and input to/from MQTT direct from ESPHome. That is how I use it.

I split my ESPHome config into separate YAML files because much of my config uses the same settings and sensors. Here is the MQTT YAML I use in all my ESP's.

# Configuration for the MQTT Broker.
# NB: This configuration does not use Home Assistant (HA). It uses TotallyInformation's standard MQTT Schema for ESP devices.
#
# The configuration variables must be set in the master YAML file.

mqtt: # Home MQTT Broker

  broker: $mqtt_broker 
  username: $mqtt_username
  password: $mqtt_password
  topic_prefix: $mqtt_prefix
  id: mqtt_client

  log_topic: # no log to MQTT, it isn't needed and isn't that useful unless you subscribe something to it.

  birth_message:
    topic: $mqtt_prefix
    payload: Online
    retain: true

  will_message:
    topic: $mqtt_prefix
    payload: Offline
    retain: true

  shutdown_message:
    topic: $mqtt_prefix
    payload: Shutdown
    retain: true

  discovery: false # No HA discovery, we aren't using HA

#--- End of mqtt ---#

And here is a typical master YAML file for a specific device

# D1 Mini Configuration for D1M05 (D1 Mini)

# Pins (=GPIO)| Input? | Output? | Comments
  # D0 = 16   | Y      | Y       | High @ boot, Wake, I/P: No Interrupt, O/P: No PWM or I2C
  # D1 = 5    | Y      | Y       | I2C SCL
  # D2 = 4    | Y      | Y       | I2C SDA
  # D3 = 0    | Y      | Y       | 
  # D4 = 2    | Y      | Y       | Onboard LED
  # D5 = 14   | Y      | Y       | 
  # D6 = 12   | Y      | Y       | 
  # D7 = 13   | Y      | Y       | 
  # D8 = 15   | Y      | Y       | 
  # RX = 3    | Y      | Y       | 
  # TX = 1    |        | Y       | 
  # A0 = ADC0 | Y      |         | 

substitutions: # All have to be strings, the substitution process will convert them to the correct types
  devicename: d1m02
  upper_devicename: D1M02
  device_location: Rear Hall
  device_description: Rear Hall custom sensor platform using ESPhome firmware
  ipaddress: 192.168.1.152
  mqtt_prefix: ESP/D1M02 #$mqtt_root/$devicename # Argh! combined substitutions don't work!
  esp_board: d1_mini
  last_update: '"2022-12-12 10:47:12"'
  
  mqtt_root: ESP
  mqtt_broker: !secret mqtt_broker 
  mqtt_username: !secret mqtt_username
  mqtt_password: !secret mqtt_password
  
  wifi_power_save_mode: light # none (default for esp8266), light (default for esp32), high
  wifi_fast_connect: "true"
  wifi_ssid: !secret WiFi_SSID
  wifi_password: !secret WiFi_password
  wifi_domain: !secret WiFi_domain
  wifi_gateway: !secret WiFi_gateway
  wifi_subnet: !secret WiFi_subnet
  wifi_dns1: !secret WiFi_DNS1
  wifi_ap_password: !secret WiFi_AP_Password

  web_auth_username: !secret Web_Auth_Username
  web_auth_password: !secret Web_Auth_Password

  publish_interval: 50s
  log_level: info # none, error, warn, info, debug, verbose
  #esp_platform: ESP8266
  
  sun_latitude: !secret sun_latitude
  sun_longitude: !secret sun_longitude 
# --- End of substitutions: --- #  
  
<<: !include includes/mqtt.yaml # For some reason, the config checker doesn't like this as a package
packages: # These allow merging whereas global includes do not
  common: !include includes/common.yaml
  logger: !include includes/logger.yaml
  wifi: !include includes/wifi.yaml
  common_sensors: !include includes/common-sensors.yaml # Includes number, text and binary
  common_switches: !include includes/common-switches.yaml
  common_intervals: !include includes/common-intervals.yaml
# --- End of packages: --- #

# Basic configuration for ESP8266 based boards. https://esphome.io/components/esp8266.html
# Board names: https://registry.platformio.org/platforms/platformio/espressif8266/boards
esp8266:
  board: $esp_board

status_led:
  pin: 
    number: D4 # GPIO-2
    inverted: true

i2c: # https://esphome.io/components/i2c.html#i2c
  frequency: 400000.0 # default 50000.0, can be up to 800k - try 400k on a d1 mini?

sensor: # NB: See also common_sensors

  # Temperature & Humidity
  #- <<: !include includes/sensors/th_dht.yaml
  # DHT based Temperature+Humidity Sensors - https://esphome.io/components/sensor/dht.html
  - platform: dht
    pin: D5
    model: AM2302
    temperature:
      name: "Temperature"
      id: temperature
      state_topic: $mqtt_prefix/DHT22/Temperature
    humidity:
      name: "Humidity"
      id: humidity
      state_topic: $mqtt_prefix/DHT22/Humidity
      accuracy_decimals: 1
      # filters:
      # - offset: 4.2
  
  # Ambient light intensity
  - <<: !include includes/sensors/light_bh1750.yaml

binary_sensor:
  - platform: gpio # 1-wire sound sensor
    pin: D3
    name: "Sound"
    id: sound
    state_topic: $mqtt_prefix/Sound/Sound

text_sensor:
  - platform: template # Template text sensor wifi channel
    id: wifi_channel
    lambda: |-
      // --- ESP8266 version ---
      std::string out;
      char buffer[64];
      sprintf(buffer, "%u", wifi_get_channel());
      out.append(buffer);
      return out;
      // --- ESP32 version ---
      //wifi_ap_record_t wifidata;
      //esp_wifi_sta_get_ap_info(&wifidata);
      //std::string out;
      //if (wifidata.primary != 0) {
        //char buffer[64];
        //sprintf(buffer, "%u", wifidata.primary);
        //out.append(buffer);
      //}
      //return out;
#EOF
1 Like

thank you, I'm saving for my next test :+1:

you must enable Native API Component — ESPHome for use this node

1 Like

I think that really should be in the readme (and pretty much the first, largest, boldest item in there)

Is it mention in the built-in help?

1 Like

ok, so I add the line api:in my .yaml config :

# interface web
web_server:
 port: 80  

ota:
api:

should I also install: $ pip3 install aioesphomeapi ?

image

because I still can't connect to my ESP32 ESPHome :

First trial worked fine for me

  • adding api: to -yaml and re-flashed the ESP device (Wemos C3 mini)
  • installed node-red-contrib-esphome

Device was found at first trial. (Both my RPi 4 running Node-RED and the Wemos devices are on the same network)

Hi Walter,
image

that's what I did but I don't understand why my device is "Disabled" :
image

the log of my espHome tells me "No client connected to API. Rebooting...":

19:23:00	[D]	[sensor:093]	'WiFi Signal Sensor': Sending state -39.00000 dBm with 0 decimals of accuracy
19:23:10	[D]	[sensor:093]	'HDC1080 Temperature': Sending state 19.04510 °C with 1 decimals of accuracy
19:23:10	[D]	[sensor:093]	'HDC1080 Humidity': Sending state 67.84058 % with 0 decimals of accuracy
19:23:10	[D]	[hdc1080:069]	Got temperature=19.0°C humidity=67.8%
19:23:20	[E]	[api:128]	No client connected to API. Rebooting...
19:25:07	[D]	[sensor:093]	'HDC1080 Temperature': Sending state 19.02496 °C with 1 decimals of accuracy

A connection is interrupted somewhere !? Does yours say “Disabled” too? Or something else ?

Hello SuperNinja, nice to see you again!

In my setup it looks ok. It worked right away when I tried it, only thing I did first was adding the api: to the .yaml and reflashed the device. Could it be something else in the .yaml configuration that is missing or so? I can show mine, just need to strip out some passwords etc from public audience :wink:


1 Like

Naughty, naughty! That's what the secrets file is for. :grinning:

1 Like
esphome:
  name: dfrc3mini
  platform: ESP32
  board: lolin_c3_mini

wifi:
  networks:
  - ssid: ""
    password: ""
    priority: 5
  - ssid: ""
    password: ""

  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.0.211
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.0.1
    dns1: 192.168.0.1

    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

#  fast_connect: true
  power_save_mode: NONE
  reboot_timeout: 5min
  output_power: 20

#captive_portal:

api:

# Enable logging
logger:
  level: DEBUG

ota:

# Example configuration entry
web_server:
  port: 80
  version: 1
#  local: true

mqtt:
  broker: 192.168.0.233
  keepalive: 30s
  reboot_timeout: 5min 
  birth_message:
    topic: dfrc3mini/newborn
    payload: online
  on_message:
   - topic: dfrc3mini/ask
     then:
       - if:
           condition:
             lambda: 'return x == "ask";'
           then:
             - mqtt.publish:
                 topic: dfrc3mini/response
                 payload: "Something happened!"
       - if:
           condition:
             lambda: 'return x == "restart";'
           then:
             - mqtt.publish:
                 topic: dfrc3mini/response
                 payload: "Booting the dfrc3mini Illuminance sensor!"
             - switch.turn_on: blrestart

sensor:
  - platform: adc
    pin: 3
    name: "dfrc3mini Illuminance"
    update_interval: 60s
    attenuation: auto
    filters:
      - lambda: |-
          return (x);
    on_value:
      then:
        - light.turn_on:
            id: myC3MiniBt_led
            brightness: 20%
            red: 10%
            green: 10%
            blue: 100%
        - delay: 1 sec  # timer length
        - light.turn_off: myC3MiniBt_led

switch:
  - platform: restart
    name: "blrestart"
    id: "blrestart"

light:
  - platform: neopixelbus
    id: "myC3MiniBt_led"
    type: GRB
    variant: WS2812
    method: ESP32_RMT_1
    num_leds: 1
    pin: GPIO7
    name: "myC3MiniBt_led"