Log's error, how to fix?

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:379
First occurred: 20:13:12 (5 occurrences)
Last logged: 20:13:12

TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.modbus_zcs_energia_generata_totale.state | float(0) > states.input_number.filtro_produzione.state | float(0) }}) renders=4>' for attribute '_attr_available' in entity 'sensor.zcs_produzione_totale'
TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.modbus_zcs_energia_acquistata_totale.state | float(0) > states.input_number.filtro_prelievo.state | float(0) }}) renders=4>' for attribute '_attr_available' in entity 'sensor.zcs_prelievo_totale'
TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.modbus_zcs_energia_venduta_totale.state | float(0) > states.input_number.filtro_immissione.state | float(0) }}) renders=4>' for attribute '_attr_available' in entity 'sensor.zcs_immissione_totale'
TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.modbus_zcs_energia_scaricata_totale.state | float(0) > states.input_number.filtro_scarica.state | float(0) }}) renders=4>' for attribute '_attr_available' in entity 'sensor.zcs_scarica_totale'
TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.modbus_zcs_energia_caricata_totale.state | float(0) > states.input_number.filtro_carica.state | float(0) }}) renders=4>' for attribute '_attr_available' in entity 'sensor.zcs_carica_totale'

https://www.home-assistant.io/docs/configuration/templating/#states

Besides what Tom says, it looks like your ā€œsensor.modbus*ā€ do not exist when the templates are evaluated.

Too few information for a fix.

What information is needed?

Whatever you think is relevant.

We donā€™t even enough info to tell you where to start. All we know is that a sensor.modbus_zcs_energia_generata_totale (and co.) is not existing when you try to evaluate a template somewhere.

Apparently, it is for availability ( for attribute '_attr_available' ), in which case you should check if sensor.modbus_zcs_energia_generata_totale is not null first.

1 Like

What I can say is that this error only occurs when restarting the HA, after which the sensors seem to do their job.
These are the original sensors:

      - name: "Modbus ZCS Energia generata totale"
        slave: 1
        address: 0x0686
        input_type: holding
        data_type: uint32
        unit_of_measurement: kWh
        device_class: energy
        scale: 0.1
        precision: 1
        scan_interval: 60
        lazy_error_count: 3
        unique_id: "energia generata tot"

      - name: "Modbus ZCS Energia acquistata totale"
        slave: 1
        address: 0x068E
        input_type: holding
        data_type: uint32
        unit_of_measurement: kWh
        device_class: energy
        scale: 0.1
        precision: 1
        scan_interval: 60
        lazy_error_count: 3
        unique_id: "energia acquistata totale"

      - name: "Modbus ZCS Energia venduta totale"
        slave: 1
        address: 0x0692
        input_type: holding
        data_type: uint32
        unit_of_measurement: kWh
        device_class: energy
        scale: 0.1
        precision: 1
        scan_interval: 60
        lazy_error_count: 3
        unique_id: "energia venduta totale"

      - name: "Modbus ZCS Energia caricata totale"
        slave: 1
        address: 0x0696
        input_type: holding
        data_type: uint32
        unit_of_measurement: kWh
        device_class: energy
        scale: 0.1
        precision: 1
        scan_interval: 60
        lazy_error_count: 3
        unique_id: "energia caricata totale"

      - name: "Modbus ZCS Energia scaricata totale"
        slave: 1
        address: 0x069A
        input_type: holding
        data_type: uint32
        unit_of_measurement: kWh
        device_class: energy
        scale: 0.1
        precision: 1
        scan_interval: 60
        lazy_error_count: 3
        unique_id: "energia scaricata totale"

These are the total sensors with increase

      - name: "ZCS Produzione Totale"
        unit_of_measurement: "kWh"
        state: >
          {% set energy = states.sensor.modbus_zcs_energia_generata_totale.state | float | default(0) %}
          {{ energy | round(2) }}
        availability: "{{ states('sensor.modbus_zcs_energia_generata_totale') | float(0) > states.input_number.filtro_produzione.state | float(0) }}"
        state_class: total_increasing
        device_class: energy
        icon: mdi:weather-sunny
        
      - name: "ZCS Prelievo Totale"
        unit_of_measurement: "kWh"
        state: >
          {% set energy = states.sensor.modbus_zcs_energia_acquistata_totale.state | float | default(0) %}
          {{ energy | round(2) }}
        availability: "{{ states('sensor.modbus_zcs_energia_acquistata_totale') | float(0) > states.input_number.filtro_prelievo.state | float(0) }}"
        state_class: total_increasing
        device_class: energy
        icon: mdi:transmission-tower
        
      - name: "ZCS Immissione Totale"
        unit_of_measurement: "kWh"
        state: >
          {% set energy = states.sensor.modbus_zcs_energia_venduta_totale.state | float | default(0) %}
          {{ energy | round(2) }}
        availability: "{{ states('sensor.modbus_zcs_energia_venduta_totale') | float(0) > states.input_number.filtro_immissione.state | float(0) }}"
        state_class: total_increasing
        device_class: energy
        icon: mdi:transmission-tower

      - name: "ZCS Scarica Totale"
        unit_of_measurement: "kWh"
        state: >
          {% set energy = states.sensor.modbus_zcs_energia_scaricata_totale.state | float | default(0) %}
          {{ energy | round(2) }}
        availability: "{{ states('sensor.modbus_zcs_energia_scaricata_totale') | float(0) > states.input_number.filtro_scarica.state | float(0) }}"
        state_class: total_increasing
        device_class: energy
        icon: mdi:battery-low
      - name: "ZCS Carica Totale"
        unit_of_measurement: "kWh"
        state: >
          {% set energy = states.sensor.modbus_zcs_energia_caricata_totale.state | float | default(0) %}
          {{ energy | round(2) }}
        availability: "{{ states('sensor.modbus_zcs_energia_caricata_totale') | float(0) > states.input_number.filtro_carica.state | float(0) }}"
        state_class: total_increasing
        device_class: energy
        icon: mdi:battery-high

You likely already changed the template according to Tomā€™s recommendation.
Iā€™m pretty convinced you wonā€™t have the message at restart, now, but to be sure;

        availability: "{{ states('sensor.modbus_zcs_energia_generata_totale') is not None and states('sensor.modbus_zcs_energia_generata_totale') | float(0) > states.input_number.filtro_produzione.state | float(0) }}"

It is probably because the secondary sensor is created before the main sensorā€¦
The fault will resolve itself (apparently) when the main sensor loaded.

Solution as Koying said (or change the order of loading the sensors)

PS Good to hear you got it to work :wink:

Yes I had made the change but when I restarted I always got the message.
Iā€™ve now made your change and when I check configuration HA notify me this message.

Logger: homeassistant.config
Source: config.py:982
First occurred: 12:56:27 (1 occurrences)
Last logged: 12:56:27

Invalid config for [template]: invalid template (TemplateAssertionError: No test named 'None'.) for dictionary value @ data['sensor'][14]['availability']. Got "{{ states('sensor.modbus_zcs_energia_generata_totale') is not None and states('sensor.modbus_zcs_energia_generata_totale') | float(0) > states.input_number.filtro_produzione.state | float(0) }}". (See /config/packages/modbus.yaml, line 751).

This is a follow up on another post

No, in the modbus.yaml file the order of the sensors is correct. First the main sensors are created.

But they are different problems

Man, itā€™s literarily the first google result:
no test named ā€˜Noneā€™ Ā· Issue #520 Ā· pallets/jinja Ā· GitHub

Use lowercase none (and please help yourself a bit).

Man donā€™t be angry please, Iā€™m sorry, Iā€™m newbie and I donā€™t know English well. I am very grateful for your help.