Value_templates - have I got this configuration correct?

I’m attempting to display an integer value in a state-badge for my living room temperature (sensor.living_room_temperature), and from reading these forums I’ve gone about this as follows.

Inside configuration.yaml…

sensors: !include sensors.yaml

Inside sensors.yaml, created in the same folder as configuration.yaml…

sensor:
  - platform: template
    sensors:
      livingroomtemp:
        value_template: "{{ states('sensor.living_toom_temperature') | int }}"

Inside my lovelace config…

- type: state-badge
  entity: sensor.livingroomtemp
  style:
    top: 44%
    left: 57%
    color: 'rgba(0,0,0,0)'

But all this results in is an error on my floorplan stating entity sensor.livingroomtemp can’t be found.

At which step have I gone wrong here?

You need to remove the line sensor: from the top of your sensors.yaml

Also remove the s from the end of sensors: in configuration.yaml.

Then reload homeassistant.

1 Like

Thank you for the prompt input!

I now have this…

$ cat configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
$ cat sensors.yaml
- platform: template
  sensors:
    livingroomtemp:
      value_template: "{{ states('sensor.living_toom_temperature') | int }}"

And have restarted Home Assistant, but still get the same error.

I don’t think you need a sensor that converts the sensor to an int, did you try using sensor.living_room_temperature directly in lovelace?

I also notice you have a typo in the sensor config you wrote toom instead of room.

1 Like

Yes I did try it directly, but it reports to two decimal places.

And thank you for the toom spot! :joy:

Unfortunately after a restart it’s still showing the same error.

$ cat sensors.yaml
- platform: template
  sensors:
    livingroomtemp:
      value_template: "{{ states('sensor.living_room_temperature') | int }}"
$ cat configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
          - type: state-badge
            entity: sensor.livingroomtemp
            style:
              top: 44%
              left: 57%
              color: 'rgba(0,0,0,0)'

Any errors in the log?

Can you see the entity under Developer Tools -> States?

There’s nothing relevant in the logs, and no I can’t see sensor.livingroomtemp in Developer Tools -> States.

I think the penny has just dropped: I’m running Home Assistant in Docker and appear to have two sets of directories with configuration.yaml present…

/usr/share/hassio/homeassistant
/home/pi/homeassistant

…and I’d been editing the latter. Setting all this up in the former appears to work perfectly!

(Should I be deleting the latter to avoid any future confusion?)

This looks like you are running Home Assistant Supervised (add-ons,automatic updates, snapshots etc.),so the second path should not be relevant. I’d still do a backup of the directory first before removing it.