Force sensor to send data

Tags: #<Tag:0x00007f32671d9160>

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");
    
}

Is there a reason why you aren’t using the pulse counter component?

I have learnd about this ,so i use this now.
Is it also possible to have a counter that reset every midningt, holding the power consuption for the day in kWh?

  # Example configuration entry
sensor:
  - platform: pulse_counter
    pin: 32
    unit_of_measurement: 'kW'
    name: 'current_power'
    filters:
      - multiply: 0.06