[SOLVED] State_attr in template sensor issue

Hi all

I have a lot of template sensors with state_attr and I see that all of them are not working anymore.
Has something changed that I’ve missed?

This is an example of sensor template:

    temperatura_netatmo:
      friendly_name: Temperatura Netatmo
      value_template: "{{ state_attr('climate.sala', 'current_temperature') | float }}"

and this is the climate.sala

I’ve tried also removing the | float part, but with no success.

What can I check?

Thanks

And what is not working?

The template sensor is unavailable

I,ve tested your code with my climate entity - no issues. Anything in the logs? What if you copy your code into Dev Tools — Template?

maybe I’ve found the issue

now the templates have to be under

template:
  - sensor:
      - name: "Temperatura Netatmo"

and not under

- platform: template
  sensors:
    temperatura_netatmo:
      friendly_name: Temperatura Netatmo
      value_template: "{{ state_attr('climate.sala', 'current_temperature') | float }}"

is it right?

Not quite, see here: Legacy Sensors

But give it a try, maybe it works better with the new format.

This is what I used to have

the fact is that if I try the template in this page I get an unknown error

but the climate.sala is ok

is it correct the template that I’ve tested?

thanks

PS: @petro sorry if I’m tagging you, but I’m really getting mad about my issue.
Your help would be appreciated, because I don’t really know what to check
Thanks

To me your template seems to be OK. Are you sure that the entity climate.sala and all its attributes do exist at the time you are using it? What happens if you test {{ states.climate.sala }}

@pedolsky @starob and @petro
the issue was related to Saver integration reading some messages regarding the error “maximum recursion depth exceeded” that I found in my log

I was on 1.2.0 of Saver, a custom integration from HACS, and disabling it, the template sensors started working again

Then I found that there was a new version 1.2.1 and upgrading and enabling it, now it’s working again

Thanks

For anyone wondering what’s going on, Saver is a custom integration.

2 Likes

Yup, in recent version I have added to Saver two custom Jinja functions and in some cases it caused infinite recursion during template environment set-up. The same problem could be also caused by v1.2.2 version of my Custom Templates integration (it should be fixed in v1.2.3).

1 Like

For future reference, before posting a question in the forum, and always before reporting an Issue in GitHub, disable custom integrations. If the behavior disappears then you know it’s probably due to one of the custom integrations.

In this case, it’s unlikely anyone who has helped you could have guessed that you were using a custom integration that directly affects the behavior of entity states and templating.

no one helped me directly, I was investigating and after several hours I found in the log that a template sensor was in error with the error I posted above.
Then, searching in the community I found this post, not related to state_attr

disabling custom integrations, if someone have a lot of them, and I one of them, could be more expensive in time to get the solution.

pedolsky and starob tried to help you.

Everyone else’s time is not expensive, just yours? Good to know when you ask the community for help again.

1 Like

I think you misunderstood and maybe you should read again the entire thread

Of course @pedolsky and @starob gave me suggestions on how to solve, but their suggetions were correct if the issue was in some wrong coding made by myself, but this was not the case. And I say thanks to them.

This is a community were everyone try to give and get help.

What I see from all you reply to this thread does not rely to give nor get help.

So, this is the way to spend time for nothing.

And I close my reply to you

Have a good time and enjoy life

Their suggestions attempted to determine if the problem was due to the entity referenced by the template or the Template Sensor’s configuration itself. That’s the normal debugging strategy when something like what you reported fails.

Your suggestion that the problem was because your sensor had to be changed from legacy to modern format was corrected by pedolsky.

Neither pedolsky or starob (or me) could have guessed that you were using an obscure custom integration that affects the behavior of entity states and templating. You knew you installed it but no one else did. That’s why it’s important to disable custom integrations first to determine if they might be the cause.

Had you posted this as an Issue in GitHub, you would have received the same advice.

2 Likes