Hide Lovelace view based on sensor value

Hi folks,

Is there a way to hide a view based on the value of a sensor in Lovelace? In short, we have rolling electricity blackouts here called load shedding. When load shedding is instituted, I want the view to be visible that shows me the load shedding times, but when there is no load shedding, the view (i.e. the tab) should be hidden.

Essentially, the sensor returns 0 if there is no load shedding, but returns anything from 1 to 8 if there is, so I only want to see the view if there is load shedding.

Any ideas on how to do this?

I use Custom Header to do that based on the status of an input boolean. You can do the same thing based on the status of a sensor.

I use custom header as well. Can you perhaps let me know how you did that with the input boolean?

You have to use a templated condition.

exceptions:
- conditions:
    template: "{{ states('input_boolean.foo') == 'on' }}"
  config:
    show_tabs:
    - a
    - b

You should follow the docs because this setup can get quite complicated.

here is the pertinent part:

custom_header:
.
.
  hide_tabs: >-
    {{ 'Alerts, ' if states.sensor.nws_alerts_are_active.state == "off" and (states.sensor.nws_test_alerts_are_active.state == "off" or states.sensor.nws_test_alerts.state == "unavailable") else '' }}
    {{ 'Debug, ' if states.input_boolean.show_debug_view.state == "off" else '' }}
    {{ 'Smoker' if states.input_boolean.show_smoker_view.state == "off" else '' }}

you should probably change yours to use the “states(‘xxx’)” method instead of the “states.xxx.state” method tho. I just never got around to it.