Template last day of specific month

I could use some help with the below.

This template writes my monthly energy consumption in sensor.energie_maand every last day of the month (23:59).

template:
  - trigger:
      - platform: template
        value_template: "{{ (now() + timedelta(days=1)).day == 1 and now().strftime("%H:%M") == '23:59' }}" 
    sensor:
      - name: "Maandelijks Energie"
        state: "{{ states('sensor.energie_maand') }}"
        unit_of_measurement: "kWh"
        device_class: energy

Now I don’t need this anymore.

That’s why I would like to “rebuild” the template for logging in a specific month.
I would like to log energy consumption in sensor.energie_maand every last day of September (23:59)

(I use it only for one month in a year)

Who can help me with this and change the template for a specific mont (September) in a year?

Thanks,
Henk

did you try the strftime option?
e.g.

{{ now().strftime("%m-%d") == "11-26" }}

returns: true (for today 26 Nov)

What a good idea.
I changed it slightly. It has been tested and it works.

{{ now().strftime("%m-%d-%H:%M") == "11-26-18:45" }}

Thanks,
Henk

I am doing the same thing but as follows:


{{ now().month in [9] and now().day in [1] and now().hour in [0] and now().minute in [0] }}

The only thing with this ‘yearly’ trigger is that with-any-issue… it will not run. So you may want to build in some ‘check’ …although this also makes it more complex…not sure if you’d like that :slight_smile: