YAML value_template help

Not exactly sure what i’m doing wrong but i’m getting the following error, from the following chunk of yaml. Anyhelp would be appreciated.

homeassistant    | 2023-10-13 09:43:06.856 ERROR (MainThread) [custom_components.attributes.sensor] Could not attribute sensor for climate.nest_3rd: TemplateSyntaxError: expected token 'end of print statement', got '{'
- platform: attributes
  friendly_name: "eco mode"
  attribute: preset_mode
  entities:
    - climate.nest_3rd
  value_template: >-
    {% if value in ['eco'] %} True
    {% else %} False
    {% endif %}

What is that supposed to be exactly?.. A trigger? A sensor?

Tell us what you’re trying to do.

It is a sensor.

Attributes is not a core sensor platform.

Are you using a custom sensor integration? If so, post a link to it’s repo.

The template syntax used by pilotak’s homeassistant-attributes custom integration is weird…

Based on some of the issues and comments in the repo, it might need to be something like:

- platform: attributes
  friendly_name: "eco mode"
  attribute: preset_mode
  entities:
    - climate.nest_3rd
  value_template: "== 'eco' "

Unless you have a bunch of thermostats, you’d be better off using template binary sensors. They are better documented and they have a much larger user base, so more people would be in a position to offer help if needed.

Update:

I was able to play around with this a bit, and the syntax shown above does work (I don’t use preset_mode, so I tested it with hvac_action). Make sure to do an actual restart after editing your sensor configuration, just reloading the yaml config was not sufficient during my tests.

1 Like