Hi everyone,
I´m new to Home Assistant and especially programming. I have a very big problem. I want to use the following Soil Moisture Sensor: Soil moisture sensor, moisture detector and plant moisture measuring device with corrosion-resistant probe for automatic irrigation system compatible with Arduino and Raspbery Pi. It´s a sensor you can find in many shops on the internet. But I have no idea what´s the right code for YAML File. I have the following code:
sensor:
- platform: adc
pin: A0
name: "BDF_SP_M.1"
id: moisture_sensor
update_interval: 60s
filters:
- sliding_window_moving_average:
window_size: 15 # Fenstergröße, um die Werte zu glätten
send_every: 15
- platform: template
name: "BDF_SP_M.1 Prozent"
lambda: |-
auto sensor_value = id(moisture_sensor).state;
int dryAnalogValue = 1023;
int wetAnalogValue = 0;
int moistureValuePercent = map(sensor_value, dryAnalogValue, wetAnalogValue, 0, 100);
return moistureValuePercent;
update_interval: 60s
unit_of_measurement: "%"
accuracy_decimals: 0
output:
- platform: gpio
pin: GPIO5
id: led_output
binary_sensor:
- platform: template
name: "Pflanze trocken SP_M.1"
lambda: |-
if (id(moisture_sensor).state == 1023) {
return true;
} else {
return false;
}
on_press:
then:
- output.turn_on: led_output
- logger.log: "SP_M.1 Pflanze ist trocken!!"
on_release:
then:
- output.turn_off: led_output
I got the code from Copilot, because I don´t find anything. The sensor measures all the time 0 V and 100 % Soil Moisture. Obviously that´s wrong. Does anyone has a solution and right code?
I use an NodeMCU V2 and a Raspberry Pi 4 with the sensor. And it´s planned that three sensors are connected with on microcontroller.
I don´t know if I can give any other important information now. I hope that´s enough.
Thanks very much in advance.