Hi, i have a running ultasonic sensor reading in %. but when values goes above then my values set it shows in -% like (-60%) ( in minus)
is their any way to set only when my sonic reading is <=80cm or >=25cm do the filers in percentage
or can we force set all values above above 80cm as 80cm.?
code im working on
sensor:
- platform: ultrasonic
trigger_pin: GPIO5
echo_pin: GPIO4
id: my_sensor
name: "Water-Level %"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 10s
filters:
- lambda: return ((((x100)-25)-(80-25))/(80-25))-100;
- filter_out: nan
code info
- Tank Depth = TD al the way from the cover where the sensor is mounted to the bottom Sensor Value = x this is will stay the same as this is the reading from the sensor Excluded Distance = EX which is the distance I have on top from the sensor which is mounted to the cover to the highest level the water can reach
return ((((x*100)-EX)-(TD-EX))/(TD-EX))*-100
what i want is, if sonic sensor takes reading of values 80+ it should force and set value as 80
say if its reading at 90cm it still should say as 80 cm
can we make somthing like this work?
on_value:
then:
- if:
id(my_sensor).state > 80; // when sonic sensor reading is above 80cm
then:
id(my_sensor).state = 80; // it should force set above 80cm values to 80 cm