Hello, I’m trying to add a trigger template sensor, and I’ve been getting errors which seem to suggest that the syntax has changed, but I can’t find any information about what the correct syntax is. I’d appreciate some assistance, if people don’t mind. This is what I have now (this can either go in configuration.yaml after template:
or in a separate templates.yaml file. I’ve tried both, with the same results):
- trigger:
- platform: state
entity_id: input_datetime.last_upstairs_motion
- platform: time
at: "00:00:00"
sensor:
- name: "Last Upstairs Display"
unique_id: last_upstairs_display
state: >
{% set last = states('input_datetime.last_upstairs') %}
{% set last_dt = strptime(last, '%Y-%m-%d %H:%M:%S') %}
{% set today = now().date() %}
{% set yesterday = (now() - timedelta(days=1)).date() %}
{% if last_dt.date() == today %}
{{ last_dt.strftime('%H:%M') }}
{% elif last_dt.date() == yesterday %}
Yesterday at {{ last_dt.strftime('%H:%M') }}
{% else %}
{{ last_dt.strftime('%d.%m. at %H:%M') }}
{% endif %}
I’m using the Studio Code Server. It gives me the error “String does not match the pattern of “LEGACY_SYNTAX^”” on each of the platform
lines, as well as an the error “String does not match the pattern of “^calendar.(?!)[\da-z]+(?<!_)$”.” on the entity_id
line.
I’ve tried looking at the documentation on home-assistant’s website, but it says to use -triggers
instead of -trigger
, which appears to be simply wrong. That gives me a “Property triggers is not allowed” error.
Could anyone point me in the right direction? I’m feeling lost and frustrated about this, but otherwise, home-assistant has been a great experience. I’m happy to read documentation, if I can find the right thing to read. Thanks.
EDIT: I’m using the latest version of home-assistant.
The key should be template
not templates
.
Sorry, that was a typo. I am using template:
.
Are you getting errors in HA when you reload the Template integration or are these just in Studio Code Server?
What would be the best way to know whether I’m getting an error when it tries to reload? In Studio Code Server, I see a popup in the bottom right corner whose source is Home Assistant Config Helper. Is that an indication that it’s failing to load the change to configuration.yaml, or should I look elsewhere. The error message is actually entirely different from the other ones: “YAMLSyntaxError: All collection items must start in the same column.”
Note that I’ve changed to a much simpler template for testing. Here’s my entire configuration.yaml:
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# template: !include templates.yaml
# template: !include_dir_merge_list templates/
template:
- trigger:
- platform: state
entity_id: input_datetime.last_upstairs_motion
sensor:
- name: "Last Upstairs Display"
unique_id: last_upstairs_display
state: "Whatever"
Thanks for the help.
The very first thing is to just check if the entity exists.
Errors shown in Studio Code Server are often just from its Home Assistant extension not being up to date… not an actual issue in HA.
Yes, I can confirm the entity exists (it auto-completes to it).
If the HA extension is outdated, I take it there’s no way to update it?
Can you please tell me the best way to check whether my update to configuration.yaml is able to be loaded?
Thank you.
If you are using the add-on, I think the extension updates with updates to the Add-on so check there. If you are running a stand alone version of VSC go to File > Preferences > Extensions.
Thanks. I just added the add-on a few days ago, so it’s probably up to date. I also just tried adding the extension in standalone VSC, and I saw the same errors.
I tried manually reloading configuration.yaml, and it loaded without error, and the very simple template sensor from my earlier post worked. So I guess the lesson is just don’t trust the editor.
Thanks for the suggestions.