Problem with sensors

I have these sensors configured:

- platform: time_date
  display_options:
    - 'time_date'
    - 'time'
    - 'date'
    - 'date_time'
    - 'beat'
- platform: template
  sensors:
    date_template:
      entity_id: sensor.date
      friendly_name: 'Oggi'
      value_template: '{{ as_timestamp(now()) | timestamp_custom("%d/%m/%y", True) }}'
- platform: template
  sensors:
    date_month:
    entity_id: sensor.time__date
    value_template: "{{as_timestamp(now())|timestamp_custom('%B', True)}}"

But i get this error when checking configuration:

Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data['sensors']['date_month']. Got None
expected a dictionary for dictionary value @ data['sensors']['entity_id']. Got 'sensor.time__date'
expected a dictionary for dictionary value @ data['sensors']['value_template']. Got "{{as_timestamp(now())|timestamp_custom('%B', True)}}". (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

How to solve?

Try removing the entity_id rows from platform: template.

Rule 3.

Put single quotes inside double quotes. So not like this:

I have that error after adding the sensor:

- platform: template
  sensors:
    date_month:
    entity_id: sensor.time__date
    value_template: "{{as_timestamp(now())|timestamp_custom('%B', True)}}"

So i think the problem is related to that sensor as the previous two are regularly working…

The entity_id is needed after 0.80.x release as the templates without an entity cannot be renewed… At lest this is what i read about…

1 Like

Don’t do that.

If you do not supply an entity_id in the configuration you will need to run the service homeassistant.update_entity to update the sensor.

Hmm, I’m on 80.3. What version did this start?

Can you quote the right way to have the template with quotes? They are my nightmare…

You got it right:

Also I think you have an extra underscore in this:

    entity_id: sensor.time__date

Should it be this?:

    entity_id: sensor.time_date

Hmm, i double-checked but that sensor has two underscores and i don’t know why as the config says:

- platform: time_date
  display_options:
    - 'time_date'
    - 'time'
    - 'date'
    - 'date_time'
    - 'beat'

And in dev-state i have sensor.time__date

So if all is correct, why i get that error?

Huh. I just had a look at mine. It does the same thing. I have sensor.date__time.
Ok so It must be something else. I’ll have another look.

Did you swap the single and double quotes in this template?

value_template: '{{ as_timestamp(now()) | timestamp_custom("%d/%m/%y", True) }}'

Should be:

value_template: "{{ as_timestamp(now()) | timestamp_custom('%d/%m/%y', True) }}"

hmm i don’t think so as that sensor doesn’t give me error… I get error only if i try to create this sensor:

- platform: template
  sensors:
    date_month:
    entity_id: sensor.time__date
    value_template: "{{as_timestamp(now()) | timestamp_custom('%B', True)}}"

this gives:


no error, template seems to the point. What does your error tell you here? btw, using the multiline > makes it easier to handle quotes.

Found it!
Indentation error… nothing more simplier… :joy:

- platform: template
  sensors:
    date_month:
      entity_id: sensor.time__date
      friendly_name: 'Corrente Mese'
      value_template: "{{as_timestamp(now()) | timestamp_custom('%B', True)}}"

In this way it works…

bingo, was just about to tell you…:wink: cool. Still, make life easier on yourself and ditch the quotes by using multiline. Always.

:grinning::ok_hand::muscle:

Yes, i will do always since now…

You should still follow the templating rules and fix it,

templating rules are you can not mix quotes or use the same in and outside the template. But he can use double quotes inside the template without issue, when using single quotes outside.

No issue at all if using the multiline >, in which case you only need quotes inside the template