How can I limit a specific value of an entity that I don’t want to exceed a specific threshold?
My use case would be to limit the heater temperature to a maximum value, even if the user using the remote control sets a higher value than the one I want. So, for example, if by using the IR control the user sets the temperature to 30°, to use an automation to bring it back to a more reasonable 25°.
The idea is to grab this event every time the temperature changes, or even periodically (and of course only when the heater is on.
The entity right now has an attribute named “temperature” which is exactly what I want to target.
Thank you @AllHailJ … your insight is more than valuable for me.
Now with your proposal it finally makes sense … the whole template mechanism.
But I still have a few errors to fix, if you can help
First of all, in your proposal there’s a typo, a “)” instead of “}”. This was easy to fix. My actual problem is that I can;t get the value of an entity inside the quotes. And this is not only on the template, but also on the automation.
On the automation I see this error on the logs:
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'input_number' is undefined
2022-03-20 19:05:20 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'input_number' is undefined when rendering '{% if state_attr('climate.bedroom', 'temperature') > input_number.maximum_temperature %}
{{ input_number.maximum_temperature }}
{% else %}
{{ state_attr('climate.bedroom', 'temperature') }}
{% endif %}'
2022-03-20 19:05:20 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: 'input_number' is undefined') while processing template 'Template("{% if state_attr('climate.bedroom', 'temperature') > input_number.maximum_temperature %}
{{ input_number.maximum_temperature }}
{% else %}
{{ state_attr('climate.bedroom', 'temperature') }}
{% endif %}")' for attribute '_attr_native_value' in entity 'sensor.bedroom_limit_temp'
I bypassed this problem by setting the value hard coded.
But then the automation has a similar ptoblem:
Error: Error rendering data template: UndefinedError: 'state' is undefined
On the template I even tried to use the syntax state('...') but with no luck either.
Have you created input number in the UI? This is done in the helpers. Configuration → Automations & Scenes → helpers. Also have you set the value either by a default or in the UI?
Yes I did… from the UI as you said and actually it does have a value.
It is strange for me that I also the automation does not recognize the value of the produced parameter.
Anyway this is a completely different problem; I don’t want to hijack your wiliness to help – you have already put me in the right track and “officially” the question I asked is solved
Thank you again