Help with Config

This is really really weird. All of a sudden it is telling me that Name is invalid in templates… I know this to be false, considering I’ve been saving configs all night.

All I did was change a template. I put everything back how it was. I’ve been up ALL night working on things, I am not about to reload my snapshot from yesterday because it’s suddenly being random. Literally the only thing I touched was this template, and I put it back… this entity doesn’t even use “Name”.
Also, what is this garbage? Won’t tell me what line the error is… yeah, I believe there is an error even less.

Any help is appreciated. The very bottom is what the sensor was. The only thing I can think is that something may have corrupted, because when I was using the template developer tool, HA crashed twice on me.

2022-05-28 09:39:27 ERROR (MainThread) [homeassistant.components.hassio] The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: [name] is an invalid option for [sensor.template]. Check: sensor.template->name. (See ?, line ?). 
2022-05-28 09:39:27 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall homeassistant.restart (c:01810b525b06b2292a61288ff79d1810)>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1645, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1664, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/hassio/__init__.py", line 679, in async_handle_core_service
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: [name] is an invalid option for [sensor.template]. Check: sensor.template->name. (See ?, line ?). 
#####
sensor:
#System Monitor
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /
      - type: memory_free
      - type: memory_use_percent      
      - type: processor_use
      - type: last_boot    
      - type: disk_free
      - type: network_in
        arg: eth0
      - type: network_out
        arg: eth0
      - type: ipv4_address
        arg: eth0
      - type: ipv4_address
        arg: wlan0
      - type: load_1m
     
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'
     
  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°F"
    value_template: "{{ value | multiply(0.001) | round(1) }}"

#Weight To Lbs
  - platform: template
    name: Pronown - Weight - Lbs
    unit_of_measurement: "lbs"
    state: >-
        {{
          (states('sensor.fitness_pronown_weight')| float(0) * 2.20462262185)
          | round(2, default=0)
        }}
    icon: "mdi:weight-pound"





#Calendar Sensor - Pronown Work
  - platform: time_date
    display_options:
      - 'time'
  - platform: template
    sensors:
      until_work_pronown:
        friendly_name: Work Countdown - Pronown
        entity_id: sensor.time
        value_template: >-
          {% set time = (value | int) | int %}
          {% set minutes = ((time % 360000) / 6000) | int %}
          {% set hours = ((time % 8640000) / 360000) | int %}
          {% set days = (time / 8640000) | int %}

          {%- if time < 6000 -%}
            Less than a minute
          {%- else -%}
            {%- if days > 0 -%}
              {{ days }}d
            {%- endif -%}
            {%- if hours > 0 -%}
              {%- if days > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ hours }}h
            {%- endif -%}
            {%- if minutes > 0 -%}
              {%- if days > 0 or hours > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ minutes }}m
            {%- endif -%}
          {%- endif -%}
         
#        value_template: >-
#          {% if states.calendar.work_pronown.attributes.start_time %}
#            {{((as_timestamp(states.calendar.work_pronown.attributes.start_time) - as_timestamp(now())) / 60) | default(99) | int }}
#          {%- else -%}
#            "none"
#          {%- endif %}
         
#Calendar Sensor - Pronown Work
  - platform: time_date
    display_options:
      - 'time'
  - platform: template
    sensors:
      work_countdown_pronown:
        friendly_name: Work Countdown - Pronown
        entity_id: sensor.time
        value_template: >-
          {% if states.calendar.work_pronown.attributes.start_time %}
            {{((as_timestamp(states.calendar.work_pronown.attributes.start_time) - as_timestamp(now())) / 60) | default(99) | int }}
          {%- else -%}
            "none"
          {%- endif %}

Idk what was wrong. I cut all my sensors and pasted them into notepad, saved config, it let me restart HASS and now I’ve put them back in with a copy paste and now it’s fine…

No it isn’t. This ain’t right:

#Weight To Lbs
  - platform: template
    name: Pronown - Weight - Lbs
    unit_of_measurement: "lbs"
    state: >-
        {{
          (states('sensor.fitness_pronown_weight')| float(0) * 2.20462262185)
          | round(2, default=0)
        }}
    icon: "mdi:weight-pound"

It should be:

#Weight To Lbs
  - platform: template
    sensors: 
      friendly_name: Pronown - Weight - Lbs
      unit_of_measurement: "lbs"
      state: >-
          {{
            (states('sensor.fitness_pronown_weight')| float(0) * 2.20462262185)
            | round(2, default=0)
          }}
      icon: "mdi:weight-pound"

Yeah, I noticed it didn’t restart after hitting post. I’ll try that, again. I had it set that way. I’ve been fighting with that one for this entire time lol. I’m about to just copy another sensor I have, rename it and paste this template and call it a day if this doesn’t work.

Used the provided code, got the same error I got last time. I was really hoping I had mistyped it.

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']['friendly_name']. Got 'Pronown - Weight - Lbs' expected dictionary for dictionary value @ data['sensors']['icon']. Got 'mdi:weight-pound' expected dictionary for dictionary value @ data['sensors']['state']. Got "{{\n (states('sensor.fitness_pronown_weight')| float(0) * 2.20462262185)\n | round(2, default=0)\n}}" expected dictionary for dictionary value @ data['sensors']['unit_of_measurement']. Got 'lbs'. (See ?, line ?).

Shouldn’t it be value_template in legacy format?

tried that too. I’ve been trying legacy and modern I even tried to copy/pasta the Withings - Home Assistant
tried the config from here even. Still a no go.

You’re missing the name of the sensor to work correctly. :slight_smile: I’d guess, you’re mixing the instructions from old and new template format(s). :slight_smile:

- platform: template #this is the old style, I'd suggest using the new style
  sensors:
    my_very_cool_sensor_name: # you are missing this line, thus not indenting the rest correctly
      friendly_name: ... # indented two more spaces

Yeah, apparently my setup no longer accepts legacy for everything, even though I have it enabled in config. OH MY GOD… I just noticed I didn’t enable legacy. It was still false.

Either way… Yeah, new format worked it looks like.

template:
  - sensor:
      - name: "Pronown - Weight - Lbs"
        state: >-
          {{
            (states('sensor.fitness_pronown_weight')| float(0) * 2.20462262185)
            | round(2, default=0)
          }}
       

Yeah you had a mix of new and old formats.

Indeed it should.

Full disclosure, I stayed up for over 24 hours writing automations, creating sensors, and generally preparing for my Blue Iris setup coming in today, so when I tried value_template, I may have tried it when I tried the new one. I know for a fact I did try it with legacy (probably didn’t work because I was set to FALSE) I copied over the config for my calendar timer, and replaced the info and added the template, still no dice. This part was what I copy modded, changed names and removed the entity_id. (I know it isn’t supposed to be in the one for the cal sensor, but for some reason it only worked with it there.)

  - platform: template
    sensors:
      until_work_pronown:
        friendly_name: Work Countdown - Pronown
        entity_id: sensor.time
        value_template: 

edit: changed the template on that during this time too, guess it didn’t work, just showing unavailable now.

Pretty sure I need to tell this to look at the start_time somehow, but not sure how. Time templates are not easy for me. It’s supposed to be aimed at trying to find the start time on Google Calendar. I think I might need to go to bed because I’m looking at this like “why did I think it would work?”

  - platform: time_date
    display_options:
      - 'time'
  - platform: template
    sensors:
      work_countdown_pronown:
        friendly_name: Work Countdown - Pronown
        entity_id: sensor.time
        value_template: >-
          {% set time = (value | int) | int %}
          {% set minutes = ((time % 360000) / 6000) | int %}
          {% set hours = ((time % 8640000) / 360000) | int %}
          {% set days = (time / 8640000) | int %}

          {%- if time < 6000 -%}
            Less than a minute
          {%- else -%}
            {%- if days > 0 -%}
              {{ days }}d
            {%- endif -%}
            {%- if hours > 0 -%}
              {%- if days > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ hours }}h
            {%- endif -%}
            {%- if minutes > 0 -%}
              {%- if days > 0 or hours > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ minutes }}m
            {%- endif -%}
          {%- endif -%}

Status changed to less than a minute for some reason. My event isn’t until tomorrow morning.

#Calendar Sensor - Pronown Work
  - platform: time_date
    display_options:
      - 'time'
  - platform: template
    sensors:
      work_countdown_pronown:
        friendly_name: Work Countdown - Pronown
        entity_id: sensor.time
        value_template: >-
          {% set time = (states('calendar.work_pronown.attributes.start_time') | int)  | int %}
          {% set minutes = ((time % 360000) / 6000) | int %}
          {% set hours = ((time % 8640000) / 360000) | int %}
          {% set days = (time / 8640000) | int %}

          {%- if time < 6000 -%}
            Less than a minute
          {%- else -%}
            {%- if days > 0 -%}
              {{ days }}d
            {%- endif -%}
            {%- if hours > 0 -%}
              {%- if days > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ hours }}h
            {%- endif -%}
            {%- if minutes > 0 -%}
              {%- if days > 0 or hours > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ minutes }}m
            {%- endif -%}
          {%- endif -%}

I feel like it is progress though

the problem is “(states(‘calendar.work_pronown.attributes.start_time’)” isn’t a number. It’s a datetime.

so when you convert it to an “int” using the filter you get a result of 0 (or at least you used to but I’m not sure now). Either way it isn’t what you expect. And no matter how many times you convert it to an “int” (twice in your case) it won’t ever be anything other than 0.

you need to convert that to a timestamp first.

And the way you were using “states” is wrong as well.

{% set time = as_timestamp(states.calendar.work_pronown.attributes.start_time) %}

or even better:

{% set time = as_timestamp(state_attr('calendar.work_pronown', 'start_time')) %}

that should get you closer

BTW< this is no longer supported:

  - platform: template
    sensors:
      until_work_pronown:
        friendly_name: Work Countdown - Pronown
        entity_id: sensor.time  #<---- remove this line
        value_template:

I can’t remember exactly what the “legacy” setting was for but I’m pretty sure it had nothing to do with old/new style template sensors. I think it was for use back when the attributes changed to using native datatypes.

TBH, I’m not even sure that’s still a thing.

Where are setting that option to ‘true’ (or at least not ‘false’)?

I’m not sure what you’re referring to there but there’s no setting for changing between the legacy and new format of template. They are under different keys (template key vs template platform under sensor key) and they have differences like one using state and the other value_template.

I think you should at least try to focus on one format (of cource preferably the new format) rather than going in between both to avoid confsuing yourself even more. And remove any deprecated options such as entity_id

1 Like

Thank you all for the help.
Got it figured out in another thread I had started because I thought this one had died and wasn’t originally tied to this sensor.
This is the solution: