Creating Packages

Hi Guys, I hope you can point out the stupid mistake(s) in my config. I am trying to move from a conventional config to packages. The error message is:
“Component error: packages - Integration ‘packages’ not found.”
The code that seems to be the problem is:


sensor: !include sensors.yaml


notify: !include notify.yaml

packages: !include_dir_named packages

homeassistant:
  customize: !include customize.yaml

In my original config I did not have the “homeassistant:” and it worked, then I split out the config and seemed to have to have “homeassistant” and indent customize to get it to work.
Now the packages is causing the config issues but not sure where to look for the issue.

This is one of my packages as an example:

automation:

# Turn on lights if someone enters, its dark and lights are off 
  - alias: Lights on when movement detected
    trigger:
      - entity_id: binary_sensor.motion_lounge
        platform: state
        to: 'on'
    condition:
         - condition: numeric_state
           entity_id: sensor.lightlevel_lounge
           below: 9
         - condition: state
           entity_id: light.lounge_group
           state: 'off'
    action:
       - service: homeassistant.turn_on
         entity_id: light.lounge_table
       - delay: '01:00'
       - service: homeassistant.turn_off
         entity_id: light.lounge_table

Many thanks, appreciate your assistance!

1 Like

packages: needs to be under homeassistant:, same height as customize.

Thanks Francisp, I had it that way and got these errors:

 Package security setup failed. Component groups Integration 'groups' not found.
Package security setup failed. Component external_doors Integration 'external_doors' not found.
Package security setup failed. Component motion_detectors Integration 'motion_detectors' not found.
Package security setup failed. Component family Integration 'family' not found.
Package security setup failed. Component mediaplayer Integration 'mediaplayer' not found.
Package water_smoke_gas setup failed. Component nest_smoke Integration 'nest_smoke' not found.
Package water_smoke_gas setup failed. Component nest_co Integration 'nest_co' not found.
Package water_smoke_gas setup failed. Component nest_battery_low Integration 'nest_battery_low' not found.
Invalid config for [speedtestdotnet]: [automation] is an invalid option for [speedtestdotnet]. Check: speedtestdotnet->speedtestdotnet->automation. (See ?, line ?). 

I have seen a number of ‘examples’ where the structure of config is

houseassistant: 
packages !include blah blah 

and the package file has the same arrangement:

houseassistant:
automation: 

Yet this seems to result in a whole load of issues.

There are no components in homeassistant called groups, external_doors, motion_detectors or any of the other components you have tried to include. What exactly are you trying to do so we can help you?

Hi, thanks for your offer to help. I guess I am struggling to format my question properly. I have split my configuration into the following structure.

Configuration.yaml
which then calls my packages, each of which contains all the components Automation, Input_boolean, scenes, scripts, etc.
/packages/lights.yaml for example

Looking at the examples in Home Assistant Docs I replicated their structure but it does not seem to work.

So here are a few of the questions I have:

  1. Why is it my config works if I don’t include “homeassistant:”?
  2. Does each of the package files need “homeassistant:”
  3. What is the hierarchy for components underneath the “homeassistant:”? I believe its indented 2 spaces, which need indented and which don’t?

Hopefully this makes sense.

I’m guessing you have some indentation issues in your packages.

Because HA is likely then ignoring the package files.

No.

ensure that configuration.yaml is like this:

homeassistant:
  name: Home # Name of the location where Home Assistant is running
  latitude: !secret latitude #Location required to calculate the time the sun rises and sets
  longitude: !secret longitude
  elevation: 16 #altitude above sea level in meters
  unit_system: metric
  time_zone: Australia/Perth # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  
  customize: !include customize.yaml # Customization file
  
  packages: !include_dir_named packages # package setup

and the file structure is correct:

image

and then you will need to show us what is in your package yaml files as that is where I suspect you have indentation problems, hence HA thinking you are trying to use components called things like ‘family’

1 Like

Here Is a sample structure from my system : -
configuration.yaml

homeassistant:
  packages: !include_dir_named packages
config:
discovery:
frontend:
  themes: !include_dir_merge_named themes
lovelace:
  mode: yaml
map:
person:
sun:
system_health:
tts:
  - platform: google_translate
zwave:
  usb_path: /dev/ttyACM0
  network_key: !secret ky_zwave

And Then an example package : -

homeassistant:
  customize:
    input_number.in_global_line_volts:
      unit_of_measurement: v
binary_sensor:
  - platform: template
    sensors:
      ## bath fan
      bs_fans_bath_fan:
        value_template: "{{ is_state('switch.fibsw_bthf_sw', 'on') }}"
        friendly_name: Bathroom Fan On
        icon_template: "{{ 'mdi:fan' if is_state('switch.fibsw_bthf_sw', 'on') else 'mdi:fan-off' }}"
input_boolean:
  ib_fans_bth_lght:
    icon: mdi:lightbulb
input_datetime:
  id_fans_on_window_opens:
    name: Permissive Slot On Time
    has_time: true
    icon: mdi:clock-start
input_number:
  in_fans_daily_run_drtn:
    name: Fan Daily Run Duration
    icon: mdi:clock-fast
    min: 2
    max: 30
    mode: box
automation:
  ## all fans run
  - alias: au_fans_run_all_temp
    trigger:
      - platform: state
        entity_id: switch.cooling_switch
    action:
      - service_template: input_boolean.turn_{{ trigger.to_state.state }}
        entity_id: input_boolean.ib_fans_bth_temp, input_boolean.ib_fans_ens_temp, input_boolean.ib_fans_loft_temp
script:
  sc_switch_loft_led_timer:
    alias: Light Loft LED Timer Script
    sequence:
      - delay: "00:{{ states('input_number.in_switch_loft_led_timer') | int }}:00"
      - service: switch.turn_off
        entity_id: switch.fib223_dblrly_loftlight_sw1

Actually this is a Frankenstein hodge-podge from a couple of them to show you typical spacing and inclusions.
You can only have one header per file but you can repeat headers across all the file you have if you need to

4 Likes

Sorry but I think that will just confuse the OP more since you are including the “customize:” section in the package under “homeassistant:”

To the OP just ignore the “homeassistant:” section included in the example package above as it’s not needed.

Once you have your configuration.yaml set up properly and your file structure correct as sparkydave showed you above then this is how your package contents should look from muttley’s example above:

binary_sensor:
  - platform: template
    sensors:
      ## bath fan
      bs_fans_bath_fan:
        value_template: "{{ is_state('switch.fibsw_bthf_sw', 'on') }}"
        friendly_name: Bathroom Fan On
        icon_template: "{{ 'mdi:fan' if is_state('switch.fibsw_bthf_sw', 'on') else 'mdi:fan-off' }}"
input_boolean:
  ib_fans_bth_lght:
    icon: mdi:lightbulb
input_datetime:
  id_fans_on_window_opens:
    name: Permissive Slot On Time
    has_time: true
    icon: mdi:clock-start

etc...

once you get that sorted out then you go more advanced with the other stuff.

I’m a bit confused, I use package homeassistant: headers when I need to customise entities within ‘that’ package. (sort of why packages exist)
It’s a totally valid structure
How is that confusing ?

Just take the structures, expand upon them pasting in your own entities with the example spacings.

homeassistant: is simply used as a header so that you can include other headers normally placed under that header. It’s just a structure.

I guess (he can correct me if I’m wrong) where finity is coming from is that generally the homeassistant: section wouldn’t get used in each package. I know I don’t use it, especially now that most of what is under that section is / can be done via the GUI. It would really only be the customising, where I do see your point to use it.

I didn’t say it wasn’t valid.

The OP is already having trouble figuring out the yaml syntax structure of how packages are supposed to be called from configuration.yaml. In particular how the packages are referenced beneath the homeassistant: section.

Then you add another “homeassistant:” section inside the package itself. Of course a new person who doesn’t even understand the basic package structure being asked to figure out the recursiveness of that example will be confused.

It’s like someone asking how to do algebra and then giving them an example of algebra used in a calculus example. It maybe valid but it’s not really helpful at that stage of learning.

Well it does if you want to include customizations in the package… that’s what I do anyway.

1 Like

…as explained in the two sentences after the one you quoted :wink:

1 Like

Thanks Guys that is awesome advice, I may not reply for a day or two while I absorb what you have said and make changes to my config files. I will get back to you either way though.

I know what you mean,

Yaml seems a bit arbitrary when you start, but there is a given hierarchy which you need to adhere to, or just not use those elements.
You can’t list triggers, without setting the ‘trigger:’ header for example and that has to go under the automation alias (or ‘id:’ if you use the gui) and they have to go under a single ‘automation:’ header etc.

Just copy the spacing and after a while it will become second nature.
It also helps to copy existing (from another package because of the spacing) code and ‘adapt’ that to your needs.
Using vsc is helpful too as you can employ the home assistant add on (which warns of duplicate keys (headers) and the rainbow spacing addon, which helps with spacing.

Thanks Mutt, I have used other configs to help me and most of the errors are usually just silly mistakes either in spacing or typos. I use VScode, but didn’t know about the addon you mention so will take a look at that.

The reason I came on here with the question was vsc was reporting good code, so it must be the hierarchy of documents rather than specific code in the files.

I will spend some time going through my packages with the advice from here and report back. Thanks again for the assistance.

No, it was reporting valid yaml within the context of the files within your config.
The trouble with ‘includes’ (of all types) is that they have to inherit yaml spacing of the calling file.
So “valid yaml” may not actually be valid under the context of that calling file.
As I said, you get used to it and/or just stick to the spacing ‘that works’ for you.

For example, sevice call spacing in automations ‘should’ (maybe/canbe/well it sorta works) be different from script spacing, but as the engine that processes it is the ‘same’ and I can get away with it. I use automation spacing in scripts (or is it the other way round :rofl: ) so that I can cut and paste actions from this script to this automation etc.
I’m just lazy

Yeah I take your point. While it complies with YAML syntax it doesn’t necessarily work when HA consolidates the separate files. Onward and upward!

It makes sense, but what I’m saying is that somewhere in your packages you are declaring components that don’t exist - for example there is no external_doors component, but according to your error message in your ‘security’ package you have external_doors: declared?

If you post one of your packages then we can probably help you out.