Hello
I tried to do a research about my issue but couldn’t find any solution, I already checked the documentation about conditions but seems like something is wrong from my side.
I have a template sensor of the count of my lights and wall switches.
I show an entity chip in my dashboard of the count of lights I have and the lights with status on
, same for wall switches, but I want to show the chip only when there is a light on, if all off then no need to show the chip.
Sensor template:
- name: Counts
unique_id: counts
state: >
{{ 0 }}
attributes:
lights: >
{{
states.light
| rejectattr('state', 'in', '(unknown|unavailable)')
| list
| count
}}
lights_on: >
{{
states.light
| rejectattr('state', 'in', '(unknown|unavailable|off)')
| list
| count
}}
lights_down: >
{{
states.light
| selectattr('state', 'in', '(unknown|unavailable)')
| list
| count
}}
wall_switches: >
{{
states.switch
| selectattr('attributes.device_class', 'eq', 'switch')
| rejectattr('state', 'in', '(unknown|unavailable)')
| list
| count
}}
wall_switches_on: >
{{
states.switch
| selectattr('attributes.device_class', 'eq', 'switch')
| rejectattr('state', 'in', '(unknown|unavailable|off)')
| list
| count
}}
wall_switches_down: >
{{
states.switch
| selectattr('attributes.device_class', 'eq', 'switch')
| selectattr('state', 'in', '(unknown|unavailable)')
| list
| count
}}
Chip YAML:
type: custom:mushroom-template-badge
entity: sensor.counts
content: >-
{{ state_attr('sensor.counts', 'lights_on') }} of {{
state_attr('sensor.counts', 'lights') }}
icon: |-
{% if (state_attr('sensor.counts', 'lights_on') | int == 0) %}
mdi:lightbulb-group-off
{% else %}
mdi:lightbulb-group
{% endif %}
color: |-
{% if (state_attr('sensor.counts', 'lights_on') | int == 0) %}
disabled
{% else %}
orange
{% endif %}
tap_action:
action: navigate
navigation_path: /lovelace/entities#wall-switch
visibility:
- condition: template
value_template: "{{ state_attr('sensor.counts', 'lights_on') > 0 }}"
for some reason, this condition does not work, I already found this in the HomeAssistant documentation here but didn’t work for me.
I tried with multiple ways I swear and I couldn’t make it work.
I appretiate your help, thanks.
EDIT:
Found the solution by doing this:
visibility:
- condition: numeric_state
entity: sensor.counts
attribure: lights_on
above: 0