Can someone tell me what's wrong with my Template Sensor?

The following is causing errors and I can’t figure out what’s wrong. I’m sure it’s something stupid I’ve done. The value template works fine in the Templates Developer tool. I’ve tried different combinations of things with no success. I’ve come up with a different way of doing what I want, however, I’d like to know WHY this didn’t.

  - platform: mqtt 
    name: "camera_status" 
    state_topic: "home/livingroom/camera/message"

  - platform: template 
    sensors: 
      camera_capture_time: 
      value_template: "{{ states.sensor.camera_status.name }}"

File "/usr/lib/python3.6/site-packages/homeassistant/helpers/config_validation.py", line 441, in validator if key in config:
TypeError: argument of type 'NoneType' is not iterable	  

Thanks in advance!

1 Like

Your value_template should be two spaces indented more than the camera_capture_time line.

1 Like

I can’t believe that this works in the templates tool.
What’s shown in the templates tool when you insert this:
{{ states.sensor.camera_status }}

<template state sensor.camera_status=unknown; friendly_name=camera_status @ 2018-01-25T11:57:05.377965-06:00>

So you can get the status:
{{ states.sensor.camera_status.state }} -> ‘unknown’
the friendly_name:
{{ states.sensor.camera_status.attributes.friendly_name }} -> ‘camera_status’
or the last changed timestamp:
{{ states.sensor.camera_status.last_changed }} -> ‘2018-01-25T11:57:05.377965-06:00’
There is no state ‘name’

EDIT: I have to correct this post. {{ states.sensor.camera_status.name }} works and returns the friendly_name. ???
I didn’t know and have never seen this.

Thanks Dolores, I swear I stared at that YAML for hours and still missed the indentation!

TIL. I would have assumed you needed attributes.friendly_name.