Sensor vs Sensors, Template sensors and Configuration

Hi Guys, been wracking my brain over this issue and been looking but can’t find answers to my problem. maybe someone can help?

So a while back I added the System monitor code to my confg.yaml file to monitor my system setup,

HA System Monitor

All was working fine.

2 Months ago I installed solar panels and and I had to resort to creating some template sensors that did some calculations I needed.

This was created in a separate file which I called sensors.yaml and I included this in my config.yaml file.

It looks like this:

- platform: template
  sensors:
  
    convert_grid_power:
      unique_id: convert_grid_power
      friendly_name: "Grid Power Watts"
      value_template: "{{ states('sensor.solarnet_power_grid') | float * 1000 | round(2) }}"
      
    convert_power_photovoltaics:
      unique_id: convert_power_photovoltaics
      friendly_name: "Power Photovoltaics W"
      value_template: "{{ states('sensor.solarnet_power_photovoltaics') | float * 1000 | round(2) }}"
      
    convert_solar_day:
      unique_id: convert_solar_day
      friendly_name: "Solar Day W"
      value_template: "{{ states('sensor.symo_advanced_15_0_3_m_1_energy_days') | float * 1000 | round(2) }}"
      
    convert_charge_power:
      unique_id: convert_charge_power
      friendly_name: "Charge Power KW"
      value_template: "{{ (states('sensor.wattpilot_charging_energy') | float / 1000) | round(2) }}"   

    house_daily_load:
      unique_id: house_daily_load
      friendly_name: "House Daily Load"
      value_template: "{{ (states('sensor.daily_energy_import') | float + states('sensor.solarnet_energy_day') | float - states('sensor.convert_daily_energy_export') | float )}}"   

    essential_load:
      unique_id: essential_load
      friendly_name: "Essential Load"
      value_template: "{{ (states('sensor.symo_advanced_15_0_3_m_1_ac_power') | float + states('sensor.convert_grid_power') | float )}}"   
      
    convert_daily_energy_export:
      unique_id: convert_daily_energy_export
      friendly_name: "Daily Energy Export KW"
      value_template: "{{ (states('sensor.daily_energy_export') | float / 1000) | round(2) }}"
      
    house_average_voltage:
      unique_id: house_average_voltage
      friendly_name: "House Average Voltage"
      value_template: "{{ ((states('sensor.smart_meter_ts_65a_3_voltage_phase_1') | float + states('sensor.smart_meter_ts_65a_3_voltage_phase_2') | float + states('sensor.smart_meter_ts_65a_3_voltage_phase_3') | float ) /3) | round(2) }}"
      

Note that line 2 has “sensors” and in my config.yaml I had to include “sensor: !include sensors.yaml”

This of course created a problem as “sensor”" was now duplicated: one with the include and one with the start of the system monitor code:

sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /config
      - type: memory_free

So i removed the system monitor code from the config.yaml file and placed it my sensors.yaml file but again the problem of sensors vs sensor.

I removed the sensor line but still nothing works.

So I am stumped. Any help would appreciated on how i can integrate the system monitor into my sensors file, or any other viable solution that would work.

I think you’re mixing template sensors with sensors derived from an integration, and at the same time mixing legacy and “modern” templates.

If you’re going to use !include in your configuration.yaml you need two lines:

sensor: !include sensors.yaml
template: !include templates.yaml

sensors.yaml (the one for integration sensors) would begin:

  - platform: systemmonitor
    resources:
      - etc. 
      - etc.

…and templates.yaml would begin:

  - sensor:
    - name: "Charge Power KW"
      state: etc. etc.

…but I’m not sure. It’s a bit confusing. :grinning_face_with_smiling_eyes:

Due to the way the !include merges it’s contents into the overall configuration, your sensors.yaml file already has a top-level key sensor so you need to remove that line from the system monitor sensor configuration.

Personally, I find Packages much less annoying and more flexible than the other merge methods.

1 Like

@Didgeridrew @Stiltjack,

Thanks for the responses.

@Didgeridrew the top level keys are different: for my solar sensors its “sensors” while for the system monitor it’s “sensor”. I have been trying that.

@Stiltjack I have tried your template method but it doesn’t work as my solar sensors are sensors and not template sensors.

Splitting up the configuration works like this: the whole contents of the sensors.yaml file will be inserted into the configuration.yaml file at the location where the !include statement is put, so after the line sensor:
This means that the sensor: line has to be left out of sensors.yaml because this is already defined in configuration.yaml
So the contents of the to be included sensors.yaml file has to be exactly the same as when the contents would be in configuration.yaml, including all indentations, with the only exception that the line sensor: has to be left out (or at least commented out with a hash tag #).
It looks like you are missing the base indentations in your sensors.yaml file.
So in configuration.yaml it should be:

#In configuration.yaml
sensor: !include sensors.yaml

And in sensors.yaml it should then be:

# sensor:
  - platform: template
    sensors:
      convert_grid_power:
        unique_id: convert_grid_power
        friendly_name: "Grid Power Watts"
        value_template: "{{ states('sensor.solarnet_power_grid') | float * 1000 | round(2) }}"
      convert_power_photovoltaics:
        unique_id: convert_power_photovoltaics
        friendly_name: "Power Photovoltaics W"
        value_template: "{{ states('sensor.solarnet_power_photovoltaics') | float * 1000 | round(2) }}"
        
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /config
      - type: memory_free

Note the indentations in front of the lines.

1 Like

@thusassistint Thanks for this. I recreated my sensors.yaml file with your suggestion and it seems to have worked. Funny thing is this is what I had tried to to do but I guess my indentations were not correct.