ESPHome: how to read sensor value in automation?


I setup a water pressure device connected to a D1 mini via the A0 pin.
In HA I am able to see values in the range of 0V - 1V but I am not able to see how to read the value from the entity inside an automation.
I also tried to multiply the value by 100 but I don’t see that in the UI.
The yaml used for the device:

  - platform: adc
    pin: A0
    name: "Water Pressure"
    update_interval: 5s
    - lambda: return x * 100;

Any ideas how to do that?


Do you mean an automation in home assistant, or in esphome?

In home assistant

You don’t need a lambda for simple multiplication. After the node is added from the esp page, the node has to be added to the integration page. If you did click on the name of the sketch it will bring up all sensors for that sketch.

      - multiply: 100

For some reason, mine looks different on the Integrations page:


When I click on the device, I see this:

Did I miss anything in the configuration process?


That is the entity that you would use for an automation. If you click on Water Pressure you will get a pop up. There you will see the sensors entity_id that you would use in automations.

Does the sensor change from 1V? What sensor are you using?

I have multiple nodes that’s why it looks different from yours.

There are two problems:

  1. The max value is 1 even after I added the multiply: 100 to the device config.
  2. I cannot read the value in the automation.

The sensor is just a water pressure that emits voltage values 0.5 V- 4.5V based on the actual pressure. The device reading the voltage is D1 mini.

Indentation is important when adding filters, please post what you are using now. Is it an esp32 or 8266? You have to add attenuation to esp32’s.

This is the config:

  name: main-water-pressure
  platform: ESP8266
  board: d1_mini_lite

# Enable logging

# Enable Home Assistant API

  password: "........"

  ssid: "......"
  password: "........"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Main-Water-Pressure"
    password: "......"

  # Set this to the IP of the ESP
    static_ip: x.x.x.x
    gateway: x.x.x.x

  - platform: adc
    pin: A0
    name: "Water Pressure"
    update_interval: 5s
    - multiply: 100

The device is this:


The maximum reading is 1v. The esp8266 max voltage on A0 on the mcu is 1v.

The d1 mini has a voltage divider so if you apply 3.3 v on the board, it measures 1v on the mcu.

I know, I just want to convert it to a scale of 0-100 and then read the value.

Yet you apply up to 4.5 v to it? Can you apply a known voltage and see what you get? Like a 1.5v battery.

No, it doesn’t reach that level. I measured 3.3V when the normal water pressure is applied. When I close the water pipe and rerelease the pressure, the reading is about 0.2V. So the sensor and device are working fine.

The main issue is that I don’t see how to read this value on the entity.
Most of my devices are working with Tasmota, and I have a good experience with that.
I just decided to give ESPHome a try after the latest integration with HA.
Maybe it’s not ready for prime time yet…

1 Like

You jest surely.

What does the HA device look like? In the ui.

This one?

3.3v or anything over will result in the adc sensor returning 1.0v as that is the maximum.

Why the x100 filter is not working I don’t know.

I think the last line is wrongly indented and should be

    - multiply: 100

Thanks for helping out.
Unfortunately, it did not resolve the problem.
I also tested with a lower voltage value and it still shows numbers like: 0.28V

In any case, I don’t mind reading the original value, the main issue is that I can’t access it in the automation for the entity.

Thanks for trying to help.

You can try

  - calibrate_linear:
      - 0.0 -> 0.0
      - 1.0 -> 100.0

What do you mean by can’t access it in an automation? You only need to reference the name of the sensor. It’s most likely sensor.water_pressure.


I finally figured out the issue, which is pretty dumb on my side :slight_smile:
I forgot that I needed to install the esphome device after every configuration change…
So all the solutions now are working, and I’m using multiply.

Thanks everyone for the help!

1 Like