Writing energy data into Influxdb does not work as planned

Hi, I have the problem that the data of the sensors that I have “included” in configuration.yaml somehow appear wildly sporadically in the Influxdb. I actually only need a value of the sensor at 23:59. As far as I understand, the value is automatically written to the Influxdb when it changes. I have data written into Influxdb ascending throughout the day at various times, but not after about 10 pm. How can I tell Homeassistant to write a sensor to Influxdb at 23:59:00? As i switched from Openhab, this point was extremely easy there. There must be a solution for this here too. This action: “Home Assistant Core Integration: Update entity from gas consumption today” unfortunately does not work either. At least this does not trigger the data to be written to influxdb.
Thankfull for any ideas.

Thank you and best regards
Michael

Take the sensor out of include and create a trigger based template sensor. Use that for influx.

# Example configuration entry
template:
  - triggers:
      - trigger: time_pattern
        hours: 23
        minutes: 59
    sensor:
      - name: "Daily gas"
        state: '{{ states('sensor.original_gas_senor') }}'
        unit_of_measurement: "add measurement here"

Thanks for the reply.
I really dont understand how to create a trigger base template sensor.
Adding your code to my template.yaml throws errors.
Using the UI i dont really know what to fill in.
Could you please explain it in more detail?
Thnx
Michael

What I posted is intended for configuration.yaml. When the entry is placed in a separate file outside, template.yaml, you do not use the top key template:

  - triggers:
      - trigger: time_pattern
        hours: 23
        minutes: 59
    sensor:
      - name: "Daily gas"
        state: '{{ states('sensor.original_gas_senor') }}'
        unit_of_measurement: "add measurement here"

Hi,
tried it in the template.yaml. Still throws an error:
“bad indentation of a mapping entry (136:28)”

Same kind of error in the configuration.yaml
Seemes to be in this line: ```
state: ‘{{ states(‘sensor.original_gas_senor’) }}’

sensor.original_gas_senor is a place holder. Change it to the sensor that provides the gas measurement.