shoei600
(Shoei600)
May 27, 2024, 10:44am
1
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.
Is there any way to run an automation once per month? Looking through the time conditions, there seems to be built-in ways to easily automate weekly. I couldn’t find any way to do the same on a monthly-basis (e.g. on the 1st or 15th).
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.
123
(Taras)
May 27, 2024, 12:42pm
2
Remove the second line containing template:
shoei600
(Shoei600)
May 27, 2024, 1:12pm
3
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 }}"
123
(Taras)
May 27, 2024, 1:21pm
4
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.
shoei600
(Shoei600)
May 27, 2024, 1:46pm
5
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