Issue with Invalid config for [sensor]: required key not provided @ data['platform']

Hello,

I’m looking to setup this card.

I have the following code in the top portion of configuration.yaml:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensor.yaml

This references the code in the sensor.yaml (linked earlier), but the critical portion is the top bit, where I think the error is being generated:

template:
  - sensor:
    - name: APF Grid Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (0 - states('sensor.powerwall_site_now')|float(0)*1000)|int(0) }}"

    - name: APF House Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (states('sensor.powerwall_load_now')|float(0)*1000)|int(0) }}"

I have seen a few posts here with a similar error and tried some troubleshooting steps with no results. Currently, when I check my configuration, I see the following error:

Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 15).

I have a brief update. I figure I should list a few of the solutions I tried. I tried to edit the sensor.yaml file to:

- platform: template
  sensors:
    - name: APF Grid Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (0 - states('sensor.powerwall_site_now')|float(0)*1000)|int(0) }}"

This produced a novel error of: Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’]. Got [OrderedDict([(‘name’, ‘APF Grid Entity’)


If you put this into sensor.yaml then that’s the cause of the error message.

template:
  - sensor:
    - name: APF Grid Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (0 - states('sensor.powerwall_site_now')|float(0)*1000)|int(0) }}"

    - name: APF House Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (states('sensor.powerwall_load_now')|float(0)*1000)|int(0) }}"

It belongs in configuration.yaml.


Alternately, if you add this to configuration.yaml

template: !include templates.yaml

then you can put this (note that the first line omits the template: key) into a file named templates.yaml.

  - sensor:
    - name: APF Grid Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (0 - states('sensor.powerwall_site_now')|float(0)*1000)|int(0) }}"

    - name: APF House Entity
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ (states('sensor.powerwall_load_now')|float(0)*1000)|int(0) }}"
1 Like

That did it!

1 Like

This worked for me to invert power consumtion parameter to be able to calculate net consumtion/production.

In the sensors.yaml file.

Replace the sensor to whatever sensor you want to invert.

- platform: template
  sensors: 
    inverted_power:
      unit_of_measurement: W
      value_template: "{{ states('sensor.power_consumtion)|float*(-1) }}"