Template sensor

I have some energy-sensors and i’m trying to create a template that summarizes the states of those.
Lets call them sensor.energy_1, sensor.energy_2 & sensor.energy_3.

My configuration looks like this:

- platform: template
  sensors:
    energy:
      value_template: "{{ float(states('sensor.energy_1')) + float(states('sensor.energy_2')) + float(states('sensor.energy_3')) }}"
      unit_of_measurement: 'KWh'

The value_template it self i know work after testing in the dev-tools. But when starting home-assistant i get this error in my log:

16-04-30 22:42:33 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/template.py", line 82, in template_sensor_event_listener
    self.update_ha_state(True)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 145, in update_ha_state
    self.update()
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/template.py", line 109, in update
    self._state = template.render(self.hass, self._template)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/template.py", line 59, in render
    }).render(kwargs).strip()
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for +: 'float' and 'str'

Could it be because the energy-sensors are z-wave and those are not setup properly when the template tries to initiate? Is there a way around that?

Hey I had similar troubles. Instead of

try using

states.sensor.energy_1.state 
1 Like

hey @deisi,

what was the solution for this?
Can’t read your answer anymore :frowning:

Havin the exact same problem