Template sensor not appearing in entities

I have a Withings sleep sensor that tells me I spent 15,000 seconds in REM last night. That’s not convenient so I am trying to convert it to minutes by creating a template sensor by putting this in configuration.yaml.

template:
  - sensor:
      - name: "REM"
        unit_of_measurement: "Minutes"
        state: >
          {% set bedroom = states('sensor.withings_sleep_rem_duration_seconds_NAME') | float %}
          {{ ((bedroom / 60)}}

This does not create a sensor in the entities. I’ve tried a number of configurations similar to this (and reloading YAML and restarting HA) and none have worked.

I have also tried

template:
    sensor:
      REM_Minutes:
        friendly_name: "REM Minutes"
        unit_of_measurement: 'Minutes'
        value_template: >-
          {% set REMminutes = states('sensor.withings_sleep_rem_duration_seconds_NAME') | float %}
          {{((REMminutes)/60}}

You have too many parentheses, and you don’t have a default for float()

template:
  - sensor:
      - name: "REM"
        unit_of_measurement: "Minutes"
        state: >
          {% set bedroom = states('sensor.withings_sleep_rem_duration_seconds_NAME') | float(0) %}
          {{ bedroom / 60 }}

Also, make sure to use the actual entity_id and that you only have one top-level template: configuration key.

1 Like

Works beautifully, thank you!