Daily and monthly energy entity - yaml template config problem

Hi all,
I’m sure I’m missing something simple here, but could you please help me understand and correct the following yaml configuration?

I have followed this post and created the yaml below but only the last sensor ‘Energy yesterday - House’ shows in entities. I tried removing the second instance of template and trigger which didn’t change the results.

My version:


template:
  - trigger:
      platform: template
      value_template: "{{ now().hour == 23 and now().minute == 59 and (now() + timedelta(days=1)).strftime(‘%-d’) == 1 }}"
    sensor:
      - name: 'Energy Last Month - Rescue Centre'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.rescue_sdm230_total_energy_t1') | float }}"
    sensor:
      - name: 'Energy Last Month - House'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.house_sdm230_total_energy_t1') | float  }}"

template:
  - trigger:
      platform: template
      value_template: "{{ now().hour == 23 and now().minute == 59 }}"
    sensor:
      - name: 'Energy yesterday - Rescue Centre'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.rescue_sdm230_total_energy_t1') | float  }}"
    sensor:
      - name: 'Energy yesterday - House'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.house_sdm230_total_energy_t1') | float  }}"

Thanks.

Remove the second line containing template:

Thank you Taras. Still same problem, can you see anything else please?

template:
  - trigger:
      platform: template
      value_template: "{{ now().hour == 23 and now().minute == 59 and (now() + timedelta(days=1)).strftime(‘%-d’) == 1 }}"
    sensor:
      - name: 'Energy Last Month - Rescue Centre'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.rescue_sdm230_total_energy_t1') | float }}"
    sensor:
      - name: 'Energy Last Month - House'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.house_sdm230_total_energy_t1') | float  }}"
  - trigger:
      platform: template
      value_template: "{{ now().hour == 23 and now().minute == 59 }}"
    sensor:
      - name: 'Energy yesterday - Rescue Centre'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.rescue_sdm230_total_energy_t1') | float  }}"
    sensor:
      - name: 'Energy yesterday - House'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: "{{ states('sensor.house_sdm230_total_energy_t1') | float  }}"

Try this version:

template:
  - trigger:
      - platform: template
        value_template: >
          {{ now().hour == 23 and now().minute == 59 and (now() + timedelta(days=1)).strftime('%-d') == 1 }}
    sensor:
      - name: 'Energy Last Month - Rescue Centre'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: >
          {{ states('sensor.rescue_sdm230_total_energy_t1') | float(0) }}
      - name: 'Energy Last Month - House'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: >
          {{ states('sensor.house_sdm230_total_energy_t1') | float(0)  }}
  - trigger:
      - platform: template
        value_template: >
          {{ now().hour == 23 and now().minute == 59 }}
    sensor:
      - name: 'Energy yesterday - Rescue Centre'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: >
          {{ states('sensor.rescue_sdm230_total_energy_t1') | float(0)  }}
      - name: 'Energy yesterday - House'
        unit_of_measurement: 'kWh'
        icon: mdi:counter
        state: >
          {{ states('sensor.house_sdm230_total_energy_t1') | float(0)  }}

Ensure you Reload Template Entities after making the changes.

If it fails to create four sensors, check the Log for errors.

Brilliant, that worked. All four sensors show now.

I just have to figure out now how to deduct the last day/month from the new and display the most recent. Ideally I would keep the most recent 5 days in daily amounts to show trend. I did try and use the built in tools but as my meter gives me actual kWh string they didnt show up as selectable sensors.

Thank you so much.

1 Like