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.

Hi,
i did that. This is how my template.yaml looks with the added gas counter:

  - sensors: 
      number_of_lights_on:
        unique_id: sensor.number_of_lights_on
        friendly_name: "Number of Lights On"
        unit_of_measurement: 'on'
        value_template: >
          {% set lights = [
          states.light.FlurGesamt,
          states.light.AZ,
          states.light.licht_wz,
          states.light.Hue_white_and_color_ambiance_2,
          states.light.ch4_switch2,
            ] %}
          {{ lights | selectattr('state','eq','on') | list | count }}    
          
  - triggers:
      - trigger: time_pattern
        hours: 23
        minutes: 59
    sensor:
      - name: "Daily gas"
        state: '{{ states('sensor.gas_taglich') }}'
        unit_of_measurement: "kWh"

Still the same error

Are you using vs code? This error?

This looks like it is an error with vs code’s checker. It’s happened before. It should clear the configuration checker in devtools and load up when restarted.

No, error is in File Editor when adding the code to the.yaml file.

Leave the error in the file editor and go to dev tools. Click on the configuration checker and see if it gives you an error. For me it doesn’t error even though it’s flagged in the editor.

To me it looks like a similar issue shown in the link I posted. Following the suggestion to just ignore the editor, last post in the link. I also posted an issue on github and no one has yet to respond.

I had some time and played around with this a little more. It seems like the plural is the problem - triggers:. Even with multiple triggers it still gives the error. This passes the checker in VS code using the singular - trigger:

  - trigger:
      - trigger: time_pattern
        hours: 23
        minutes: 59
    sensor:
      - name: "Daily gas"
        state: '{{ states('sensor.gas_taglich') }}'
        unit_of_measurement: "kWh"