Using Packages demands a Platform Key

I need help using Packages.
I see an error asking for a “platform key”
The error is “Invalid config for ‘binary_sensor’ at packages/driveway/functionality1.yaml, line 3: required key ‘platform’ not provided
I need help to understand what a “platform key” is and how to use it in a Package.

It would be really helpful if you could post the YAML for functionality1.yaml. There’s a reasonable possibility that you have an indent error, missing closing quote or bracket, or just have the YAML wrong. But nobody can help you without seeing the actual YAML.

2 Likes

Thanks for such a quick response.
I have been working with HA for a few months and decided to organize my stuff using Packages.
I am stuck resolving a bug that is asking for a Key for Platform.
Here is the YAML for my config and the package…

filename: /homeassistant/configuration.yaml

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

homeassistant:
  packages: !include_dir_merge_named packages/

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

    

automation: !include automations.yaml
template: !include_dir_merge_named templates
scene: !include scenes.yaml
script: !include_dir_merge_named scripts
###sensor: !include_dir_merge_named sensors
###binarysenesor: !include_dir_merge_named binarysensors


switch:
  - platform: template
    switches:
      ewelink_virtual_switch:
        turn_on:
          service: switch.turn_on
        turn_off:
          service: switch.turn_off
          

      
      

filename: /homeassistant/packages/driveway/functionality1.yaml


driveway_functionality1:
  binary_sensor:
  - name: Driveway_07_B
    state: "{{is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}"
    
  sensor:
    - name: Driveway_DoorStatus
      state: >
          {% set ms1 = states('binary_sensor.driveway_controller_switch4') %}
          {% set ms2 = states('binary_sensor.driveway_controller_switch3') %}
          {% set status = ms1 ~ ms2 %}
    
          {% if status == "offon" %}        Closed
          {% elif status == "onoff" %}      Open
          {% elif status == "onon" %}       Moving
          {% else %}                        Unknown   ms1: {{ ms1 }} ms2: {{ ms2 }} 
          {% endif %}
       
    - name: Driveway_GateStatus
      state: >
          {% set ms1 = states('switch.driveway_07_ms3') %}
          {% set ms2 = states('switch.driveway_07_ms2') %}
          {% set status = unavailable %}
    
          {% if status == "onoff" %}        Open
          {% elif status == "offon" %}      Closed
          {% elif status == "offoff" %}     Moving
          {% else %}                        Unknown   ms1: {{ ms1 }} ms2: {{ ms2 }} 
          {% endif %}

Thanks in anticipation.
Please feel free to offer me suggestions about i proving my YAML.

Delete

and move everything what was under it 2 spaces to the left.

I believe you are trying to create template sensors.

If so you need to change the first section to this:

template:
  - binary_sensor:
    - name: Driveway_07_B
      state: "{{is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}"
    
  - sensor:
    - name: Driveway_DoorStatus
.
.
1 Like

Thanks Francis. I tried your suggestion with this simplified YAML -

binary_sensor:
  - name: driveway_07_b
    state: "{{is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}"
This caused error:

Setup of package ‘binary_sensor’ failed: Invalid package definition ‘binary_sensor’: expected a dictionary. Package will not be initialized

I also tried suggestion from Regular but was unsuccessful and have responded separately.

Thanks Regular.
I tried your suggestion with simplified YAML:

template:
- binary_sensor:
    - name: driveway_07_b
      state: "{{is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}

This failed with error message:

Configuration warnings
Setup of package 'template' failed: Invalid package definition 'template': expected a dictionary. Package will not be initialized

I also tried other variations without success.

In YAML indentation is absolutely critical to get right. In the last example you provided, the binary sensor line needs to be indented two spaces. I think the lines after that will be fine (since the name line is already indented four spaces from the “root,” which will give it the two space indent from it’s parent when you are done).

Thanks everyone. I have a config that works! I asked ChatGPT for help.
I think there were two problems:

  1. A ‘platform’ key was required.
  2. the entity names needed to be lower case.
    Here is the YAML that worked:
driveway_functionality1:
  binary_sensor:
    - platform: template
      sensors:
        driveway_07_b:
          friendly_name: "Freddy"
          value_template: "{{ on }}"
  sensor:
    - platform: template
      sensors:
        driveway_doorstatus:
          value_template: >
            {% set ms1 = states('binary_sensor.driveway_controller_switch4') %}
            {% set ms1 = states('binary_sensor.driveway_controller_switch4') %}
            {% set status = ms1 ~ ms2 %}
            {% if status == "offon" %}        Closed
            {% elif status == "onoff" %}      Open
            {% elif status == "onon" %}       Moving
            {% else %}                        Unknown   ms1: {{ ms1 }} ms2: {{ ms2 }} 
            {% endif %}
       
        driveway_gatestatus:
          value_template: >
            {% set ms1 = states('switch.driveway_07_ms3') %}
            {% set ms2 = states('switch.driveway_07_ms2') %}
            {% set status = unavailable %}
            {% if status == "onoff" %}        Open
            {% elif status == "offon" %}      Closed
            {% elif status == "offoff" %}     Moving
            {% else %}                        Unknown   ms1: {{ ms1 }} ms2: {{ ms2 }} 
            {% endif %}

My first experience using the Community has been very rerwarding.

Your problem was that the template: key was missing.
You were using the modern format for template (binary) sensors.

ChatGPT now moved you back to the legacy format.

this is what you should have done:

template:
  - binary_sensor:
      - name: Driveway_07_B
        state: "{{is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}"
    
  - sensor:
      - name: Driveway_DoorStatus
        state: >
          {% set ms1 = states('binary_sensor.driveway_controller_switch4') %}
          {% set ms2 = states('binary_sensor.driveway_controller_switch3') %}
          {% set status = ms1 ~ ms2 %}
    
          {% if status == "offon" %}        Closed
          {% elif status == "onoff" %}      Open
          {% elif status == "onon" %}       Moving
          {% else %}                        Unknown   ms1: {{ ms1 }} ms2: {{ ms2 }} 
          {% endif %}
       
      - name: Driveway_GateStatus
        state: >
          {% set ms1 = states('switch.driveway_07_ms3') %}
          {% set ms2 = states('switch.driveway_07_ms2') %}
          {% set status = unavailable %}
    
          {% if status == "onoff" %}        Open
          {% elif status == "offon" %}      Closed
          {% elif status == "offoff" %}     Moving
          {% else %}                        Unknown   ms1: {{ ms1 }} ms2: {{ ms2 }} 
          {% endif %}

BTW, I wouls advice to add a unique_id to each (binary) sensor

I’m really surprised that you didn’t get an error from this:

driveway_functionality1:
.
.

Hi TheFes, Thanks. I tried your suggestion but the result was this error:

Configuration warnings
Setup of package 'template' failed: Invalid package definition 'template': expected a dictionary. Package will not be initialized

I used the following YAML:

template:
  - binary_sensor:
      - name: driveway_07_b1
        state: "{{is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}"

Question: does the YAML need to be different for template created in a Package, rather than in a Template. In my case I am trying to create a Package!
Also; you suggested I should add a unique_id to each sensor. Can you show me syntax I need to do this?

Hi finity, Thanks. You expressed surprise that the “driveway_functionality1:” key did not cause an error. Maybe this requirement is an artifact of the fact that my YAML was for a Package rather than a Script or Template?

1 Like

Feels like you’re flailing around a bit here. ChatGPT is never a good solution to writing HA code.

Exactly as per the docs:

image

you want:

driveway_functionality1:
  template:
    - binary_sensor:
        - name: Driveway_07_B
          state: "{{ is_state_attr('sensor.driveway_07_wifi_connect_count', 'value', 1) }}"

    - sensor:
        - name: Driveway_DoorStatus
          state: 
### and so on 

You don’t need the functionality1 at the end of the package name: that’s just an example.

And @finity, this is a package setup which is why we have the driveway_functionality1: heading.

1 Like

Ah, right, I forgot to include the package name in my config.
I use another include for packages where the package name is taken from the filename

Hi Troon, Thanks. You are correct, I have been flailing about!
I did read the documentation you pointed me to, several times. It did not get into my brain what the first line of the YAML is about. I have now discovered that the key there MUST be unique. If not unique then nothing happens, no error message, no nothing.
Whilst flailing I saw many error messages demanding a “platform” key but I never got to understand the issue.
Thanks for all you help.

None of my packages have package names/headers. How is the packages config different for getting the package name from the header as opposed to the file name?

I’ve never seen that syntax for packages before now.

Depends on how you set the include in your config file.

could you give an example of the difference?

See the packages doc (link in my post above), which covers it well.

1 Like