I’ve read the documentation at Template - Home Assistant and various threads in this forum but am struggling to get this working.
In my config.yaml I have “template: !include template.yaml”
In the template.yaml I have some working template sensors but I cannot translate the example in the documentaion into my file.
#EMS-ESP Working Hours
sensor:
- name: 'System Uptime (hr)'
unit_of_measurement: 'hr'
icon: 'mdi:clock-check-outline'
state: >
{% set mins = states('sensor.system_uptime_sec') %}
{% set hours = ((mins | int / 3600) | string).split('.')[0] %}
{{hours}}
# Total Electricity Yesterday
trigger:
- platform: time_pattern
hours: 23
minutes: 59
sensor:
- name: 'Smart Meter Electricity Energy Yesterday'
unit_of_measurement: "kWh"
state: {{states('sensor.smart_meter_electricity_import_today_new')|float(3)}}
#EMS-ESP Working Hours
- sensor:
- name: 'System Uptime (hr)'
unit_of_measurement: 'hr'
icon: 'mdi:clock-check-outline'
state: >
{% set mins = states('sensor.system_uptime_sec') %}
{% set hours = ((mins | int / 3600) | string).split('.')[0] %}
{{hours}}
# Total Electricity Yesterday
- trigger:
- platform: time_pattern
hours: 23
minutes: 59
sensor:
- name: 'Smart Meter Electricity Energy Yesterday'
unit_of_measurement: "kWh"
state: {{states('sensor.smart_meter_electricity_import_today_new')|float(3)}}
Template wants an array of items. For each item you can define a trigger and then sensors, binary sensors, selects, etc. that have their state set from that trigger. Or omit trigger for a item if you just want a bunch of sensors, binary sensors, selects, etc. that are set whenever anything in their template changes.
Thanks. I can see I missed the very first hyphen before ‘sensor:’
I actually had 17 sensors with templates that I had moved from sensor.yaml and it passed all checks and was running perfectly until I tried to add to add the ‘trigger’.
I will add in the hyphen and re-indent everything. Once it works I have a bunch of midnight events in automations that will be joining my ‘electricity yesterday’ .