Really excited to get your reply!
Getting the idea of whats trying to be achieved.
It turns out “sensor” wasnt needed in the binary_sensor ID as I’ve written a standard template sensor with two outcomes and it worked with “binary_sensor.aeon_labs_dsb45_water_sensor_sensor_4”
So modified the code:
platform: template
sensors:
water_tank_level:
friendly_name: “Water Tank”
icon_template: mdi:cup-water
value_template: >-
{% set top = states(‘binary_sensor.aeon_labs_dsb45_water_sensor_sensor_3’) %}
{% set bottom = states(‘binary_sensor.aeon_labs_dsb45_water_sensor_sensor_4’) %}
{% if top == ‘on’ and bottom == ‘on’} Full
{% elif top == ‘off’ and bottom == ‘on’} Half
{% elif top == ‘off’ and bottom == ‘off’} Low
{% else %} Error
{% endif %}
But I get this error on checking the config:
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’]. Got None. (See ?, line ?). Please check the docs at Template - Home Assistant
Comment the lot out and the config file works again…
Have replied with formatted code and now get a different error message!
Dunno why its different to before as I just pasted in the suggested text again…
This is directly from my configuration file.
- platform: template
sensors:
water_tank_level:
friendly_name: "Water Tank"
value_template: >-
{% set top = states('binary_sensor.aeon_labs_dsb45_water_sensor_sensor_3') %}
{% set bottom = states('binary_sensor.aeon_labs_dsb45_water_sensor_sensor_4') %}
{% if top == 'on' and bottom == 'on'} Full
{% elif top == 'off' and bottom == 'on'} Half
{% elif top == 'off' and bottom == 'off'} Low
{% else %} Error
{% endif %}
But get a new error:
Configuration invalid
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ‘}’) for dictionary value @ data[‘sensors’][‘water_tank_level’][‘value_template’]. Got “{% set top = states(‘binary_sensor.aeon_labs_dsb45_water_sensor_sensor_3’) %} {% set bottom = states(‘binary_sensor.aeon_labs_dsb45_water_sensor_sensor_4’) %} {% if top == ‘on’ and bottom == ‘on’} Full {% elif top == ‘off’ and bottom == ‘on’} Half {% elif top == ‘off’ and bottom == ‘off’} Low {% else %} Error {% endif %}”. (See ?, line ?). Please check the docs at Template - Home Assistant
Look at the revised version of what I posted previously. You’ll see I corrected several syntax errors. It passes Config Check now but while testing it it doesn’t report anything other than Error so I have to track down what silly thing is causing it. May take awhile because I have to step out right now.
Got it. My test version, which uses input_booleans instead of binary_sensors was configured incorrectly. The revised posted version (using your binary_sensors) should work for you.