I would like to create a new sensor called garage_counts that counts the number of time my garage door opens and closes.
I already have a template sensor with an entiy id of sensor.garage_door_state
and I would like to count the total of times it goes from open to close.
The entiy_id: sensor.garage_door_state, shows open when it is open and closed when it is closed.
So if the sensor.garage_door_state changes from open to closed the garage_counts sensor would index up by 1.
So the first time the garage door opens and closes the garage_counts sensor would equal 1, the next
time it would equal 2 . Thanks for any help
Try this History Stats sensor. It will automatically reset its count at midnight.
sensor:
- platform: history_stats
name: Garage Door Openings
entity_id: sensor.garage_door_state
state: 'open'
type: count
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
1 Like
Thanks 123 Taras
what if I don’t want it to reset at midnight, I just want it to keep counting
Use a counter, and an automation that increments the counter every time the garage door state changes to open.
1 Like
In that case, use mf_social’s solution (an automation that triggers when the door opens and then increments a counter entity).
1 Like
mf_social and 123 Taras thank you
1 Like
Or use the history_stats with:
start: "{{ 0 }}"
end: "{{ now() }}"
2 Likes