Number of month as part of an entity

I created some input_numbers, where _01, _02, _03… indicate the month number.

input_number:
  piek_afname_01:
    name: Piek afname januari
    min: 0
    max: 10.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"
# also 02,03, ....
  piek_afname_12:
    name: Piek afname december
    min: 0
    max: 10.0
    step: 0.001
    mode: box
    unit_of_measurement: "kWh"

I have an automation

  - alias: Laatste piek
    mode: parallel
    trigger:
      - platform: state
        entity_id: sensor.fluvius_verbruik_energy_kwartier_gemiddelde
    condition:
      - condition: template
        value_template: >
# XX                                                                                                                     vv
          {{  states("sensor.fluvius_verbruik_energy_kwartier_gemiddelde") | float(0) > states("input_number.piek_afname_XX") | float(0)}}
    action:
      - service: input_number.set_value
        target:
          entity_id: input_number.piek_afname
        data:
            value: >
              {{ states("sensor.fluvius_verbruik_energy_kwartier_gemiddelde") | float(0)}}
      - service: input_number.set_value
        target:
          entity_id: 'input_number.piek_afname_{{ (as_timestamp(now()))|timestamp_custom("%m", true) }}'
        data:
          value: >
            {{ states("sensor.fluvius_verbruik_energy_kwartier_gemiddelde") | float(0)}}

The problem is that I don’t know how to write this exactly.
I want to replace XX with the month number like I use it in the second service: input_number.set_value : (as_timestamp(now()))|timestamp_custom("%m", true)
but I’m having problems with putting the symbols (like: {, (, …) in the correct place.

So, how do I write the line after “# XX” correctly ?

Thanks

Hi, working with time and date components depends a lot on what you use as input and how that is loaded… 01 is possibly a string, 1 aa integer, etc.
Having had multiple challenges in the past and on different topics needing different solutions, I found this one most helpful
The EPIC Time Conversion and Manipulation Thread! - Configuration - Home Assistant Community (home-assistant.io)

alias: Laatste piek
mode: parallel
variables:
  maand: '{{ now().strftime("%m") }}'
  gemiddelde: '{{ states("sensor.fluvius_verbruik_energy_kwartier_gemiddelde") | float(0)}}'
trigger:
  - platform: state
    entity_id: sensor.fluvius_verbruik_energy_kwartier_gemiddelde
condition:
  - condition: template
    value_template: >
      {{  gemiddelde > states("input_number.piek_afname_"~maand) | float(0) }}
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.piek_afname
    data:
      value: '{{ gemiddelde }}'
  - service: input_number.set_value
    target:
      entity_id: input_number.piek_afname_{{ maand }}
    data:
      value: '{{ gemiddelde }}'

Thanks, it looks very (c)lean. I’ll see the results in the morning, when my battery has drained :slight_smile:
Peaks are 0 for now…

For lovelace, is there also a way to make the shown entity dynamic ?

cards:
  - type: entities
    title: Consumption
    show_header_toggle: false
    entities:
      - entity: 'input_number.piek_afname_{{ (as_timestamp(now()))|timestamp_custom("%m", true) }}'
        type: custom:multiple-entity-row
        name: Piek huidige maand
        format: precision1

is not working.

I also tried with (with and without single quotes):

      - entity: 'input_number.piek_afname_{{ now().strftime("%m") }}'