I have quite a few Template sensor entries in my configuration.yaml for various things.
The majority are for monitoring my electricity use from the solar PV set-up. I was hoping to be able to separate these from all the other template sensors for the sake of clarity… but merge them in the main file via !include.
What I tried without success - was to setup
template: !include template-power.yaml
The file template-power.yaml would include something like:
- name: Grid Power TEST
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: "kW"
device_class: power
state: >
{{ ([0, states('sensor.consumption_power') | float(0) -
states('sensor.solar_power') | float ] | max) | round(3)}}
The main configuration.yaml would include something like:
template: !include template-power.yaml
template:
- sensor:
- name: SunTriggerStudy
state_class: measurement
icon: mdi:blind
state: >
{{(state_attr('sun.sun','elevation')) - (atan(2250/(1150/(sin((pi/180)*((state_attr('sun.sun','azimuth')-8.5))))))*(180/pi))}}
and a whole range of unrelated sensor entries. etc etc etc. I got a duplication error (too many “template” entries.
I also tried:
template:
- sensor:
!include template-power.yaml
(and then all the rest of the template sensors)
Is this merge possible or do I need to look at other solutions?