The volunteers at our local community woodworking shop have built Arduino-based automated blast gates for our dust collection system. The gates publish their state via MQTT. We are successfully monitoring the gate state (open, closed, opening, or closing) using MQTT with Home Assistant.
Now we are attempting to create a template to count the total number of gates open.
I am a novice using HA and YAML. I have found several examples of counts of binary switches. Based on these examples, I created the template below. I always get a count of 0 no matter how many of entities are in an open state.
We use an RPI 4-64 running Home Assistant 2024.2.3 using HassOS image.
Can someone provide me some clues?
Here is the template:
template:
-sensor:
- name: open_gate_count
unique_id: open_gate_count
{% set entities = ['cover.m01', 'cover.m02', 'cover.m00', 'cover.M06', 'cover.m10', 'cover.m11', 'cover.m16', 'cover.m17', 'cover.m26', 'cover.m28', 'cover.m29', 'cover.m30', 'cover.m31', 'cover.m33', 'cover.m34', 'cover.m35', 'cover.m36', 'cover.m38'] %}
{{ entities | selectattr('state','eq',"open") | list | count }}
Here is a sample of the entity configuration files:
mqtt:
cover:
- name: "M01"
unique_id: M01
state_topic: "home-assistant/blastgates/M01/state"
availability:
- topic: "home-assistant/blastgates/M01/availability"
payload_available: "online"
payload_not_available: "offline"
qos: 0
device_class: damper
optimistic: false
- name: "M02"
unique_id: M02
state_topic: "home-assistant/blastgates/M02/state"
availability:
- topic: "home-assistant/blastgates/M02/availability"
payload_available: "online"
payload_not_available: "offline"
qos: 0
device_class: damper
optimistic: false
- name: "M03"
unique_id: M03
state_topic: "home-assistant/blastgates/M03/state"
availability:
- topic: "home-assistant/blastgates/M03/availability"
payload_available: "online"
payload_not_available: "offline"
qos: 0
device_class: damper
optimistic: false