How am I not formatting this value template correctly?

The value template works fine in dev tools but I cant get past the config check.

- platform: template
  sensors:
    sensor name:
      friendly_name: "Circulation time"
      value_template:
        "{{% set hours = (11526 / states('sensor.total_circulation_lph') | int) | float %}
        {% set minutes = ((hours % 1) * 60) | int %}
        {% set hours = (hours - (hours % 1)) | int %}
        {{ '%02i:%02i'%(hours, minutes) }}"

I should add that this is my first value template! (and not all mine at that).

You cannot do “{{%”

try:

- platform: template
  sensors:
    sensor name:
      friendly_name: "Circulation time"
      value_template: >-
        {% set hours = (11526 / states('sensor.total_circulation_lph') | int) | float %}
        {% set minutes = ((hours % 1) * 60) | int %}
        {% set hours = (hours - (hours % 1)) | int %}
        {{ '%02i:%02i'%(hours, minutes) }}

Thanks for the help.

I’m still getting:

Invalid config for [sensor.template]: invalid slug sensor name (try sensor_name) for dictionary value @ data['sensors']. Got OrderedDict([('sensor name', OrderedDict([('friendly_name', 'Circulation time'), ('value_template', "{% set hours = (11526 / states('sensor.total_circulation_lph') | int) | float %} {% set minutes = ((hours % 1) * 60) | int %} {% set hours = (hours - (hours % 1)) | int %} {{ '%02i:%02i'%(hours, minutes) }}")]))]). (See ?, line ?).

when you see references to slug it means the field that your template resides in.

You can’t have spaces or capitals in your slug. change that to circulation_time or something simliar.

EDIT: Also, that template does not protect against dividing by zero… If sensor.total_circulation_lph is ever zero, you’ll get errors.

- platform: template
  sensors:
    circulation_time:
      friendly_name: "Circulation time"
      value_template: >-
        {% set lph = states('sensor.total_circulation_lph') | int(none) %}
        {% if lph %}
          {% set hours = 11526 / lph %}
          {% set minutes = ((hours % 1) * 60) | int %}
          {% set hours = (hours - (hours % 1)) | int %}
          {{ '%02i:%02i'%(hours, minutes) }}
        {% else %}
          none
        {% endif %}

Brilliant!

Works a treat. Thank you for taking the time.