I use the internal counter in ESP 32 to count pulses during 60 seconds. Then the internal timer reset the counter and starts counting again. By this i can count pulses per minute. The thing is that i need to send the value to the server on the timeout trigger. I know ho do that by the MQTT server . But how do i do that by using home Assistant standard interface, and wath metod do homeassistent use as standard ?
esphome:
name: stuen
platform: ESP32
board: nodemcu-32s
wifi:
ssid: "WiFixxx"
password: "Mypassword"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "ssidHotspot"
password: "V75xxxxxx"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "Luxxxxx"
ota:
password: "Luxxxxxx"
# Example recive pulses from ESP32 trigged by time out counter on ESP32
sensor:
- platform: ???
pin: 2 ??
pulses:
name: "Number of pulses sent from ESP32 "
update_interval: 60s ??
So each time the timerAlarmWrite
fires off i will force the ESP32 to send data to server.
void PulseCounter_setup()
{
// input pin - vstupní pin //
pinMode(pulsePin, INPUT_PULLUP);
PulseCounter_ini();
// set timer and alarm - nastavíme timer a alarm
timer = timerBegin(0, 80, true);
// Attach onTimer function to our timer.
timerAttachInterrupt(timer, &onTimer, true);
// Set alarm to call onTimer function every second (value in microseconds).
// Repeat the alarm (third parameter)
timerAlarmWrite(timer, 60000000, true); // 100000 = 1 second - 60000000 = 1 minute
// Start an alarm
timerAlarmEnable(timer);
Serial.println("PulseCounter_setup - completed");
}