Template sensor not updating after update

I am using this template sensor, but its not updating anymore after updating HassIO

elechoog:
  friendly_name: "Meterstand electra hoog"
  unit_of_measurement: 'kWh'
  value_template: "{{ states('sensor.power_consumption_normal') | int }}"
  icon_template: mdi:power-socket-eu

I have read all the similar topics but cant find the solution.
Can any off you help. Thanks

I don’t see anything wrong with it and can’t explain why it’s not updating, unless sensor.power_consumption_normal is not changing. (Template sensors don’t update unless the entity/entities they’re watching change.)

On the other hand, I don’t see the point of this template sensor – it’s just exactly mirroring the state of sensor.power_consumption_normal. Can you explain why you even have it?

1 Like

I use it to monitor if its changing.
The state value is changing, but Meterstand electra hoog is not.
I use it to strip the decimals. Its working in dev templating.
This is the original sensor from my ISKRA AM550 power meter:

Since recent update - I believe you have to specifically state the entity_id in the template, no? Otherwise it won’t update automatically.

2 Likes

Ok, fair enough. That makes sense.

I think the issue might be that you’re using icon_template instead of icon. The value for icon_template does not contain any entities that it can find, so it’s probably deciding not to update. (You should see a warning.) I’d suggest changing icon_template to just icon.

1 Like

Not true. Unfortunately a lot of people seem to be coming to this incorrect conclusion. You only have to specifically list entities if the automatic entity extraction mechanism can’t find entity_id’s for all the templates.

Hmm, it doesn’t appear the template sensor has an option for icon. So you probably either have to list the entity_id source explicitly as @larsentim suggests, or maybe you can add the icon via customize.yaml. But I think the bottom line is the fact that icon_template does not contain an entity_id reference.

And how do you know when that is the case? Does it hurt to list the entity ID? I thought it would make it faster to process anyhow?

I removed the icon_template from the sensor template.
I will further test it. Keep you posted.
Thanks

By reading the code.

No, as long as you don’t make a mistake and miss one of the entities or misspell something, or forget to update the list if/when the template is changed.

Yes, you’ll probably save a few milliseconds during startup. :wink:

I thought the link would have been to the release notes, not the code itself.

Nobody reads the actual code. that’s why we have developers. :wink:

@larsentim

You can read the breaking changes, too. Bullet #4:

Then I guess I’m nobody. :blush:

But seriously, the documentation doesn’t describe how it automatically determines what entity/entities a template references. And unless you know that, it’s kind of hard to know if the template will update properly. E.g., it might only find some of the entities a template references. In that case you won’t get a warning – it just won’t work as you expect.

Documentation is all fine and good, but sometimes you have to read the code to understand how something might work in your particular situation. Or you can just ask on this forum, and maybe someone who has read the code, or will read the code to try and answer your question, will come along and help. :slight_smile:

1 Like

Removing the icon_template entry solved the problem.
Template sensor is updating again.
Thanks to all for the solution.

1 Like

Personally, I know it’s the case when I get an error about it in the log file. I just added the sensors referenced to the entity id’s in those templates and it fixed it.

I had the same problem:
I moved the icon_template above the value template and it fired right up. I’ll watch it for a day or two and see if it keeps updated.

Update: Still NOT working, just updates on a restart

Post your code but I’m betting you haven’t added the entity to the sensor…

David, thanks for taking the time…

The template sensor errors out during verification if it has an icon, icon_template goes smoothly

“hydro_rate” shows up as the entity, are you suggesting that an “entity: xxxxxxxxx” is somehow required?

This would be great to cure since I have a number of these sensor templates with poor icons

I had the icon_template above and below

      hydro_rate:
        icon_template: >- 
          {% if true %}
            mdi:flash
          {% endif %}
        value_template: >-
          {% if now().weekday() > 4 or now().hour < 7 or now().hour >= 19 %}
            off_peak
          {% elif now().hour >= 7 and now().hour < 11 %}
            {% if now().month >= 5 and now().month <= 10 %}
              mid_peak
            {% else %}
              on_peak
            {% endif %}
          {% elif now().hour >= 11 and now().hour < 17 %}
            {% if now().month >= 5 and now().month <= 10 %}
              on_peak
            {% else %}
              mid_peak
            {% endif %}
          {% elif now().hour >= 17 and now().hour < 19 %}
            {% if now().month >= 5 and now().month <= 10 %}
              mid_peak
            {% else %}
              on_peak
            {% endif %}
          {% endif %}

Your templates don’t make sense… if WHAT is true for the icon_template???

Here is one of my ones.

  - platform: template
    sensors:
      bom_forecast_0:
        entity_id:
          - sensor.bom_today_max
          - sensor.bom_today_min
          - sensor.bom_gosford_chance_of_rain_0
          - sensor.bom_gosford_icon_0
        friendly_name: "Today"
        value_template: >
          {{states('sensor.bom_today_max')|round(0)}}°/{{states('sensor.bom_today_min')|round(0)}}°/{{states('sensor.bom_gosford_chance_of_rain_0')|round(0)}}%
        entity_picture_template: >-
          {%- if states('sun.sun') == 'below_horizon' and (states('sensor.bom_gosford_icon_0') == 'fog' or states('sensor.bom_gosford_icon_0') == 'haze' or states('sensor.bom_gosford_icon_0') == 'light-showers' or states('sensor.bom_gosford_icon_0') == 'partly-cloudy' or states('sensor.bom_gosford_icon_0') == 'showers') -%}
          {{ '/local/icons/bom_icons/' ~ states('sensor.bom_gosford_icon_0') ~ '-night.png' }}
          {%- else -%}
          {{ '/local/icons/bom_icons/' ~ states('sensor.bom_gosford_icon_0') ~ '.png' }}
          {%- endif -%}

It’s using an entity picture, not an icon but you get the idea.

See how I define the entities at the top… this means if those entity state changes it will re-evaluate the template. That is most probably the bit you are missing but you have not really posted anything useful…

Regarding the icon_template
I just want to change the default icon. Nothing fancy.
The verifier errors out on an ‘icon:’ when included.
The verifier is quite happy to take the icon_template with a true (like saying if ‘1’, evaluates to true).
That does update the icon correctly but breaks the value logic (if it ever worked)

Regarding the value_template

It’s starting to make sense now. The logic evaluates now() but if there are no other entities present there may never be anything changing which causes hydro_rate to be re-evaluated.

Is that what your are saying? If yes i’ll have to create an entity that changes every hour and add it to the logic???

In your code you’ve listed the entities you are evaluating in the entity ID section. That makes sense, to expose them there since they are buried in the template.

i’d appreciate your thoughts