I am quite new with HA. I would like your help to get a counter implemented in my Lovelace dashboard that shows the number interrupts of an infrared beam in my garden during the night and that can be reset manually through the dashboard.
Current situation: There are two infrared beams installed both at the front and the back of our house. If the beam at the front is interrupted during the night, an HA automation turns on flashing red LED strips for 5 minutes. If the beam at the back is interrupted during the night, an HA automation turns on lights inside the house for 5 minutes.
The HA automations run fine, they are triggered by the infrared switch (trigger: switch.ac_1a3cd52_12 turned on) at the front and a similar trigger for the back. However I do not know how to implement the counters I described and their display in Lovelace. I would much appreciate if someone could provide me with a hint/solution. I am not yet very familiar with templates. Thanks in advance.
I think we could add an second trigger and use that in a jinja expression to return 0 or the current calc depending on what trigger triggered. For that second trigger could use an input boolean, an event (fired from a button press) a time of day. Let me know if you figure it out
Thank you all: @boheme61, @PeteRage, @vingerha. You provided me the lead and all the solution components that allowed me to create the solution:
I created 2 Helpers of type Counter and one of type Button.
I added an action to my 2 existing automations (that switched-on LEDs and lights). These automations are triggered by a physical interrupt of the IR beam at the front and at the back of our house. The actions in the automation now also call the service âCounter: Incrementâ which increments the Counter I created earlier through the Helper. On an entity card in Lovelace I monitor the counter.
In a new Automation I used the Button as State change trigger for performing the service: Counter: Reset for both counters. In the entity card in Lovelace I added the Button for manual reset via the UI of both counters in one go.