home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.79k stars 30.04k forks source link

trigger based template throws config error on top key triggerS: #126814

Open Mariusthvdb opened 1 day ago

Mariusthvdb commented 1 day ago

The problem

as title, documentation mentions

# Example configuration entry
template:
  - triggers:
      - trigger: time_pattern
        # This will update every night
        hours: 0
        minutes: 0
    sensor:
      # Keep track how many days have past since a date
      - name: "Not smoking"
        state: '{{ ( ( as_timestamp(now()) - as_timestamp(strptime("06.07.2018", "%d.%m.%Y")) ) / 86400 ) | round(default=0) }}'
        unit_of_measurement: "Days"

but the top triggers key throws an error

took it all back to

template:

  - trigger: # <----- had this set to triggers first but errors
      - trigger: time_pattern
        hours: '/3'
#       - trigger: homeassistant
#         event: start
      - trigger: event
        event_type: event_template_reloaded

for now, and config checker seems ok.

What version of Home Assistant Core has the issue?

2024.10.0b0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

template

Link to integration documentation on our website

https://rc.home-assistant.io/integrations/template/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-09-26 11:37:24.381 ERROR (MainThread) [homeassistant.config] Invalid config for 'template' at packages/package_weer.yaml, line 465: 'triggers' is an invalid option for 'template', check: triggers

Additional information

No response

home-assistant[bot] commented 1 day ago

Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `template` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign template` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


template documentation template source (message by IssueLinks)

frenck commented 1 day ago

This is my bad; I shouldn't have updated that particular example in the documentation.

Will fix the docs 👍

../Frenck

Mariusthvdb commented 1 day ago

ok, so you can confirm that we should be using this now, after changing platform: state to trigger: state


template:

  - trigger:
      - trigger: state
      - 
Petro31 commented 1 day ago

ok, so you can confirm that we should be using this now, after changing platform: state to trigger: state

template:

  - trigger:
      - trigger: state
      - 

Templates were not updated to support the word triggers in it's configuration. The only change was that individual triggers, you replace the word platform with trigger.

I.e. Integration agnostic change was

- platform: state
  ....

to

- trigger: state
  ...

It does not matter where you put the trigger as long as the field you're putting it in accepts triggers. In your case, you're putting it in the trigger field for template entities.