Hey everyone, I’m diving into the world of smart home automation and I have to say, it’s been a fascinating journey! One of my recent projects has been setting up a counter for the number of times my house gate opens. I thought it would be straightforward, but boy, did I learn a thing or two along the way!
So, here’s the setup: I connected the contact button of my intercom to a relay driven by a NODEMCU running ESPEasy. Via MQTT, I can trigger the contact from Home Assistant. The gate is programmed to open and close automatically after 40 seconds. If the contact closes while the gate is open, it continues to open, and if it’s closing, it reopens. Pretty neat, right?
Now, the challenge was adding a counter to track the number of gate openings. I set up a switch in Home Assistant using MQTT to control the relay:
yaml
- platform: mqtt
name: “ESP-CITOFONO-CARRAIO RESIDENCE”
qos: 1
state_topic: “/ESP-CITOFONO/Switch4”
command_topic: “/ESP-CITOFONO/Switch4/gpio/15/cmd”
payload_on: “Pulse,15,0,500”
payload_off: “Pulse,15,0,500”
And I created a sensor to count the openings:
yaml
- platform: history_stats
name: CARRAIO number
entity_id: switch.esp_citofono_carraio_residence
state: “on”
type: count
start: “{{ 0 }}”
end: “{{ now() }}”
But here’s the kicker: the counter on the web interface wasn’t updating. I scratched my head for a while, thinking I must have missed something. After some digging, I realized I needed to link the switch and the sensor more effectively. It turns out, the sensor wasn’t properly tracking the state changes of the switch. A little tweak later, and voilà! The counter started working like a charm.
This project taught me the importance of understanding how different components interact in a smart home setup. It also highlighted the value of the community—without the tips and tricks shared here, I might still be pulling my hair out!
If anyone has similar projects or tips to share, I’m all ears! Let’s keep the learning and innovation going! ![]()