A template question after 0.81 upgrade

I have a load of template sensors that need to have their entity_id added following the 0.81 upgrade. This is largely down to my garden irrigation system which has two cycles, each with five zones so generating many tens of templated sensors which are used in the front end display.

It is intuitively obvious that where possible using the new homeassistant.update_entity service would be more efficient than including the entity_id - Is this correct and if so is the benefit significant enough to think about?

Also: I thought I should just check; here is an example of one of my template senors. The input_booloean is set by the user, the input_datetime is set by an automation/script. Am I right in thinking that I need to include both of these as entity_ids in the template?

This is a HUGE breaking change for me. luckily I have until next summer to sort it all out!!!

sensors:
  cycle1_next_run_time:
    friendly_name: "Next scheduled run time"
    value_template: >
      {% if is_state('input_boolean.cycle1_enable', 'on') %}
        {{ (as_timestamp(states.input_datetime.cycle1_next_run_time.state)) | timestamp_custom("%a %d %h at %H:%M") }}
      {% else %}
        None
      {% endif %}
    icon_template: mdi:clock-start

I donā€™t think youā€™ll need one for the input_boolean. I just looked at the log to see which sensors were throwing errors and added the entity IDā€™s.

You could use an automation to update them every minute or so and just have the sensors in the automation with the new update serviceā€¦

I just looked a bit more closely at the error in the log and it only refers to the icon template. Why is that? This has confused me even moreā€¦

I think considering the reach of this breaking change the documentation has not been goodā€¦

2018-10-31 08:38:53 WARNING (MainThread) [homeassistant.components.sensor.template] Template sensor cycle1_next_run_time has no entity ids configured to track nor were we able to extract the entities to track from the icon template(s). This entity will only be able to be updated manually.

1 Like

OK, I really donā€™t understand thisā€¦

Why is this template senor ok without an entity_id

  cycle1_running:
    friendly_name: "Morning cycle"
    value_template: >
      {% if is_state('input_boolean.cycle1_running', 'on') %}
        Running
      {% else %}
        Not running
      {% endif %}     
    icon_template: >
      {% if is_state('input_boolean.cycle1_running', 'on') %}
        mdi:run
      {% else %}
        mdi:human-handsdown
      {% endif %}     

But this one wasnā€™t???

  cycle1_next_run_time:
    friendly_name: "Next scheduled run time"
    entity_id: input_datetime.cycle1_next_run_time
    value_template: >
      {% if is_state('input_boolean.cycle1_enable', 'on') %}
        {{ (as_timestamp(states.input_datetime.cycle1_next_run_time.state)) | timestamp_custom("%a %d %h at %H:%M") }}
      {% else %}
        None
      {% endif %}
    icon_template: mdi:clock-start

not sure, but this is not a templateā€¦

fwiw with template sensors, and not needing to change the icon,I always set the (fixed) icon through customize, since template sensors donā€™t have the option of a fixed icon.

@Mariusthvdb is correct. You arenā€™t using a template in your icon_template. The logs are telling you ā€œHey I canā€™t find an entity_id in this templateā€. Your other template has one, so it wonā€™t complain.

The proper way to adjust an icon (without a template) is through the customize section:

1 Like

@petro, @Mariusthvdb

Yes, but I am using a value_template arenā€™t I?

Orā€¦ hang onā€¦
Are you saying that this template_sensor is all ok as far as the value_template bit is concerned and that HA was only complaining about the icon bit? Which would make sense of the error message, show up my lack of understanding :blush: and mean I have edited a load of my sensors for no reason!

  cycle1_next_run_time:
    friendly_name: "Next scheduled run time"
    entity_id: input_datetime.cycle1_next_run_time
    value_template: >
      {% if is_state('input_boolean.cycle1_enable', 'on') %}
        {{ (as_timestamp(states.input_datetime.cycle1_next_run_time.state)) | timestamp_custom("%a %d %h at %H:%M") }}
      {% else %}
        None
      {% endif %}
    icon_template: mdi:clock-start

That all makes perfect sense! One day a whole 24 hours might pass without finding out something new!!!

Thank you to you both.

You are using value_template but the config is bitching about your icon_template. You are just using a string there without any entities.

    icon_template: mdi:clock-start

yes, take out the icon_template here and instead use:

homeassistant:
  customize:
    sensor.cycle1_next_run_time:
      icon: mdi:clock-start

depending on your customize: settings in configuration.yaml

2 Likes

@petro. @Mariusthvdb

Thanks again, Iā€™m cleaning up my configā€¦
:slight_smile:

1 Like

always an ongoing process I find as your knowledge increasesā€¦

What about if i have a friendly_name_template? Tried moving it to customize (Using packages) - it appears it doesnā€™t take templates or i am missing something?

WARNING: Template sensor xxx has no entity ids configured to track nor were we able to extract the entities to track from the friendly_name template(s). This entity will only be able to be updated manually.

Can you post the original?

I Believe hass is complaining about this ā€˜friendly_name_templateā€™ - Tried moving it to customize but it didnā€™t work - I suppose ā€˜friendly_name_templateā€™ is supported under customize?

 forecast_1:
    friendly_name_template: >
      {%- set date = as_timestamp(now()) + (1 * 86400 ) -%}
      {{ date | timestamp_custom("Tomorrow (%d/%m)") | replace("(0", "(") | replace("/0", "/") }}
    value_template: >
      {{states.sensor.dark_sky_daytime_high_temperature_1.state|round(0)}}Ā°/{{states.sensor.dark_sky_overnight_low_temperature_1.state|round(0)}}Ā°/{{states.sensor.dark_sky_precip_probability_1.state|round(0)}}%
    entity_picture_template: >-
      {{ '/local/icons/dark_sky/' ~ states.sensor.dark_sky_icon_1.state ~ '.png'}}


2018-11-01 18:36:41 WARNING (MainThread) [homeassistant.components.sensor.template] Template sensor forecast_1 has no entity ids configured to track nor were we able to extract the entities to track from the friendly_name template(s). This entity will only be able to be updated manually.

Yes it would, thereā€™s no id in there. You can just and entity_id to forcast_1. In entity_id, list out all the entities used in value_template and entity_picture_template.

1 Like