Error in Template configuration

Hey Guys,

i tried to configure a template sensor who shows my remaining battery using time…

template:
  - sensor:
      - name: "Battery Remaining Time"
        unique_id: "Battery Remaining Time"
        state: >-
          {% set energy = states("sensor.q3m_energy_current_inverted") | float(0) %}
          {% set capacitymax = states('sensor.byd_battery_box_premium_hv_capacity_maximum') | float(0) %}
          {% set chargestate = states('sensor.byd_battery_box_premium_hv_state_of_charge') | float(0) %}
          {% set currentconsumption = states('sensor.sensor.verbrauch_gesamt') | float(0) %}
          {% set consumptioncalculated = currentconsumption * 60 | float(0) %}
          {% set capacity = ( capacitymax / 100 | float(0) ) x chargestate | float(0) %}
          {% if energy > 100 %} 0
          {% else %}
            {{ capacitymax / consumptioncalculated | float(0) }}
          {% endif %}

but i got following Error:

Invalid config for [template]: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘x’) for dictionary value @ data[‘sensor’][0][‘state’]. Got '{% set energy = states(“sensor.q3m_energy_current_inverted”) | float(0) %} {% set capacitymax = states(‘sensor.byd_battery_box_premium_hv_capacity_maximum’) | float(0) %} #{% set chargestate = states(‘sensor.byd_battery_box_premium_hv_state_of_charge’) | float(0) %} #{% set currentconsume = states(‘sensor.sensor.verbrauch_gesamt’) | float(0) %} #{% set consumecalculated = currentconsume * 60 | float(0) %} #{% set capacity = ( capacitymax / 100 | float(0) ) x chargestate | float(0) %} {… (See /config/configuration.yaml, line 59).

On line 11 you have an x where you need a *

1 Like

Ohh wow, thank you very much.

Ive looked for that ‘x’ before and didnt noticed it :smiley:

still got a Problem with my Sensor, the Value is always ‘unkown’

here’s my current config:

template:
  - sensor:
      - name: "Battery Remaining Time"
        unique_id: "Battery Remaining Time"
        state: >-
          {% set capacitymax = states('sensor.byd_battery_box_premium_hv_capacity_maximum') | float(0) %}
          {% set chargestate = states('sensor.byd_battery_box_premium_hv_state_of_charge') | float(0) %}
          {% set consumption = states('sensor.sensor.verbrauch_gesamt') | float(0) %}
          {% set capacity = ( capacitymax / 100 ) | float(0)  * chargestate | float(0) %}
            {{ ( capacity / consumption ) | float(0) }}

A Template Sensor will report unknown until one of the entities it references in its template changes state. The state-change will cause the template to be processed and the result reported.

So in your Template Sensor, the value of one of its three sensors must change in order for the template to be processed.

sensor.byd_battery_box_premium_hv_capacity_maximum
sensor.byd_battery_box_premium_hv_state_of_charge
sensor.verbrauch_gesamt

From the documentation:

Template entities will by default update as soon as any of the referenced data in the template updates.

For example, you can have a template that takes the averages of two sensors. Home Assistant will update your template sensor as soon as either source sensor updates.

My sensor sensor.verbrauch_gesamt changes all 5s. So it should be executed.

But you gave me the important hint.

I wrote sensor.sensor., that was one sensor. to much :grin:

Thank you very much.

1 Like