IngoNRW
(Ingo)
May 12, 2020, 11:07am
1
Hello i want so set a template (sensor?) to set a value.
Backround are five Switches to measure the fuel level of a water tank.
Here we go
switch 1 off Water Level 0 %
switch 2 on Water Level 25 %
switch 3 on Water Level 50 %
switch 4 on Water Level 75 %
switch 5 on Watter Level 100 %
How can i set the Percent to the Entity sensor.Waterlevel ?
did I need a Lambda ?
Thank for your Help and greetings from Germany
sensor:
- platform: template
sensors:
water_tank_level:
friendly_name: Water tank level
value_template: >
{% if is_state('switch.switch5' , 'on' ) %} 100
{% elif is_state('switch.switch4' , 'on' ) %} 75
{% elif is_state('switch.switch3' , 'on' ) %} 50
{% elif is_state('switch.switch2' , 'on' ) %} 25
{% else %} 0 {% endif %}
unit_of_measurement: "%"
tom_l
May 12, 2020, 11:47am
3
Or you could use a text based sensor (no graphing) for a little more information:
sensor:
- platform: template
sensors:
water_tank_level:
friendly_name: Water tank level
value_template: >
{% if is_state('switch.switch5' , 'on' ) %} 100%
{% elif is_state('switch.switch4' , 'on' ) %} 75-99%
{% elif is_state('switch.switch3' , 'on' ) %} 50-74%
{% elif is_state('switch.switch2' , 'on' ) %} 25-49%
{% elif is_state('switch.switch1' , 'on' ) %} 1-24%
{% else %} 0% {% endif %}
Also what are you doing putting fuel in your water tank?
IngoNRW
(Ingo)
May 12, 2020, 12:47pm
4
Thanks for all sugestions
but whats about the lowest level switch ?
In this example the sensor become state 0 % on real 24 %
Better way ?
sensor:
- platform: template
sensors:
water_tank_level:
friendly_name: Water tank level
value_template: >
{% if is_state('switch.switch5' , 'on' ) %} 100
{% elif is_state('switch.switch4' , 'on' ) %} 75
{% elif is_state('switch.switch3' , 'on' ) %} 50
{% elif is_state('switch.switch2' , 'on' ) %} 25
{% elif is_state('switch.switch1' , 'off' ) %} 0
{% endif %}
unit_of_measurement: "%"
I have two 1000 Litre IBC Tanks in my garden and collect Rain Water
First i measured it with ultrasonic Sensors but there was too unstable
No i try the mechanical way with this reed sensors:
Sorry, that’s because I did a load of awkward phone screen copy and paste and didn’t really think about the logic
tom_l
May 12, 2020, 1:10pm
6
IngoNRW:
Better way ?
No.
What happens when switch 2 turns off leaving only switch 1 on?
Your template has no case for this and generates an error / unknown state.
The correct way to cover this is shown in my example.
Your set up is not good enough for a continuous sensor.
IngoNRW
(Ingo)
May 12, 2020, 1:20pm
7
i agree tom.
In my understanding if every switch has state “off” we reach 0 Percent
Is it true ?
IngoNRW
(Ingo)
May 20, 2020, 5:46am
9
short response
i implemate the script and it works
Thank you for the help