Hi everyone.
I am bulding the sensor for level tank.
I use 2 binary sensor to identify High and Low level.
Formula:
Sensor one ON and sensor two ON = Tank High
Sensor one OFF and sensor two ON = Tank Half
Sensor one OFF and sensor two OFF = Tank Low
i need help with this code
- platform: gpio
pin: 34
device_class: moisture
name: "High"
id: high_level
on_state:
if:
condition:
- binary_sensor.is_on: high_level
then:
- switch.turn_off: pump
- switch.turn_off: valve
- platform: gpio
pin: 35
device_class: moisture
name: "Low"
id: low_level
on_state:
if:
condition:
- binary_sensor.is_off: low_level
- binary_sensor.is_off: high_level
then:
- switch.turn_on: pump
- switch.turn_off: valve
- platform: template
sensors:
water_tank_level:
friendly_name: “Water Tank”
entity_id:
- binary_sensor.high_level
- binary_sensor.low_level
value_template: >-
{% set top = states(‘binary_sensor.high_level’) %}
{% set bottom = states(‘binary_sensor.low_level’) %}
{% if top == ‘on’ and bottom == ‘on’ %} Full
{% elif top == ‘off’ and bottom == ‘on’ %} Half
{% elif top == ‘off’ and bottom == ‘off’ %} Low
{% else %} Error
{% endif %}
the logs show
Failed config
binary_sensor.template: [source /config/esphome/esp32.yaml:90]
platform: template
[sensors] is an invalid option for [binary_sensor.template]. Please check the indentation.
sensors:
water_tank_level:
friendly_name: “Water Tank”
entity_id:
- binary_sensor.high_level
- binary_sensor.low_level
value_template: |-
{% set top = states(‘binary_sensor.high_level’) %} {% set bottom = states(‘binary_sensor.low_level’) %} {% if top == ‘on’ and bottom == ‘on’ %} Full {% elif top == ‘off’ and bottom == ‘on’ %} Half {% elif top == ‘off’ and bottom == ‘off’ %} Low {% else %} Error {% endif %}