Config.yaml structure

Good afternoon,

I have been messing around with some copy and pasting in my yaml and well, things work. However, I feel that there is already some degree of mess in my file when looking at other config files and would like to bring more structure in it. Moreover, I do receive a notification saying

Invalid config for [template]: [platform] is an invalid option for [template]. Check: template->sensor->0->platform. (See /config/configuration.yaml, line 33).

I’ve tried to structure it the way I though it would be right but that took me way deeper in the rabbit hole. Can someone please give me guidance what the right structure would be to make the file more future proof for template sensors and binary sensor?

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
group: !include groups.yaml

    
template:
#Photovoltaik Sensoren für Energy Dashboard
  - sensor:
      - name: "Battery Power Charging"
        unit_of_measurement: W
        device_class: power
        state: "{{ max(0, 0 - states('sensor.solarnet_power_battery') | float(default=0)) }}"
      - name: "Battery Power Discharging"
        unit_of_measurement: W
        device_class: power
        state: "{{ max(0, states('sensor.solarnet_power_battery') | float(default=0)) }}"
      - name: "Power Photovoltaics"
        unit_of_measurement: W
        device_class: power
        state: "{{ states('sensor.solarnet_power_photovoltaics') | float(default=0) }}"
        
  - sensor:
    - platform: integration
      source: sensor.battery_power_charging
      name: "Total Batterie geladen"
      method: left
    - platform: integration
      source: sensor.battery_power_discharging
      name: "Total Batterie entladen"
      method: left
    - platform: integration
      source: sensor.power_photovoltaics
      name: "Total Photovoltaik"
      method: left


binary_sensor:
  - platform: template
    sensors:
      someone_home:
        friendly_name: Someone Home
        icon_template: >-
          {% if is_state('binary_sensor.someone_home','on') %}
            mdi:home-account
          {% else %}
            mdi:home-outline
          {% endif %}
        value_template: "{{ is_state('person.2','home') or  is_state('person.1','home') }}"

Thank you very much in advance!

Not read it myself for a while but I guess its all here somewhere

The problem is that you’ve incorrectly entered the integration sensor definitions under template:

template:
#Photovoltaik Sensoren für Energy Dashboard
  - sensor:
      - name: "Battery Power Charging"
        unit_of_measurement: W
        device_class: power
        state: "{{ max(0, 0 - states('sensor.solarnet_power_battery') | float(default=0)) }}"
      - name: "Battery Power Discharging"
        unit_of_measurement: W
        device_class: power
        state: "{{ max(0, states('sensor.solarnet_power_battery') | float(default=0)) }}"
      - name: "Power Photovoltaics"
        unit_of_measurement: W
        device_class: power
        state: "{{ states('sensor.solarnet_power_photovoltaics') | float(default=0) }}"
        
sensor:
  - platform: integration
    source: sensor.battery_power_charging
    name: "Total Batterie geladen"
    method: left
  - platform: integration
    source: sensor.battery_power_discharging
    name: "Total Batterie entladen"
    method: left
  - platform: integration
    source: sensor.power_photovoltaics
    name: "Total Photovoltaik"
    method: left

(you should also switch the template binary sensor over to the new format)

Hi @Tinkerer,

what would the right format look like? I think I’ll understand how the idea of the structure is when seeing how it’s done the correct way.

I’d like to avoid splitting the config file as suggest by @Arh as I would like to get a basic understanding of things before getting to advanced configurations.

Thank you!

binary_sensor:
  - platform: template
    sensors:
      someone_home:
        friendly_name: Someone Home
        icon_template: >-
          {% if is_state('binary_sensor.someone_home','on') %}
            mdi:home-account
          {% else %}
            mdi:home-outline
          {% endif %}
        value_template: "{{ is_state('person.2','home') or  is_state('person.1','home') }}"

becomes

template:
  - binary_sensor:
      - name: Someone Home
        icon: >-
          {% if is_state('binary_sensor.someone_home','on') %}
            mdi:home-account
          {% else %}
            mdi:home-outline
          {% endif %}
        state: "{{ is_state('person.2','home') or is_state('person.1','home') }}"
1 Like

That’s working, thanks very much! I got the idea now.

I have solved the other error with deleting the sensors from the config and added them as a helper.