Using packages - what can you include?

I’m trying to transition to packages, and want to know what, exactly, I can include. I understand things like switch: and sensor entries are possible. But how about things like include/exclude lists for records or homekit? If I add another sensor in a package, can I also include it in my homekit component within the package? Exclude it from the recorder, inside the package?

For example, can I have something like this in a package file:

sensor: 
  name: bob
recorder:
  exclude:
    entities: 
    - sensor.bob
homekit:
  filter:
    include_entities:
     - sensor.bob

and have it work correctly? Where these specific inclusions/exclusions will be merged in with other items from other packages to create the fill inclusion/exclusion set?

Thanks!

I could be wrong but I’m pretty sure that everything can be put into a package, even packages and !include’ s.

Try it and see if it works. Worst case scenario you have to put it back the other way.

Have a look at some of the configurations users have uploaded to github, a fair few contain packages that you can browse to get an idea

This one has plenty of examples

1 Like

What are the advantages of using packages?

All I see is one big disadvantage:

Note that if you use packages for your configuration, the configuration reloading buttons in the configuration panel will not reload your packages.

I suppose its everything being in one file for a certain thing, automation, sensors, etc

Plus i dont use the reloading buttons, i use docker so it takes about 20 seconds to restart it anyway.

I don’t use those buttons anyway, so that’s not a downside.

For me, the advantage is that everything related to something will be in one place. For example, everything connected to the living room lighting - PIR sensors, timers, light controls, automations, customizations, etc. If I need to change something, I don’t need to look in 5 different places, it’s all right there.

I love packages because I can group everything for a specific task or item into one yaml file.

For example I have an ensuite_light.yaml which has the code for the light itself (yeelight) plus the automations and scripts associated with that light. I have a kitchen_light.yaml with a similar setup. So when I want to make a change for a particular item in my house, its only a matter of editing one file.
I guess my main (most complex) package is for my retic (irrigation for the non-aussies :wink:) which has almost every domain in HA! (switch, sensor, binary_sensor, input_datetime, input_number, script, automation… you get the idea) If this was not a package I’d have A LOT of different files to play with for one ‘task’.

The reload thing isn’t much of an issue when a full HA restart only takes a minute or so.

Ok. That makes sense. Thanks.

Just an UpDate, Packages are now included when you reload automations and scripts.

Mybe for other integrations too, but I can’t attest

1 Like

Nice topic. Im thing also to change my config to packages.
I want split them up into rooms: Livingroom, Bedroom, etc…
Global stuff like some automations will into global_system.yaml

I think this makes editing much more easier. I have now everything split up in many files

What you can do is simply have folders for each room then yaml files for each item in that room. Eg: I have a yaml file for my kitchen lights which then has all the input_numbers, automations, scripts etc for that entity

1 Like

Can someone tell me what this mean

customize: &customize

see this many times in the packages files of

That’s a yaml anchor. For some reason people tend to dump them at the top of packages even though most of the time they’re not beneficial.

What it does is prevent duplication, so if you’re reusing the same values all the time you just write a reference to them once and then include the reference whenever you want to duplicate the code.

The best example I can give is here…

Basically the turn_off action for the switch is identical to the turn_on, so I anchored the turn_on and replicated it in the turn_off saving several lines of code.

1 Like

Thanks, very nice way solution.
To understand it bit more. When i add a anchor in 1 yaml file, i can use them also in other yaml files to prevent duplicates, or only inside the same yaml file?

Otherwise i create a yaml file where i put all the anchor parts.

And HA is not complaining that it miss a script part while restart? When it load a yaml script without the anchor already loaded, how does it handle that?

Sorry for all the questions, but want to understand it well before change everything :slight_smile:

They only work in the file they’re declared in, so if you think you’re going to have a lot of duplicated code try to formulate your packages around that.

1 Like