core: Trigger based template error in Package: Component template can not be merged
The problem
building sensors using the new trigger template component, the above error is thrown, even on a single sensor
What is version of Home Assistant Core has the issue?
2021.4.4
What was the last working version of Home Assistant Core?
x
What type of installation are you running?
Home Assistant OS
Integration causing the issue
template
Link to integration documentation on our website
Example YAML snippet
template:
- trigger:
- platform: time
at: '00:00:00'
sensor:
- name: Afzuigkap zolder power daystart
state: >
{{states('sensor.afzuigkap_zolder_actueel')|float}}
unit_of_measurement: W
Anything in the logs that might be useful for us?
021-04-14 17:02:03 ERROR (MainThread) [homeassistant.config] Package package_zwave setup failed. Integration template cannot be merged. Expected a dict. (See /config/packages/package_zwave.yaml:6).
the reference to ;line 6 in the package doesn’t make sense, the component doest get configured there at all. If I take out this little snippet in the package, config checks ok.
as posted here Ive also tried this with a single line template and all fields quoted. Same error is thrown. to be 100% sure, taking this snippet to a single dedicated package with only that as contents yields the same error, albeit with reference to line 0.
edit just found this https://community.home-assistant.io/t/trigger-based-template-sensors-in-configuration-package-not-working/297693/3
is it the fact the config is in a package?
edit2
yes it is, adding all sensors in the configuration.yaml makes the config check ok. Adjusting title to reflect this bug.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 18 (15 by maintainers)
Ok I figured out what’s going on. Within the function it uses for merging things configured in packages into the main config it looks at the component to see whether its schema is a list or a dictionary here: https://github.com/home-assistant/core/blob/dev/homeassistant/config.py#L722
If the component contains
PLATFORM_SCHEMA(likesensordoes) then it assumes the config is a list and merges it as a list. If the component does not containPLATFORM_SCHEMA(templatedoes not) then it looks forCONFIG_SCHEMAand runs it through this logic here to try and figure out if its a dictionary or a list: https://github.com/home-assistant/core/blob/dev/homeassistant/config.py#L627This doesn’t work with
templatethough becauseCONFIG_SCHEMAdoesn’t exist here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/template/__init__.pyInstead the template component passes the pieces to the respective platforms within it. So sensors are validated with
SENSOR_SCHEMAhere and binary sensor are validated withBINARY_SENSOR_SCHEMAhere. Since it didn’t find aCONFIG_SCHEMAit assumes it is a dictionary and returns an exception when it finds a list instead here.So I think this is an issue and should be re-opened. This isn’t a use case that was removed by design, the package loading process has logic in there to handle merging in configs which are dictionaries as well as merging in configs that are lists. The problem is that its not able to identify right now that
templateis a list-based config. So eithertemplateshould be adjusted to present its schema the way the package loading process wants it (using aCONFIG_SCHEMA) or the package loading process should be adjusted to recognize this new situation if this is the way configuration should be going forward.… and so on.
Package files are included in
configuration.yamllike below. All configuration yaml files are in a directorypackages.It would be great if templates could be used in packages.